]> www.wagner.pp.ru Git - openssl-gost/engine.git/blob - gosthash2012.h
gosthash2012: Enable building with SIMD implementation
[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 __SSE2__
14 # define __GOST3411_HAS_SSE2__
15 #endif
16
17 #ifdef __GOST3411_HAS_SSE2__
18 # if (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 2)
19 #  undef __GOST3411_HAS_SSE2__
20 # endif
21 #endif
22
23 #ifndef L_ENDIAN
24 # define __GOST3411_BIG_ENDIAN__
25 #endif
26
27 #if defined __GOST3411_HAS_SSE2__
28 # include "gosthash2012_sse2.h"
29 #else
30 # include "gosthash2012_ref.h"
31 #endif
32
33 # if defined(__GNUC__) || defined(__clang__)
34 #  define RESTRICT __restrict__
35 # else
36 #  define RESTRICT
37 # endif
38
39 #ifdef _MSC_VER
40 # define ALIGN(x) __declspec(align(x))
41 #else
42 # define ALIGN(x) __attribute__ ((__aligned__(x)))
43 #endif
44
45 ALIGN(16)
46 typedef union uint512_u {
47     unsigned long long QWORD[8];
48     unsigned char B[64];
49 } uint512_u;
50
51 #include "gosthash2012_const.h"
52 #include "gosthash2012_precalc.h"
53
54 /* GOST R 34.11-2012 hash context */
55 typedef struct gost2012_hash_ctx {
56     union uint512_u buffer;
57     union uint512_u h;
58     union uint512_u N;
59     union uint512_u Sigma;
60     size_t bufsize;
61     unsigned int digest_size;
62 } gost2012_hash_ctx;
63
64 void init_gost2012_hash_ctx(gost2012_hash_ctx * CTX,
65                             const unsigned int digest_size);
66 void gost2012_hash_block(gost2012_hash_ctx * CTX,
67                          const unsigned char *data, size_t len);
68 void gost2012_finish_hash(gost2012_hash_ctx * CTX, unsigned char *digest);