]> www.wagner.pp.ru Git - openssl-gost/engine.git/blob - gosthash2012.h
gosthash2012: Make `add512' to work in-place
[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 # if defined(__GNUC__) || defined(__clang__)
37 #  define RESTRICT __restrict__
38 # else
39 #  define RESTRICT
40 # endif
41
42 #ifdef _MSC_VER
43 # define ALIGN(x) __declspec(align(x))
44 #else
45 # define ALIGN(x) __attribute__ ((__aligned__(x)))
46 #endif
47
48 ALIGN(16)
49 typedef union uint512_u {
50     unsigned long long QWORD[8];
51 } uint512_u;
52
53 #include "gosthash2012_const.h"
54 #include "gosthash2012_precalc.h"
55
56 /* GOST R 34.11-2012 hash context */
57 typedef struct gost2012_hash_ctx {
58     unsigned char buffer[64];
59     union uint512_u h;
60     union uint512_u N;
61     union uint512_u Sigma;
62     size_t bufsize;
63     unsigned int digest_size;
64 } gost2012_hash_ctx;
65
66 void init_gost2012_hash_ctx(gost2012_hash_ctx * CTX,
67                             const unsigned int digest_size);
68 void gost2012_hash_block(gost2012_hash_ctx * CTX,
69                          const unsigned char *data, size_t len);
70 void gost2012_finish_hash(gost2012_hash_ctx * CTX, unsigned char *digest);