]> wagner.pp.ru Git - openssl-gost/engine.git/blob - gosthash2012_ref.h
EVP_MAC_init API changed
[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 # define __XLPS_FOR for (_i = 0; _i <= 7; _i++)
29 #ifndef __GOST3411_BIG_ENDIAN__
30 # define _datai _i
31 #else
32 # define _datai 7 - _i
33 #endif
34
35 #define XLPS(x, y, data) { \
36     register unsigned long long r0, r1, r2, r3, r4, r5, r6, r7; \
37     int _i; \
38     \
39     r0 = x->QWORD[0] ^ y->QWORD[0]; \
40     r1 = x->QWORD[1] ^ y->QWORD[1]; \
41     r2 = x->QWORD[2] ^ y->QWORD[2]; \
42     r3 = x->QWORD[3] ^ y->QWORD[3]; \
43     r4 = x->QWORD[4] ^ y->QWORD[4]; \
44     r5 = x->QWORD[5] ^ y->QWORD[5]; \
45     r6 = x->QWORD[6] ^ y->QWORD[6]; \
46     r7 = x->QWORD[7] ^ y->QWORD[7]; \
47     \
48     \
49     __XLPS_FOR {\
50         data->QWORD[_datai]  = Ax[0][r0 & 0xFF]; \
51         data->QWORD[_datai] ^= Ax[1][r1 & 0xFF]; \
52         data->QWORD[_datai] ^= Ax[2][r2 & 0xFF]; \
53         data->QWORD[_datai] ^= Ax[3][r3 & 0xFF]; \
54         data->QWORD[_datai] ^= Ax[4][r4 & 0xFF]; \
55         data->QWORD[_datai] ^= Ax[5][r5 & 0xFF]; \
56         data->QWORD[_datai] ^= Ax[6][r6 & 0xFF]; \
57         data->QWORD[_datai] ^= Ax[7][r7 & 0xFF]; \
58         r0 >>= 8; \
59         r1 >>= 8; \
60         r2 >>= 8; \
61         r3 >>= 8; \
62         r4 >>= 8; \
63         r5 >>= 8; \
64         r6 >>= 8; \
65         r7 >>= 8; \
66     }\
67 }
68
69 #define ROUND(i, Ki, data) { \
70     XLPS(Ki, (&C[i]), Ki); \
71     XLPS(Ki, data, data); \
72 }