]> www.wagner.pp.ru Git - openssl-gost/engine.git/blob - gosthash2012_ref.h
Merge branch 'no_gost94_sig' into gost12_algs
[openssl-gost/engine.git] / gosthash2012_ref.h
1 /*
2  * Portable implementation of core functions for GOST R 34.11-2012.
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 #ifdef __GOST3411_HAS_SSE2__
12 # error "GOST R 34.11-2012: portable implementation disabled in config.h"
13 #endif
14
15 #define X(x, y, z) { \
16     z->QWORD[0] = x->QWORD[0] ^ y->QWORD[0]; \
17     z->QWORD[1] = x->QWORD[1] ^ y->QWORD[1]; \
18     z->QWORD[2] = x->QWORD[2] ^ y->QWORD[2]; \
19     z->QWORD[3] = x->QWORD[3] ^ y->QWORD[3]; \
20     z->QWORD[4] = x->QWORD[4] ^ y->QWORD[4]; \
21     z->QWORD[5] = x->QWORD[5] ^ y->QWORD[5]; \
22     z->QWORD[6] = x->QWORD[6] ^ y->QWORD[6]; \
23     z->QWORD[7] = x->QWORD[7] ^ y->QWORD[7]; \
24 }
25
26 #ifndef __GOST3411_BIG_ENDIAN__
27 # define __XLPS_FOR for (_i = 0; _i <= 7; _i++)
28 # define _datai _i
29 #else
30 # define __XLPS_FOR for (_i = 7; _i >= 0; _i--)
31 # define _datai 7 - _i
32 #endif
33
34 #define XLPS(x, y, data) { \
35     register unsigned long long r0, r1, r2, r3, r4, r5, r6, r7; \
36     int _i; \
37     \
38     r0 = x->QWORD[0] ^ y->QWORD[0]; \
39     r1 = x->QWORD[1] ^ y->QWORD[1]; \
40     r2 = x->QWORD[2] ^ y->QWORD[2]; \
41     r3 = x->QWORD[3] ^ y->QWORD[3]; \
42     r4 = x->QWORD[4] ^ y->QWORD[4]; \
43     r5 = x->QWORD[5] ^ y->QWORD[5]; \
44     r6 = x->QWORD[6] ^ y->QWORD[6]; \
45     r7 = x->QWORD[7] ^ y->QWORD[7]; \
46     \
47     \
48     __XLPS_FOR {\
49         data->QWORD[_datai]  = Ax[0][(r0 >> (_i << 3)) & 0xFF]; \
50         data->QWORD[_datai] ^= Ax[1][(r1 >> (_i << 3)) & 0xFF]; \
51         data->QWORD[_datai] ^= Ax[2][(r2 >> (_i << 3)) & 0xFF]; \
52         data->QWORD[_datai] ^= Ax[3][(r3 >> (_i << 3)) & 0xFF]; \
53         data->QWORD[_datai] ^= Ax[4][(r4 >> (_i << 3)) & 0xFF]; \
54         data->QWORD[_datai] ^= Ax[5][(r5 >> (_i << 3)) & 0xFF]; \
55         data->QWORD[_datai] ^= Ax[6][(r6 >> (_i << 3)) & 0xFF]; \
56         data->QWORD[_datai] ^= Ax[7][(r7 >> (_i << 3)) & 0xFF]; \
57     }\
58 }
59
60 #define ROUND(i, Ki, data) { \
61     XLPS(Ki, (&C[i]), Ki); \
62     XLPS(Ki, data, data); \
63 }