]> www.wagner.pp.ru Git - openssl-gost/engine.git/blob - gosthash2012.h
Initial commit providing GOST 2012 algorithms.
[openssl-gost/engine.git] / gosthash2012.h
1 /*
2  * GOST R 34.11-2012 core functions definitions.
3  *
4  * Copyright (c) 2013 Cryptocom LTD.
5  * This file is distributed under the same license as OpenSSL.
6  *
7  * Author: Alexey Degtyarev <alexey@renatasystems.org>
8  *
9  */
10
11 #include <string.h>
12
13 #ifdef OPENSSL_IA32_SSE2
14 # ifdef __MMX__
15 #  ifdef __SSE2__
16 #   define __GOST3411_HAS_SSE2__
17 #  endif
18 # endif
19 #endif
20
21 #ifdef __GOST3411_HAS_SSE2__
22 # if (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 2)
23 #  undef __GOST3411_HAS_SSE2__
24 # endif
25 #endif
26
27 #ifndef L_ENDIAN
28 # define __GOST3411_BIG_ENDIAN__
29 #endif
30 #if defined __GOST3411_HAS_SSE2__
31 # include "gosthash2012_sse2.h"
32 #else
33 # include "gosthash2012_ref.h"
34 #endif
35
36 #ifdef _MSC_VER
37 # define ALIGN(x) __declspec(align(x))
38 #else
39 # define ALIGN(x) __attribute__ ((__aligned__(x)))
40 #endif
41
42 ALIGN(16)
43 typedef union uint512_u {
44     unsigned long long QWORD[8];
45 } uint512_u;
46
47 #include "gosthash2012_const.h"
48 #include "gosthash2012_precalc.h"
49
50 /* GOST R 34.11-2012 hash context */
51 ALIGN(16)
52 typedef struct gost2012_hash_ctx {
53     ALIGN(16) unsigned char buffer[64];
54     union uint512_u hash;
55     union uint512_u h;
56     union uint512_u N;
57     union uint512_u Sigma;
58     size_t bufsize;
59     unsigned int digest_size;
60 } gost2012_hash_ctx;
61
62 void init_gost2012_hash_ctx(gost2012_hash_ctx * CTX,
63                             const unsigned int digest_size);
64 void gost2012_hash_block(gost2012_hash_ctx * CTX,
65                          const unsigned char *data, size_t len);
66 void gost2012_finish_hash(gost2012_hash_ctx * CTX, unsigned char *digest);