|
|
|
@ -185,20 +185,7 @@ namespace crypto
@@ -185,20 +185,7 @@ namespace crypto
|
|
|
|
|
0x492c024284fbaec0, 0xaa16012142f35760, 0x550b8e9e21f7a530, 0xa48b474f9ef5dc18, |
|
|
|
|
0x70a6a56e2440598e, 0x3853dc371220a247, 0x1ca76e95091051ad, 0x0edd37c48a08a6d8, |
|
|
|
|
0x07e095624504536c, 0x8d70c431ac02a736, 0xc83862965601dd1b, 0x641c314b2b8ee083 |
|
|
|
|
}; // in Little Endian
|
|
|
|
|
|
|
|
|
|
static const uint8_t T_[64]= |
|
|
|
|
{ |
|
|
|
|
0, 8, 16, 24, 32, 40, 48, 56, |
|
|
|
|
1, 9, 17, 25, 33, 41, 49, 57, |
|
|
|
|
2, 10, 18, 26, 34, 42, 50, 58, |
|
|
|
|
3, 11, 19, 27, 35, 43, 51, 59, |
|
|
|
|
4, 12, 20, 28, 36, 44, 52, 60, |
|
|
|
|
5, 13, 21, 29, 37, 45, 53, 61, |
|
|
|
|
6, 14, 22, 30, 38, 46, 54, 62, |
|
|
|
|
7, 15, 23, 31, 39, 47, 55, 63 |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
static const uint8_t C_[12][64] = |
|
|
|
|
{ |
|
|
|
@ -320,21 +307,17 @@ namespace crypto
@@ -320,21 +307,17 @@ namespace crypto
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void S () |
|
|
|
|
{ |
|
|
|
|
for (int i = 0; i < 64; i++) |
|
|
|
|
buf[i] = sbox_[buf[i]]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void L () |
|
|
|
|
void SPL () |
|
|
|
|
{ |
|
|
|
|
uint8_t p[64]; |
|
|
|
|
memcpy (p, buf, 64); // we need to copy it for P's transposition
|
|
|
|
|
for (int i = 0; i < 8; i++) |
|
|
|
|
{ |
|
|
|
|
uint64_t c = 0; |
|
|
|
|
for (int j = 0; j < 8; j++) |
|
|
|
|
{ |
|
|
|
|
uint8_t bit = 0x80; |
|
|
|
|
uint8_t byte = buf[i*8+j]; |
|
|
|
|
uint8_t byte = sbox_[p[j*8+i]]; // S - sbox_, P - transpose (i,j)
|
|
|
|
|
for (int k = 0; k < 8; k++) |
|
|
|
|
{ |
|
|
|
|
if (byte & bit) c ^= A_[j*8+k]; |
|
|
|
@ -345,27 +328,15 @@ namespace crypto
@@ -345,27 +328,15 @@ namespace crypto
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void P () |
|
|
|
|
{ |
|
|
|
|
uint8_t t[64]; |
|
|
|
|
for (int i = 0; i < 64; i++) |
|
|
|
|
t[i] = buf[T_[i]]; |
|
|
|
|
memcpy (buf, t, 64); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
GOST3411Block E (const GOST3411Block& m) |
|
|
|
|
{ |
|
|
|
|
GOST3411Block k = *this; |
|
|
|
|
GOST3411Block res = k^m; |
|
|
|
|
for (int i = 0; i < 12; i++) |
|
|
|
|
{ |
|
|
|
|
res.S (); |
|
|
|
|
res.P (); |
|
|
|
|
res.L (); |
|
|
|
|
res.SPL (); |
|
|
|
|
k = k^C_[i]; |
|
|
|
|
k.S (); |
|
|
|
|
k.P (); |
|
|
|
|
k.L (); |
|
|
|
|
k.SPL (); |
|
|
|
|
res = k^res; |
|
|
|
|
} |
|
|
|
|
return res; |
|
|
|
@ -375,9 +346,7 @@ namespace crypto
@@ -375,9 +346,7 @@ namespace crypto
|
|
|
|
|
static GOST3411Block gN (const GOST3411Block& N, const GOST3411Block& h, const GOST3411Block& m) |
|
|
|
|
{ |
|
|
|
|
GOST3411Block res = N ^ h; |
|
|
|
|
res.S (); |
|
|
|
|
res.P (); |
|
|
|
|
res.L (); |
|
|
|
|
res.SPL (); |
|
|
|
|
res = res.E (m); |
|
|
|
|
res = res^h; |
|
|
|
|
res = res^m; |
|
|
|
|