2 * Portable implementation of core functions for GOST R 34.11-2012.
4 * Copyright (c) 2013 Cryptocom LTD.
5 * This file is distributed under the same license as OpenSSL.
7 * Author: Alexey Degtyarev <alexey@renatasystems.org>
11 #ifdef __GOST3411_HAS_SSE2__
12 # error "GOST R 34.11-2012: portable implementation disabled in config.h"
15 # pragma message "Use regular implementation"
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]; \
28 # define __XLPS_FOR for (_i = 0; _i <= 7; _i++)
29 #ifndef __GOST3411_BIG_ENDIAN__
32 # define _datai 7 - _i
35 #define XLPS(x, y, data) { \
36 register unsigned long long r0, r1, r2, r3, r4, r5, r6, r7; \
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]; \
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]; \
69 #define ROUND(i, Ki, data) { \
70 XLPS(Ki, (&C[i]), Ki); \
71 XLPS(Ki, data, data); \