]> www.wagner.pp.ru Git - openssl-gost/engine.git/blob - gosthash2012.h
tcl_tests: ca.try: Ignore openssl crl exit status for 'corrupted CRL' test
[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 # if !defined(__x86_64__) && !defined(__e2k__)
16 /*
17  * x86-64 bit Linux and Windows ABIs provide malloc function that returns
18  * 16-byte alignment memory buffers required by SSE load/store instructions.
19  * Other platforms require special trick for proper gost2012_hash_ctx structure
20  * allocation. It will be easier to switch to unaligned loadu/storeu memory
21  * access instructions in this case.
22  */
23 #  define UNALIGNED_SIMD_ACCESS
24 #  pragma message "Use unaligned SIMD memory access"
25 # endif
26 #endif
27
28 #ifdef __GOST3411_HAS_SSE2__
29 # if (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 2)
30 #  undef __GOST3411_HAS_SSE2__
31 # endif
32 #endif
33
34 #ifndef L_ENDIAN
35 # define __GOST3411_BIG_ENDIAN__
36 #endif
37
38 #if defined __GOST3411_HAS_SSE2__
39 # include "gosthash2012_sse2.h"
40 #else
41 # include "gosthash2012_ref.h"
42 #endif
43
44 # if defined(__GNUC__) || defined(__clang__)
45 #  define RESTRICT __restrict__
46 # else
47 #  define RESTRICT
48 # endif
49
50 #ifdef _MSC_VER
51 # define ALIGN(x) __declspec(align(x))
52 #else
53 # define ALIGN(x) __attribute__ ((__aligned__(x)))
54 #endif
55
56 ALIGN(16)
57 typedef union uint512_u {
58     unsigned long long QWORD[8];
59     unsigned char B[64];
60 } uint512_u;
61
62 #include "gosthash2012_const.h"
63 #include "gosthash2012_precalc.h"
64
65 /* GOST R 34.11-2012 hash context */
66 typedef struct gost2012_hash_ctx {
67     union uint512_u buffer;
68     union uint512_u h;
69     union uint512_u N;
70     union uint512_u Sigma;
71     size_t bufsize;
72     unsigned int digest_size;
73 } gost2012_hash_ctx;
74
75 void init_gost2012_hash_ctx(gost2012_hash_ctx * CTX,
76                             const unsigned int digest_size);
77 void gost2012_hash_block(gost2012_hash_ctx * CTX,
78                          const unsigned char *data, size_t len);
79 void gost2012_finish_hash(gost2012_hash_ctx * CTX, unsigned char *digest);