]> www.wagner.pp.ru Git - openssl-gost/engine.git/blob - gosthash2012_ref.h
gosthash2012: Enable building with SIMD implementation
[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 # pragma message "Use regular implementation"
16
17 #define X(x, y, z) { \
18     z->QWORD[0] = x->QWORD[0] ^ y->QWORD[0]; \
19     z->QWORD[1] = x->QWORD[1] ^ y->QWORD[1]; \
20     z->QWORD[2] = x->QWORD[2] ^ y->QWORD[2]; \
21     z->QWORD[3] = x->QWORD[3] ^ y->QWORD[3]; \
22     z->QWORD[4] = x->QWORD[4] ^ y->QWORD[4]; \
23     z->QWORD[5] = x->QWORD[5] ^ y->QWORD[5]; \
24     z->QWORD[6] = x->QWORD[6] ^ y->QWORD[6]; \
25     z->QWORD[7] = x->QWORD[7] ^ y->QWORD[7]; \
26 }
27
28 #ifndef __GOST3411_BIG_ENDIAN__
29 # define __XLPS_FOR for (_i = 0; _i <= 7; _i++)
30 # define _datai _i
31 #else
32 # define __XLPS_FOR for (_i = 7; _i >= 0; _i--)
33 # define _datai 7 - _i
34 #endif
35
36 #define XLPS(x, y, data) { \
37     register unsigned long long r0, r1, r2, r3, r4, r5, r6, r7; \
38     int _i; \
39     \
40     r0 = x->QWORD[0] ^ y->QWORD[0]; \
41     r1 = x->QWORD[1] ^ y->QWORD[1]; \
42     r2 = x->QWORD[2] ^ y->QWORD[2]; \
43     r3 = x->QWORD[3] ^ y->QWORD[3]; \
44     r4 = x->QWORD[4] ^ y->QWORD[4]; \
45     r5 = x->QWORD[5] ^ y->QWORD[5]; \
46     r6 = x->QWORD[6] ^ y->QWORD[6]; \
47     r7 = x->QWORD[7] ^ y->QWORD[7]; \
48     \
49     \
50     __XLPS_FOR {\
51         data->QWORD[_datai]  = Ax[0][(r0 >> (_i << 3)) & 0xFF]; \
52         data->QWORD[_datai] ^= Ax[1][(r1 >> (_i << 3)) & 0xFF]; \
53         data->QWORD[_datai] ^= Ax[2][(r2 >> (_i << 3)) & 0xFF]; \
54         data->QWORD[_datai] ^= Ax[3][(r3 >> (_i << 3)) & 0xFF]; \
55         data->QWORD[_datai] ^= Ax[4][(r4 >> (_i << 3)) & 0xFF]; \
56         data->QWORD[_datai] ^= Ax[5][(r5 >> (_i << 3)) & 0xFF]; \
57         data->QWORD[_datai] ^= Ax[6][(r6 >> (_i << 3)) & 0xFF]; \
58         data->QWORD[_datai] ^= Ax[7][(r7 >> (_i << 3)) & 0xFF]; \
59     }\
60 }
61
62 #define ROUND(i, Ki, data) { \
63     XLPS(Ki, (&C[i]), Ki); \
64     XLPS(Ki, data, data); \
65 }