@li0ard/gost 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/gf/gf128.d.ts +2 -0
- package/gf/gf128.js +15 -0
- package/gf/gf256.d.ts +1 -0
- package/gf/gf256.js +62 -0
- package/gf/gf64.d.ts +2 -0
- package/gf/gf64.js +15 -0
- package/gf/index.d.ts +3 -0
- package/gf/index.js +3 -0
- package/gost3410/const.js +20 -20
- package/gost3410/vko.js +1 -1
- package/gost341194/index.d.ts +2 -2
- package/kdf.js +2 -2
- package/kuznyechik/const.js +0 -5
- package/kuznyechik/index.js +18 -33
- package/magma/const.d.ts +38 -38
- package/magma/const.js +190 -190
- package/magma/index.d.ts +1 -2
- package/magma/index.js +16 -18
- package/modes/_keytransform.d.ts +1 -1
- package/modes/mac.js +37 -28
- package/modes/mgm.js +2 -17
- package/modes/wrap.d.ts +1 -1
- package/modes/wrap.js +1 -1
- package/package.json +1 -1
- package/streebog/index.js +3 -3
package/gf/gf128.d.ts
ADDED
package/gf/gf128.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { bytesToNumberBE, numberToBytesBE } from "@noble/curves/utils.js";
|
|
2
|
+
export const gf128Multiply = (a, b) => {
|
|
3
|
+
let x = bytesToNumberBE(a), y = bytesToNumberBE(b), z = 0n;
|
|
4
|
+
const max_bit = 1n << 127n;
|
|
5
|
+
while (y > 0n) {
|
|
6
|
+
if ((y & 1n) == 1n)
|
|
7
|
+
z ^= x;
|
|
8
|
+
if ((x & max_bit) > 0n)
|
|
9
|
+
x = ((x ^ max_bit) << 1n) ^ 0x87n;
|
|
10
|
+
else
|
|
11
|
+
x <<= 1n;
|
|
12
|
+
y >>= 1n;
|
|
13
|
+
}
|
|
14
|
+
return numberToBytesBE(z, 16);
|
|
15
|
+
};
|
package/gf/gf256.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const gf256Multiply: (a: number, b: number) => number;
|
package/gf/gf256.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/*// Precompute GF(256) multiply table
|
|
2
|
+
const gf256Multiply_slow = (a: number, b: number): number => {
|
|
3
|
+
let result = 0, high_bit: number;
|
|
4
|
+
for(let _ = 0; _ < 8; _++) {
|
|
5
|
+
if((b & 1) === 1) result ^= a;
|
|
6
|
+
high_bit = a & 0x80;
|
|
7
|
+
a <<= 1;
|
|
8
|
+
if(high_bit == 0x80) a ^= 0xC3;
|
|
9
|
+
b >>= 1;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return result & 0xFF;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const gen_mul_tables = () => {
|
|
16
|
+
let c = 1;
|
|
17
|
+
|
|
18
|
+
for (let i = 0; i < 256; i++) {
|
|
19
|
+
gf_multtable_log[c] = i;
|
|
20
|
+
gf_multtable_exp[i] = c;
|
|
21
|
+
c = gfMultiply_slow(c, 3);
|
|
22
|
+
}
|
|
23
|
+
}*/
|
|
24
|
+
const gf_multtable_exp = new Uint8Array([
|
|
25
|
+
0x01, 0x03, 0x05, 0x0F, 0x11, 0x33, 0x55, 0xFF, 0xC2, 0x85, 0x4C, 0xD4, 0xBF, 0x02, 0x06, 0x0A,
|
|
26
|
+
0x1E, 0x22, 0x66, 0xAA, 0x3D, 0x47, 0xC9, 0x98, 0x6B, 0xBD, 0x04, 0x0C, 0x14, 0x3C, 0x44, 0xCC,
|
|
27
|
+
0x97, 0x7A, 0x8E, 0x51, 0xF3, 0xD6, 0xB9, 0x08, 0x18, 0x28, 0x78, 0x88, 0x5B, 0xED, 0xF4, 0xDF,
|
|
28
|
+
0xA2, 0x25, 0x6F, 0xB1, 0x10, 0x30, 0x50, 0xF0, 0xD3, 0xB6, 0x19, 0x2B, 0x7D, 0x87, 0x4A, 0xDE,
|
|
29
|
+
0xA1, 0x20, 0x60, 0xA0, 0x23, 0x65, 0xAF, 0x32, 0x56, 0xFA, 0xCD, 0x94, 0x7F, 0x81, 0x40, 0xC0,
|
|
30
|
+
0x83, 0x46, 0xCA, 0x9D, 0x64, 0xAC, 0x37, 0x59, 0xEB, 0xFE, 0xC1, 0x80, 0x43, 0xC5, 0x8C, 0x57,
|
|
31
|
+
0xF9, 0xC8, 0x9B, 0x6E, 0xB2, 0x15, 0x3F, 0x41, 0xC3, 0x86, 0x49, 0xDB, 0xAE, 0x31, 0x53, 0xF5,
|
|
32
|
+
0xDC, 0xA7, 0x2A, 0x7E, 0x82, 0x45, 0xCF, 0x92, 0x75, 0x9F, 0x62, 0xA6, 0x29, 0x7B, 0x8D, 0x54,
|
|
33
|
+
0xFC, 0xC7, 0x8A, 0x5D, 0xE7, 0xEA, 0xFD, 0xC4, 0x8F, 0x52, 0xF6, 0xD9, 0xA8, 0x3B, 0x4D, 0xD7,
|
|
34
|
+
0xBA, 0x0D, 0x17, 0x39, 0x4B, 0xDD, 0xA4, 0x2F, 0x71, 0x93, 0x76, 0x9A, 0x6D, 0xB7, 0x1A, 0x2E,
|
|
35
|
+
0x72, 0x96, 0x79, 0x8B, 0x5E, 0xE2, 0xE5, 0xEC, 0xF7, 0xDA, 0xAD, 0x34, 0x5C, 0xE4, 0xEF, 0xF2,
|
|
36
|
+
0xD5, 0xBC, 0x07, 0x09, 0x1B, 0x2D, 0x77, 0x99, 0x68, 0xB8, 0x0B, 0x1D, 0x27, 0x69, 0xBB, 0x0E,
|
|
37
|
+
0x12, 0x36, 0x5A, 0xEE, 0xF1, 0xD0, 0xB3, 0x16, 0x3A, 0x4E, 0xD2, 0xB5, 0x1C, 0x24, 0x6C, 0xB4,
|
|
38
|
+
0x1F, 0x21, 0x63, 0xA5, 0x2C, 0x74, 0x9C, 0x67, 0xA9, 0x38, 0x48, 0xD8, 0xAB, 0x3E, 0x42, 0xC6,
|
|
39
|
+
0x89, 0x58, 0xE8, 0xFB, 0xCE, 0x91, 0x70, 0x90, 0x73, 0x95, 0x7C, 0x84, 0x4F, 0xD1, 0xB0, 0x13,
|
|
40
|
+
0x35, 0x5F, 0xE1, 0xE0, 0xE3, 0xE6, 0xE9, 0xF8, 0xCB, 0x9E, 0x61, 0xA3, 0x26, 0x6A, 0xBE, 0x01
|
|
41
|
+
]);
|
|
42
|
+
const gf_multtable_log = new Uint8Array([
|
|
43
|
+
0x00, 0xFF, 0x0D, 0x01, 0x1A, 0x02, 0x0E, 0xB2, 0x27, 0xB3, 0x0F, 0xBA, 0x1B, 0x91, 0xBF, 0x03,
|
|
44
|
+
0x34, 0x04, 0xC0, 0xEF, 0x1C, 0x65, 0xC7, 0x92, 0x28, 0x3A, 0x9E, 0xB4, 0xCC, 0xBB, 0x10, 0xD0,
|
|
45
|
+
0x41, 0xD1, 0x11, 0x44, 0xCD, 0x31, 0xFC, 0xBC, 0x29, 0x7C, 0x72, 0x3B, 0xD4, 0xB5, 0x9F, 0x97,
|
|
46
|
+
0x35, 0x6D, 0x47, 0x05, 0xAB, 0xF0, 0xC1, 0x56, 0xD9, 0x93, 0xC8, 0x8D, 0x1D, 0x14, 0xDD, 0x66,
|
|
47
|
+
0x4E, 0x67, 0xDE, 0x5C, 0x1E, 0x75, 0x51, 0x15, 0xDA, 0x6A, 0x3E, 0x94, 0x0A, 0x8E, 0xC9, 0xEC,
|
|
48
|
+
0x36, 0x23, 0x89, 0x6E, 0x7F, 0x06, 0x48, 0x5F, 0xE1, 0x57, 0xC2, 0x2C, 0xAC, 0x83, 0xA4, 0xF1,
|
|
49
|
+
0x42, 0xFA, 0x7A, 0xD2, 0x54, 0x45, 0x12, 0xD7, 0xB8, 0xBD, 0xFD, 0x18, 0xCE, 0x9C, 0x63, 0x32,
|
|
50
|
+
0xE6, 0x98, 0xA0, 0xE8, 0xD5, 0x78, 0x9A, 0xB6, 0x2A, 0xA2, 0x21, 0x7D, 0xEA, 0x3C, 0x73, 0x4C,
|
|
51
|
+
0x5B, 0x4D, 0x74, 0x50, 0xEB, 0x09, 0x69, 0x3D, 0x2B, 0xE0, 0x82, 0xA3, 0x5E, 0x7E, 0x22, 0x88,
|
|
52
|
+
0xE7, 0xE5, 0x77, 0x99, 0x4B, 0xE9, 0xA1, 0x20, 0x17, 0xB7, 0x9B, 0x62, 0xD6, 0x53, 0xF9, 0x79,
|
|
53
|
+
0x43, 0x40, 0x30, 0xFB, 0x96, 0xD3, 0x7B, 0x71, 0x8C, 0xD8, 0x13, 0xDC, 0x55, 0xAA, 0x6C, 0x46,
|
|
54
|
+
0xEE, 0x33, 0x64, 0xC6, 0xCF, 0xCB, 0x39, 0x9D, 0xB9, 0x26, 0x90, 0xBE, 0xB1, 0x19, 0xFE, 0x0C,
|
|
55
|
+
0x4F, 0x5A, 0x08, 0x68, 0x87, 0x5D, 0xDF, 0x81, 0x61, 0x16, 0x52, 0xF8, 0x1F, 0x4A, 0xE4, 0x76,
|
|
56
|
+
0xC5, 0xED, 0xCA, 0x38, 0x0B, 0xB0, 0x25, 0x8F, 0xDB, 0x8B, 0xA9, 0x6B, 0x70, 0x95, 0x3F, 0x2F,
|
|
57
|
+
0xF3, 0xF2, 0xA5, 0xF4, 0xAD, 0xA6, 0xF5, 0x84, 0xE2, 0xF6, 0x85, 0x58, 0xA7, 0x2D, 0xC3, 0xAE,
|
|
58
|
+
0x37, 0xC4, 0xAF, 0x24, 0x2E, 0x6F, 0x8A, 0xA8, 0xF7, 0x60, 0x49, 0xE3, 0x80, 0x86, 0x59, 0x07
|
|
59
|
+
]);
|
|
60
|
+
export const gf256Multiply = (a, b) => (a == 0 || b == 0)
|
|
61
|
+
? 0
|
|
62
|
+
: gf_multtable_exp[(gf_multtable_log[a] + gf_multtable_log[b]) % 255];
|
package/gf/gf64.d.ts
ADDED
package/gf/gf64.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { bytesToNumberBE, numberToBytesBE } from "@noble/curves/utils.js";
|
|
2
|
+
export const gf64Multiply = (a, b) => {
|
|
3
|
+
let x = bytesToNumberBE(a), y = bytesToNumberBE(b), z = 0n;
|
|
4
|
+
const max_bit = 1n << 63n;
|
|
5
|
+
while (y > 0n) {
|
|
6
|
+
if ((y & 1n) == 1n)
|
|
7
|
+
z ^= x;
|
|
8
|
+
if ((x & max_bit) > 0n)
|
|
9
|
+
x = ((x ^ max_bit) << 1n) ^ 0x1bn;
|
|
10
|
+
else
|
|
11
|
+
x <<= 1n;
|
|
12
|
+
y >>= 1n;
|
|
13
|
+
}
|
|
14
|
+
return numberToBytesBE(z, 8);
|
|
15
|
+
};
|
package/gf/index.d.ts
ADDED
package/gf/index.js
ADDED
package/gost3410/const.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** GOST R 34.10-2001 CryptoCom param set */
|
|
2
|
-
export const ID_GOSTR3410_2001_PARAM_SET_CC =
|
|
2
|
+
export const ID_GOSTR3410_2001_PARAM_SET_CC = {
|
|
3
3
|
p: 0xc0000000000000000000000000000000000000000000000000000000000003c7n,
|
|
4
4
|
n: 0x5fffffffffffffffffffffffffffffff606117a2f4bde428b7458a54b6e87b85n,
|
|
5
5
|
a: 0xc0000000000000000000000000000000000000000000000000000000000003c4n,
|
|
@@ -9,9 +9,9 @@ export const ID_GOSTR3410_2001_PARAM_SET_CC = ({
|
|
|
9
9
|
h: 1n,
|
|
10
10
|
length: 32,
|
|
11
11
|
oids: ["1.2.643.2.9.1.8.1"]
|
|
12
|
-
}
|
|
12
|
+
};
|
|
13
13
|
/** GOST R 34.10-2001 test param set */
|
|
14
|
-
export const ID_GOSTR3410_2001_TEST_PARAM_SET =
|
|
14
|
+
export const ID_GOSTR3410_2001_TEST_PARAM_SET = {
|
|
15
15
|
p: 0x8000000000000000000000000000000000000000000000000000000000000431n,
|
|
16
16
|
n: 0x8000000000000000000000000000000150fe8a1892976154c59cfc193accf5b3n,
|
|
17
17
|
a: 7n,
|
|
@@ -21,9 +21,9 @@ export const ID_GOSTR3410_2001_TEST_PARAM_SET = ({
|
|
|
21
21
|
h: 1n,
|
|
22
22
|
length: 32,
|
|
23
23
|
oids: ["1.2.643.2.2.35.0"]
|
|
24
|
-
}
|
|
24
|
+
};
|
|
25
25
|
/** GOST R 34.10-2012 256 bit `A` param set */
|
|
26
|
-
export const ID_GOSTR3410_2012_256_PARAM_SET_A =
|
|
26
|
+
export const ID_GOSTR3410_2012_256_PARAM_SET_A = {
|
|
27
27
|
p: 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd97n,
|
|
28
28
|
n: 0x400000000000000000000000000000000fd8cddfc87b6635c115af556c360c67n,
|
|
29
29
|
a: 0xc2173f1513981673af4892c23035a27ce25e2013bf95aa33b22c656f277e7335n,
|
|
@@ -36,9 +36,9 @@ export const ID_GOSTR3410_2012_256_PARAM_SET_A = ({
|
|
|
36
36
|
length: 32,
|
|
37
37
|
st: [0x7e7e82520f9f015faa1d0f18c14ab9fb35188275da3fd94206b74f34a48e0ecdn, 0x0100fe73f595ff158e974b44d478d9588744fe5c192ac47ea63075dce7a14aaan],
|
|
38
38
|
oids: ["1.2.643.7.1.2.1.1.1"]
|
|
39
|
-
}
|
|
39
|
+
};
|
|
40
40
|
/** GOST R 34.10-2012 256 bit `B` param set (aka CryptoPro `A` (`XchA`) param set) */
|
|
41
|
-
export const ID_GOSTR3410_2012_256_PARAM_SET_B =
|
|
41
|
+
export const ID_GOSTR3410_2012_256_PARAM_SET_B = {
|
|
42
42
|
p: 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd97n,
|
|
43
43
|
n: 0xffffffffffffffffffffffffffffffff6c611070995ad10045841b09b761b893n,
|
|
44
44
|
a: 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd94n,
|
|
@@ -48,9 +48,9 @@ export const ID_GOSTR3410_2012_256_PARAM_SET_B = ({
|
|
|
48
48
|
h: 1n,
|
|
49
49
|
length: 32,
|
|
50
50
|
oids: ["1.2.643.7.1.2.1.1.2", "1.2.643.2.2.35.1", "1.2.643.2.2.36.0"]
|
|
51
|
-
}
|
|
51
|
+
};
|
|
52
52
|
/** GOST R 34.10-2012 256 bit `C` param set (aka CryptoPro `B` param set) */
|
|
53
|
-
export const ID_GOSTR3410_2012_256_PARAM_SET_C =
|
|
53
|
+
export const ID_GOSTR3410_2012_256_PARAM_SET_C = {
|
|
54
54
|
p: 0x8000000000000000000000000000000000000000000000000000000000000c99n,
|
|
55
55
|
n: 0x800000000000000000000000000000015f700cfff1a624e5e497161bcc8a198fn,
|
|
56
56
|
a: 0x8000000000000000000000000000000000000000000000000000000000000c96n,
|
|
@@ -60,9 +60,9 @@ export const ID_GOSTR3410_2012_256_PARAM_SET_C = ({
|
|
|
60
60
|
h: 1n,
|
|
61
61
|
length: 32,
|
|
62
62
|
oids: ["1.2.643.7.1.2.1.1.3", "1.2.643.2.2.35.2"]
|
|
63
|
-
}
|
|
63
|
+
};
|
|
64
64
|
/** GOST R 34.10-2012 256 bit `D` param set (aka CryptoPro `C` (`XchB`) param set) */
|
|
65
|
-
export const ID_GOSTR3410_2012_256_PARAM_SET_D =
|
|
65
|
+
export const ID_GOSTR3410_2012_256_PARAM_SET_D = {
|
|
66
66
|
p: 0x9b9f605f5a858107ab1ec85e6b41c8aacf846e86789051d37998f7b9022d759bn,
|
|
67
67
|
n: 0x9b9f605f5a858107ab1ec85e6b41c8aa582ca3511eddfb74f02f3a6598980bb9n,
|
|
68
68
|
a: 0x9b9f605f5a858107ab1ec85e6b41c8aacf846e86789051d37998f7b9022d7598n,
|
|
@@ -72,9 +72,9 @@ export const ID_GOSTR3410_2012_256_PARAM_SET_D = ({
|
|
|
72
72
|
h: 1n,
|
|
73
73
|
length: 32,
|
|
74
74
|
oids: ["1.2.643.7.1.2.1.1.4", "1.2.643.2.2.35.3", "1.2.643.2.2.36.1"]
|
|
75
|
-
}
|
|
75
|
+
};
|
|
76
76
|
/** GOST R 34.10-2012 512 bit test param set */
|
|
77
|
-
export const ID_GOSTR3410_2012_512_TEST_PARAM_SET =
|
|
77
|
+
export const ID_GOSTR3410_2012_512_TEST_PARAM_SET = {
|
|
78
78
|
p: 0x4531acd1fe0023c7550d267b6b2fee80922b14b2ffb90f04d4eb7c09b5d2d15df1d852741af4704a0458047e80e4546d35b8336fac224dd81664bbf528be6373n,
|
|
79
79
|
n: 0x4531acd1fe0023c7550d267b6b2fee80922b14b2ffb90f04d4eb7c09b5d2d15da82f2d7ecb1dbac719905c5eecc423f1d86e25edbe23c595d644aaf187e6e6dfn,
|
|
80
80
|
a: 7n,
|
|
@@ -84,9 +84,9 @@ export const ID_GOSTR3410_2012_512_TEST_PARAM_SET = ({
|
|
|
84
84
|
h: 1n,
|
|
85
85
|
length: 64,
|
|
86
86
|
oids: ["1.2.643.7.1.2.1.2.0"]
|
|
87
|
-
}
|
|
87
|
+
};
|
|
88
88
|
/** GOST R 34.10-2012 512 bit `A` param set */
|
|
89
|
-
export const ID_GOSTR3410_2012_512_PARAM_SET_A =
|
|
89
|
+
export const ID_GOSTR3410_2012_512_PARAM_SET_A = {
|
|
90
90
|
p: 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdc7n,
|
|
91
91
|
n: 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff27e69532f48d89116ff22b8d4e0560609b4b38abfad2b85dcacdb1411f10b275n,
|
|
92
92
|
a: 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdc4n,
|
|
@@ -96,9 +96,9 @@ export const ID_GOSTR3410_2012_512_PARAM_SET_A = ({
|
|
|
96
96
|
h: 1n,
|
|
97
97
|
length: 64,
|
|
98
98
|
oids: ["1.2.643.7.1.2.1.2.1"]
|
|
99
|
-
}
|
|
99
|
+
};
|
|
100
100
|
/** GOST R 34.10-2012 512 bit `B` param set */
|
|
101
|
-
export const ID_GOSTR3410_2012_512_PARAM_SET_B =
|
|
101
|
+
export const ID_GOSTR3410_2012_512_PARAM_SET_B = {
|
|
102
102
|
p: 0x8000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006fn,
|
|
103
103
|
n: 0x800000000000000000000000000000000000000000000000000000000000000149a1ec142565a545acfdb77bd9d40cfa8b996712101bea0ec6346c54374f25bdn,
|
|
104
104
|
a: 0x8000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006cn,
|
|
@@ -108,9 +108,9 @@ export const ID_GOSTR3410_2012_512_PARAM_SET_B = ({
|
|
|
108
108
|
h: 1n,
|
|
109
109
|
length: 64,
|
|
110
110
|
oids: ["1.2.643.7.1.2.1.2.2"]
|
|
111
|
-
}
|
|
111
|
+
};
|
|
112
112
|
/** GOST R 34.10-2012 512 bit `C` param set */
|
|
113
|
-
export const ID_GOSTR3410_2012_512_PARAM_SET_C =
|
|
113
|
+
export const ID_GOSTR3410_2012_512_PARAM_SET_C = {
|
|
114
114
|
p: 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdc7n,
|
|
115
115
|
n: 0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc98cdba46506ab004c33a9ff5147502cc8eda9e7a769a12694623cef47f023edn,
|
|
116
116
|
a: 0xdc9203e514a721875485a529d2c722fb187bc8980eb866644de41c68e143064546e861c0e2c9edd92ade71f46fcf50ff2ad97f951fda9f2a2eb6546f39689bd3n,
|
|
@@ -123,7 +123,7 @@ export const ID_GOSTR3410_2012_512_PARAM_SET_C = ({
|
|
|
123
123
|
length: 64,
|
|
124
124
|
st: [0x186c289cffa09c983b168c30c829006c952ff4aaf99c73850875d7e77bebef18d653187d6ba8fe533ec74c6f061872585b97cc0f50f57752cd73f4913304621en, 0x9a628f975594ecefd89ba28a2539ffb79c8ab238aeed0851fa5c1abb02b80b44c6734501b83a011dd625cd0b5145091a6d9acd4b1f5c5b1e21b2b249ddfd1271n],
|
|
125
125
|
oids: ["1.2.643.7.1.2.1.2.3"]
|
|
126
|
-
}
|
|
126
|
+
};
|
|
127
127
|
export const CURVES = {
|
|
128
128
|
ID_GOSTR3410_2001_PARAM_SET_CC,
|
|
129
129
|
ID_GOSTR3410_2001_TEST_PARAM_SET,
|
package/gost3410/vko.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Field } from "@noble/curves/abstract/modular.js";
|
|
2
2
|
import { weierstrass } from "@noble/curves/abstract/weierstrass.js";
|
|
3
|
-
import { gost341194 } from "../gost341194";
|
|
3
|
+
import { gost341194 } from "../gost341194/index.js";
|
|
4
4
|
import { streebog256, streebog512 } from "../streebog/index.js";
|
|
5
5
|
import { bytesToNumberBE, concatBytes, numberToBytesLE } from "@noble/curves/utils.js";
|
|
6
6
|
/**
|
package/gost341194/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export declare class Gost341194 implements Hash<Gost341194> {
|
|
|
7
7
|
readonly outputLen = 32;
|
|
8
8
|
readonly canXOF = false;
|
|
9
9
|
/** GOST R 34.11-94 hash function */
|
|
10
|
-
constructor(data?: TArg<Uint8Array>, sbox?: TArg<Uint8Array>
|
|
10
|
+
constructor(data?: TArg<Uint8Array>, sbox?: TArg<Uint8Array>);
|
|
11
11
|
/** Create hash instance */
|
|
12
12
|
static create(): Gost341194;
|
|
13
13
|
destroy(): void;
|
|
@@ -18,6 +18,6 @@ export declare class Gost341194 implements Hash<Gost341194> {
|
|
|
18
18
|
digest(): TRet<Uint8Array>;
|
|
19
19
|
}
|
|
20
20
|
/** GOST R 34.11-94 hash function */
|
|
21
|
-
export declare const gost341194: (msg: TArg<Uint8Array>, sbox?: TArg<Uint8Array>
|
|
21
|
+
export declare const gost341194: (msg: TArg<Uint8Array>, sbox?: TArg<Uint8Array>) => TRet<Uint8Array>;
|
|
22
22
|
/** DSTU GOST 34.311-95 */
|
|
23
23
|
export declare const gost3431195: (msg: TArg<Uint8Array>) => TRet<Uint8Array>;
|
package/kdf.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { concatBytes, createHasher } from "@noble/hashes/utils.js";
|
|
1
|
+
import { concatBytes, copyBytes, createHasher } from "@noble/hashes/utils.js";
|
|
2
2
|
import { streebog256hmac } from "./hmac.js";
|
|
3
3
|
import { numberToBytesBE } from "@noble/curves/utils.js";
|
|
4
4
|
import { pbkdf2 } from "@noble/hashes/pbkdf2.js";
|
|
@@ -35,7 +35,7 @@ export const cpkdf = (password, salt) => {
|
|
|
35
35
|
if (password.length != 0)
|
|
36
36
|
hasher.update(pin);
|
|
37
37
|
const hash = hasher.digest();
|
|
38
|
-
const c =
|
|
38
|
+
const c = copyBytes(CPKDF_CONST);
|
|
39
39
|
const m0 = new Uint8Array(bs);
|
|
40
40
|
const m1 = new Uint8Array(bs);
|
|
41
41
|
for (let j = 0; j < (password.length != 0 ? 2000 : 2); j++) {
|
package/kuznyechik/const.js
CHANGED
|
@@ -37,11 +37,6 @@ export const PI_REV = new Uint8Array([
|
|
|
37
37
|
export const L = new Uint8Array([
|
|
38
38
|
0x01, 0x94, 0x20, 0x85, 0x10, 0xc2, 0xc0, 0x01, 0xfb, 0x01, 0xc0, 0xc2, 0x10, 0x85, 0x20, 0x94,
|
|
39
39
|
]);
|
|
40
|
-
/*const ITER: Uint8Array[] = Array(32).fill(null).map(() => new Uint8Array(16));
|
|
41
|
-
for(let i = 0; i < 32; i++) {
|
|
42
|
-
ITER[i][15] = i + 1;
|
|
43
|
-
ITER[i] = LL(ITER[i]);
|
|
44
|
-
}*/
|
|
45
40
|
export const ITER = [
|
|
46
41
|
new Uint8Array([0x6E, 0xA2, 0x76, 0x72, 0x6C, 0x48, 0x7A, 0xB8, 0x5D, 0x27, 0xBD, 0x10, 0xDD, 0x84, 0x94, 0x01]),
|
|
47
42
|
new Uint8Array([0xDC, 0x87, 0xEC, 0xE4, 0xD8, 0x90, 0xF4, 0xB3, 0xBA, 0x4E, 0xB9, 0x20, 0x79, 0xCB, 0xEB, 0x02]),
|
package/kuznyechik/index.js
CHANGED
|
@@ -1,19 +1,7 @@
|
|
|
1
1
|
import { copyBytes } from "@noble/curves/utils.js";
|
|
2
2
|
import { ITER, L, PI, PI_REV } from "./const.js";
|
|
3
3
|
import { xorBytes } from "../utils.js";
|
|
4
|
-
|
|
5
|
-
let result = 0, high_bit;
|
|
6
|
-
for (let _ = 0; _ < 8; _++) {
|
|
7
|
-
if ((b & 1) === 1)
|
|
8
|
-
result ^= a;
|
|
9
|
-
high_bit = a & 0x80;
|
|
10
|
-
a <<= 1;
|
|
11
|
-
if (high_bit == 0x80)
|
|
12
|
-
a ^= 0xC3;
|
|
13
|
-
b >>= 1;
|
|
14
|
-
}
|
|
15
|
-
return result & 0xFF;
|
|
16
|
-
};
|
|
4
|
+
import { gf256Multiply } from "../gf/index.js";
|
|
17
5
|
const S = (input, pi = PI) => new Uint8Array([
|
|
18
6
|
pi[input[0]], pi[input[1]], pi[input[2]], pi[input[3]],
|
|
19
7
|
pi[input[4]], pi[input[5]], pi[input[6]], pi[input[7]],
|
|
@@ -21,26 +9,26 @@ const S = (input, pi = PI) => new Uint8Array([
|
|
|
21
9
|
pi[input[12]], pi[input[13]], pi[input[14]], pi[input[15]]
|
|
22
10
|
]);
|
|
23
11
|
const R = (input) => new Uint8Array([
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
12
|
+
gf256Multiply(input[15], L[0]) ^ gf256Multiply(input[0], L[1]) ^
|
|
13
|
+
gf256Multiply(input[1], L[2]) ^ gf256Multiply(input[2], L[3]) ^
|
|
14
|
+
gf256Multiply(input[3], L[4]) ^ gf256Multiply(input[4], L[5]) ^
|
|
15
|
+
gf256Multiply(input[5], L[6]) ^ gf256Multiply(input[6], L[7]) ^
|
|
16
|
+
gf256Multiply(input[7], L[8]) ^ gf256Multiply(input[8], L[9]) ^
|
|
17
|
+
gf256Multiply(input[9], L[10]) ^ gf256Multiply(input[10], L[11]) ^
|
|
18
|
+
gf256Multiply(input[11], L[12]) ^ gf256Multiply(input[12], L[13]) ^
|
|
19
|
+
gf256Multiply(input[13], L[14]) ^ gf256Multiply(input[14], L[15]),
|
|
32
20
|
...input.subarray(0, 15)
|
|
33
21
|
]);
|
|
34
22
|
const Rr = (input) => new Uint8Array([
|
|
35
23
|
...input.subarray(1, 16),
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
24
|
+
gf256Multiply(input[0], L[0]) ^ gf256Multiply(input[1], L[1]) ^
|
|
25
|
+
gf256Multiply(input[2], L[2]) ^ gf256Multiply(input[3], L[3]) ^
|
|
26
|
+
gf256Multiply(input[4], L[4]) ^ gf256Multiply(input[5], L[5]) ^
|
|
27
|
+
gf256Multiply(input[6], L[6]) ^ gf256Multiply(input[7], L[7]) ^
|
|
28
|
+
gf256Multiply(input[8], L[8]) ^ gf256Multiply(input[9], L[9]) ^
|
|
29
|
+
gf256Multiply(input[10], L[10]) ^ gf256Multiply(input[11], L[11]) ^
|
|
30
|
+
gf256Multiply(input[12], L[12]) ^ gf256Multiply(input[13], L[13]) ^
|
|
31
|
+
gf256Multiply(input[14], L[14]) ^ gf256Multiply(input[15], L[15])
|
|
44
32
|
]);
|
|
45
33
|
// Call `R` 16x times
|
|
46
34
|
const LL = (input) => R(R(R(R(R(R(R(R(R(R(R(R(R(R(R(R(input))))))))))))))));
|
|
@@ -61,10 +49,7 @@ export class Kuznyechik {
|
|
|
61
49
|
const roundKeys = Array(10);
|
|
62
50
|
roundKeys[0] = key.slice(0, this.blockSize);
|
|
63
51
|
roundKeys[1] = key.slice(this.blockSize);
|
|
64
|
-
let temp1 = copyBytes(roundKeys[0]);
|
|
65
|
-
let temp2 = copyBytes(roundKeys[1]);
|
|
66
|
-
let temp3 = new Uint8Array(16);
|
|
67
|
-
let temp4 = new Uint8Array(16);
|
|
52
|
+
let temp1 = copyBytes(roundKeys[0]), temp2 = copyBytes(roundKeys[1]), temp3 = new Uint8Array(16), temp4 = new Uint8Array(16);
|
|
68
53
|
for (let i = 0; i < 4; i++) {
|
|
69
54
|
const baseIndex = i * 8;
|
|
70
55
|
temp3 = F(temp1, temp2, ITER[baseIndex]);
|
package/magma/const.d.ts
CHANGED
|
@@ -1,58 +1,58 @@
|
|
|
1
1
|
/** S-Box from RFC 7836 */
|
|
2
|
-
export declare const ID_TC26_GOST_28147_PARAM_Z: Uint8Array<ArrayBuffer
|
|
2
|
+
export declare const ID_TC26_GOST_28147_PARAM_Z: Uint8Array<ArrayBuffer>;
|
|
3
3
|
/** S-Box from RFC 4357 aka `CryptoPro Paramset A` */
|
|
4
|
-
export declare const ID_GOST_28147_89_CRYPTO_PRO_A_PARAM_SET: Uint8Array<ArrayBuffer
|
|
4
|
+
export declare const ID_GOST_28147_89_CRYPTO_PRO_A_PARAM_SET: Uint8Array<ArrayBuffer>;
|
|
5
5
|
/** S-Box from RFC 4357 aka `CryptoPro Paramset B` */
|
|
6
|
-
export declare const ID_GOST_28147_89_CRYPTO_PRO_B_PARAM_SET: Uint8Array<ArrayBuffer
|
|
6
|
+
export declare const ID_GOST_28147_89_CRYPTO_PRO_B_PARAM_SET: Uint8Array<ArrayBuffer>;
|
|
7
7
|
/** S-Box from RFC 4357 aka `CryptoPro Paramset C` */
|
|
8
|
-
export declare const ID_GOST_28147_89_CRYPTO_PRO_C_PARAM_SET: Uint8Array<ArrayBuffer
|
|
8
|
+
export declare const ID_GOST_28147_89_CRYPTO_PRO_C_PARAM_SET: Uint8Array<ArrayBuffer>;
|
|
9
9
|
/** S-Box from RFC 4357 aka `CryptoPro Paramset D` */
|
|
10
|
-
export declare const ID_GOST_28147_89_CRYPTO_PRO_D_PARAM_SET: Uint8Array<ArrayBuffer
|
|
10
|
+
export declare const ID_GOST_28147_89_CRYPTO_PRO_D_PARAM_SET: Uint8Array<ArrayBuffer>;
|
|
11
11
|
/** S-Box from Instruction no. 114 by State Special Communications Service of Ukraine */
|
|
12
|
-
export declare const DSSZZI_UA_DKE_1: Uint8Array<ArrayBuffer
|
|
12
|
+
export declare const DSSZZI_UA_DKE_1: Uint8Array<ArrayBuffer>;
|
|
13
13
|
/** S-Box from Instruction no. 114 by State Special Communications Service of Ukraine */
|
|
14
|
-
export declare const DSSZZI_UA_DKE_2: Uint8Array<ArrayBuffer
|
|
14
|
+
export declare const DSSZZI_UA_DKE_2: Uint8Array<ArrayBuffer>;
|
|
15
15
|
/** S-Box from Instruction no. 114 by State Special Communications Service of Ukraine */
|
|
16
|
-
export declare const DSSZZI_UA_DKE_3: Uint8Array<ArrayBuffer
|
|
16
|
+
export declare const DSSZZI_UA_DKE_3: Uint8Array<ArrayBuffer>;
|
|
17
17
|
/** S-Box from Instruction no. 114 by State Special Communications Service of Ukraine */
|
|
18
|
-
export declare const DSSZZI_UA_DKE_4: Uint8Array<ArrayBuffer
|
|
18
|
+
export declare const DSSZZI_UA_DKE_4: Uint8Array<ArrayBuffer>;
|
|
19
19
|
/** S-Box from Instruction no. 114 by State Special Communications Service of Ukraine */
|
|
20
|
-
export declare const DSSZZI_UA_DKE_5: Uint8Array<ArrayBuffer
|
|
20
|
+
export declare const DSSZZI_UA_DKE_5: Uint8Array<ArrayBuffer>;
|
|
21
21
|
/** S-Box from Instruction no. 114 by State Special Communications Service of Ukraine */
|
|
22
|
-
export declare const DSSZZI_UA_DKE_6: Uint8Array<ArrayBuffer
|
|
22
|
+
export declare const DSSZZI_UA_DKE_6: Uint8Array<ArrayBuffer>;
|
|
23
23
|
/** S-Box from Instruction no. 114 by State Special Communications Service of Ukraine */
|
|
24
|
-
export declare const DSSZZI_UA_DKE_7: Uint8Array<ArrayBuffer
|
|
24
|
+
export declare const DSSZZI_UA_DKE_7: Uint8Array<ArrayBuffer>;
|
|
25
25
|
/** S-Box from Instruction no. 114 by State Special Communications Service of Ukraine */
|
|
26
|
-
export declare const DSSZZI_UA_DKE_8: Uint8Array<ArrayBuffer
|
|
26
|
+
export declare const DSSZZI_UA_DKE_8: Uint8Array<ArrayBuffer>;
|
|
27
27
|
/** S-Box from Instruction no. 114 by State Special Communications Service of Ukraine */
|
|
28
|
-
export declare const DSSZZI_UA_DKE_9: Uint8Array<ArrayBuffer
|
|
28
|
+
export declare const DSSZZI_UA_DKE_9: Uint8Array<ArrayBuffer>;
|
|
29
29
|
/** S-Box from Instruction no. 114 by State Special Communications Service of Ukraine */
|
|
30
|
-
export declare const DSSZZI_UA_DKE_10: Uint8Array<ArrayBuffer
|
|
31
|
-
export declare const ID_GOST_28147_89_TEST_PARAM_SET: Uint8Array<ArrayBuffer
|
|
32
|
-
export declare const ID_GOSTR_3411_94_TEST_PARAM_SET: Uint8Array<ArrayBuffer
|
|
33
|
-
export declare const ID_GOSTR_3411_94_CRYPTOPRO_PARAM_SET: Uint8Array<ArrayBuffer
|
|
34
|
-
export declare const EAC_PARAM_SET: Uint8Array<ArrayBuffer
|
|
30
|
+
export declare const DSSZZI_UA_DKE_10: Uint8Array<ArrayBuffer>;
|
|
31
|
+
export declare const ID_GOST_28147_89_TEST_PARAM_SET: Uint8Array<ArrayBuffer>;
|
|
32
|
+
export declare const ID_GOSTR_3411_94_TEST_PARAM_SET: Uint8Array<ArrayBuffer>;
|
|
33
|
+
export declare const ID_GOSTR_3411_94_CRYPTOPRO_PARAM_SET: Uint8Array<ArrayBuffer>;
|
|
34
|
+
export declare const EAC_PARAM_SET: Uint8Array<ArrayBuffer>;
|
|
35
35
|
/** Implemented S-Boxes */
|
|
36
36
|
export declare const magmaSboxes: {
|
|
37
|
-
ID_TC26_GOST_28147_PARAM_Z: Uint8Array<ArrayBuffer
|
|
38
|
-
ID_GOST_28147_89_CRYPTO_PRO_A_PARAM_SET: Uint8Array<ArrayBuffer
|
|
39
|
-
ID_GOST_28147_89_CRYPTO_PRO_B_PARAM_SET: Uint8Array<ArrayBuffer
|
|
40
|
-
ID_GOST_28147_89_CRYPTO_PRO_C_PARAM_SET: Uint8Array<ArrayBuffer
|
|
41
|
-
ID_GOST_28147_89_CRYPTO_PRO_D_PARAM_SET: Uint8Array<ArrayBuffer
|
|
42
|
-
ID_GOST_28147_89_TEST_PARAM_SET: Uint8Array<ArrayBuffer
|
|
43
|
-
ID_GOSTR_3411_94_TEST_PARAM_SET: Uint8Array<ArrayBuffer
|
|
44
|
-
ID_GOSTR_3411_94_CRYPTOPRO_PARAM_SET: Uint8Array<ArrayBuffer
|
|
45
|
-
EAC_PARAM_SET: Uint8Array<ArrayBuffer
|
|
46
|
-
DSSZZI_UA_DKE_1: Uint8Array<ArrayBuffer
|
|
47
|
-
DSSZZI_UA_DKE_2: Uint8Array<ArrayBuffer
|
|
48
|
-
DSSZZI_UA_DKE_3: Uint8Array<ArrayBuffer
|
|
49
|
-
DSSZZI_UA_DKE_4: Uint8Array<ArrayBuffer
|
|
50
|
-
DSSZZI_UA_DKE_5: Uint8Array<ArrayBuffer
|
|
51
|
-
DSSZZI_UA_DKE_6: Uint8Array<ArrayBuffer
|
|
52
|
-
DSSZZI_UA_DKE_7: Uint8Array<ArrayBuffer
|
|
53
|
-
DSSZZI_UA_DKE_8: Uint8Array<ArrayBuffer
|
|
54
|
-
DSSZZI_UA_DKE_9: Uint8Array<ArrayBuffer
|
|
55
|
-
DSSZZI_UA_DKE_10: Uint8Array<ArrayBuffer
|
|
37
|
+
ID_TC26_GOST_28147_PARAM_Z: Uint8Array<ArrayBuffer>;
|
|
38
|
+
ID_GOST_28147_89_CRYPTO_PRO_A_PARAM_SET: Uint8Array<ArrayBuffer>;
|
|
39
|
+
ID_GOST_28147_89_CRYPTO_PRO_B_PARAM_SET: Uint8Array<ArrayBuffer>;
|
|
40
|
+
ID_GOST_28147_89_CRYPTO_PRO_C_PARAM_SET: Uint8Array<ArrayBuffer>;
|
|
41
|
+
ID_GOST_28147_89_CRYPTO_PRO_D_PARAM_SET: Uint8Array<ArrayBuffer>;
|
|
42
|
+
ID_GOST_28147_89_TEST_PARAM_SET: Uint8Array<ArrayBuffer>;
|
|
43
|
+
ID_GOSTR_3411_94_TEST_PARAM_SET: Uint8Array<ArrayBuffer>;
|
|
44
|
+
ID_GOSTR_3411_94_CRYPTOPRO_PARAM_SET: Uint8Array<ArrayBuffer>;
|
|
45
|
+
EAC_PARAM_SET: Uint8Array<ArrayBuffer>;
|
|
46
|
+
DSSZZI_UA_DKE_1: Uint8Array<ArrayBuffer>;
|
|
47
|
+
DSSZZI_UA_DKE_2: Uint8Array<ArrayBuffer>;
|
|
48
|
+
DSSZZI_UA_DKE_3: Uint8Array<ArrayBuffer>;
|
|
49
|
+
DSSZZI_UA_DKE_4: Uint8Array<ArrayBuffer>;
|
|
50
|
+
DSSZZI_UA_DKE_5: Uint8Array<ArrayBuffer>;
|
|
51
|
+
DSSZZI_UA_DKE_6: Uint8Array<ArrayBuffer>;
|
|
52
|
+
DSSZZI_UA_DKE_7: Uint8Array<ArrayBuffer>;
|
|
53
|
+
DSSZZI_UA_DKE_8: Uint8Array<ArrayBuffer>;
|
|
54
|
+
DSSZZI_UA_DKE_9: Uint8Array<ArrayBuffer>;
|
|
55
|
+
DSSZZI_UA_DKE_10: Uint8Array<ArrayBuffer>;
|
|
56
56
|
};
|
|
57
57
|
/** Sequences of `K_i` S-Box applying */
|
|
58
58
|
export declare const magmaKeySequences: {
|
package/magma/const.js
CHANGED
|
@@ -1,209 +1,209 @@
|
|
|
1
1
|
/** S-Box from RFC 7836 */
|
|
2
|
-
export const ID_TC26_GOST_28147_PARAM_Z = [
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
];
|
|
2
|
+
export const ID_TC26_GOST_28147_PARAM_Z = new Uint8Array([
|
|
3
|
+
0x0c, 0x04, 0x06, 0x02, 0x0a, 0x05, 0x0b, 0x09, 0x0e, 0x08, 0x0d, 0x07, 0x00, 0x03, 0x0f, 0x01,
|
|
4
|
+
0x06, 0x08, 0x02, 0x03, 0x09, 0x0a, 0x05, 0x0c, 0x01, 0x0e, 0x04, 0x07, 0x0b, 0x0d, 0x00, 0x0f,
|
|
5
|
+
0x0b, 0x03, 0x05, 0x08, 0x02, 0x0f, 0x0a, 0x0d, 0x0e, 0x01, 0x07, 0x04, 0x0c, 0x09, 0x06, 0x00,
|
|
6
|
+
0x0c, 0x08, 0x02, 0x01, 0x0d, 0x04, 0x0f, 0x06, 0x07, 0x00, 0x0a, 0x05, 0x03, 0x0e, 0x09, 0x0b,
|
|
7
|
+
0x07, 0x0f, 0x05, 0x0a, 0x08, 0x01, 0x06, 0x0d, 0x00, 0x09, 0x03, 0x0e, 0x0b, 0x04, 0x02, 0x0c,
|
|
8
|
+
0x05, 0x0d, 0x0f, 0x06, 0x09, 0x02, 0x0c, 0x0a, 0x0b, 0x07, 0x08, 0x01, 0x04, 0x03, 0x0e, 0x00,
|
|
9
|
+
0x08, 0x0e, 0x02, 0x05, 0x06, 0x09, 0x01, 0x0c, 0x0f, 0x04, 0x0b, 0x00, 0x0d, 0x0a, 0x03, 0x07,
|
|
10
|
+
0x01, 0x07, 0x0e, 0x0d, 0x00, 0x05, 0x08, 0x03, 0x04, 0x0f, 0x0a, 0x06, 0x09, 0x0c, 0x0b, 0x02,
|
|
11
|
+
]);
|
|
12
12
|
/** S-Box from RFC 4357 aka `CryptoPro Paramset A` */
|
|
13
|
-
export const ID_GOST_28147_89_CRYPTO_PRO_A_PARAM_SET = [
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
];
|
|
13
|
+
export const ID_GOST_28147_89_CRYPTO_PRO_A_PARAM_SET = new Uint8Array([
|
|
14
|
+
0x09, 0x06, 0x03, 0x02, 0x08, 0x0b, 0x01, 0x07, 0x0a, 0x04, 0x0e, 0x0f, 0x0c, 0x00, 0x0d, 0x05,
|
|
15
|
+
0x03, 0x07, 0x0e, 0x09, 0x08, 0x0a, 0x0f, 0x00, 0x05, 0x02, 0x06, 0x0c, 0x0b, 0x04, 0x0d, 0x01,
|
|
16
|
+
0x0e, 0x04, 0x06, 0x02, 0x0b, 0x03, 0x0d, 0x08, 0x0c, 0x0f, 0x05, 0x0a, 0x00, 0x07, 0x01, 0x09,
|
|
17
|
+
0x0e, 0x07, 0x0a, 0x0c, 0x0d, 0x01, 0x03, 0x09, 0x00, 0x02, 0x0b, 0x04, 0x0f, 0x08, 0x05, 0x06,
|
|
18
|
+
0x0b, 0x05, 0x01, 0x09, 0x08, 0x0d, 0x0f, 0x00, 0x0e, 0x04, 0x02, 0x03, 0x0c, 0x07, 0x0a, 0x06,
|
|
19
|
+
0x03, 0x0a, 0x0d, 0x0c, 0x01, 0x02, 0x00, 0x0b, 0x07, 0x05, 0x09, 0x04, 0x08, 0x0f, 0x0e, 0x06,
|
|
20
|
+
0x01, 0x0d, 0x02, 0x09, 0x07, 0x0a, 0x06, 0x00, 0x08, 0x0c, 0x04, 0x05, 0x0f, 0x03, 0x0b, 0x0e,
|
|
21
|
+
0x0b, 0x0a, 0x0f, 0x05, 0x00, 0x0c, 0x0e, 0x08, 0x06, 0x02, 0x03, 0x09, 0x01, 0x07, 0x0d, 0x04,
|
|
22
|
+
]);
|
|
23
23
|
/** S-Box from RFC 4357 aka `CryptoPro Paramset B` */
|
|
24
|
-
export const ID_GOST_28147_89_CRYPTO_PRO_B_PARAM_SET = [
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
];
|
|
24
|
+
export const ID_GOST_28147_89_CRYPTO_PRO_B_PARAM_SET = new Uint8Array([
|
|
25
|
+
0x08, 0x04, 0x0b, 0x01, 0x03, 0x05, 0x00, 0x09, 0x02, 0x0e, 0x0a, 0x0c, 0x0d, 0x06, 0x07, 0x0f,
|
|
26
|
+
0x00, 0x01, 0x02, 0x0a, 0x04, 0x0d, 0x05, 0x0c, 0x09, 0x07, 0x03, 0x0f, 0x0b, 0x08, 0x06, 0x0e,
|
|
27
|
+
0x0e, 0x0c, 0x00, 0x0a, 0x09, 0x02, 0x0d, 0x0b, 0x07, 0x05, 0x08, 0x0f, 0x03, 0x06, 0x01, 0x04,
|
|
28
|
+
0x07, 0x05, 0x00, 0x0d, 0x0b, 0x06, 0x01, 0x02, 0x03, 0x0a, 0x0c, 0x0f, 0x04, 0x0e, 0x09, 0x08,
|
|
29
|
+
0x02, 0x07, 0x0c, 0x0f, 0x09, 0x05, 0x0a, 0x0b, 0x01, 0x04, 0x00, 0x0d, 0x06, 0x08, 0x0e, 0x03,
|
|
30
|
+
0x08, 0x03, 0x02, 0x06, 0x04, 0x0d, 0x0e, 0x0b, 0x0c, 0x01, 0x07, 0x0f, 0x0a, 0x00, 0x09, 0x05,
|
|
31
|
+
0x05, 0x02, 0x0a, 0x0b, 0x09, 0x01, 0x0c, 0x03, 0x07, 0x04, 0x0d, 0x00, 0x06, 0x0f, 0x08, 0x0e,
|
|
32
|
+
0x00, 0x04, 0x0b, 0x0e, 0x08, 0x03, 0x07, 0x01, 0x0a, 0x02, 0x09, 0x06, 0x0f, 0x0d, 0x05, 0x0c,
|
|
33
|
+
]);
|
|
34
34
|
/** S-Box from RFC 4357 aka `CryptoPro Paramset C` */
|
|
35
|
-
export const ID_GOST_28147_89_CRYPTO_PRO_C_PARAM_SET = [
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
];
|
|
35
|
+
export const ID_GOST_28147_89_CRYPTO_PRO_C_PARAM_SET = new Uint8Array([
|
|
36
|
+
0x01, 0x0b, 0x0c, 0x02, 0x09, 0x0d, 0x00, 0x0f, 0x04, 0x05, 0x08, 0x0e, 0x0a, 0x07, 0x06, 0x03,
|
|
37
|
+
0x00, 0x01, 0x07, 0x0d, 0x0b, 0x04, 0x05, 0x02, 0x08, 0x0e, 0x0f, 0x0c, 0x09, 0x0a, 0x06, 0x03,
|
|
38
|
+
0x08, 0x02, 0x05, 0x00, 0x04, 0x09, 0x0f, 0x0a, 0x03, 0x07, 0x0c, 0x0d, 0x06, 0x0e, 0x01, 0x0b,
|
|
39
|
+
0x03, 0x06, 0x00, 0x01, 0x05, 0x0d, 0x0a, 0x08, 0x0b, 0x02, 0x09, 0x07, 0x0e, 0x0f, 0x0c, 0x04,
|
|
40
|
+
0x08, 0x0d, 0x0b, 0x00, 0x04, 0x05, 0x01, 0x02, 0x09, 0x03, 0x0c, 0x0e, 0x06, 0x0f, 0x0a, 0x07,
|
|
41
|
+
0x0c, 0x09, 0x0b, 0x01, 0x08, 0x0e, 0x02, 0x04, 0x07, 0x03, 0x06, 0x05, 0x0a, 0x00, 0x0f, 0x0d,
|
|
42
|
+
0x0a, 0x09, 0x06, 0x08, 0x0d, 0x0e, 0x02, 0x00, 0x0f, 0x03, 0x05, 0x0b, 0x04, 0x01, 0x0c, 0x07,
|
|
43
|
+
0x07, 0x04, 0x00, 0x05, 0x0a, 0x02, 0x0f, 0x0e, 0x0c, 0x06, 0x01, 0x0b, 0x0d, 0x09, 0x03, 0x08,
|
|
44
|
+
]);
|
|
45
45
|
/** S-Box from RFC 4357 aka `CryptoPro Paramset D` */
|
|
46
|
-
export const ID_GOST_28147_89_CRYPTO_PRO_D_PARAM_SET = [
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
];
|
|
46
|
+
export const ID_GOST_28147_89_CRYPTO_PRO_D_PARAM_SET = new Uint8Array([
|
|
47
|
+
0x0f, 0x0c, 0x02, 0x0a, 0x06, 0x04, 0x05, 0x00, 0x07, 0x09, 0x0e, 0x0d, 0x01, 0x0b, 0x08, 0x03,
|
|
48
|
+
0x0b, 0x06, 0x03, 0x04, 0x0c, 0x0f, 0x0e, 0x02, 0x07, 0x0d, 0x08, 0x00, 0x05, 0x0a, 0x09, 0x01,
|
|
49
|
+
0x01, 0x0c, 0x0b, 0x00, 0x0f, 0x0e, 0x06, 0x05, 0x0a, 0x0d, 0x04, 0x08, 0x09, 0x03, 0x07, 0x02,
|
|
50
|
+
0x01, 0x05, 0x0e, 0x0c, 0x0a, 0x07, 0x00, 0x0d, 0x06, 0x02, 0x0b, 0x04, 0x09, 0x03, 0x0f, 0x08,
|
|
51
|
+
0x00, 0x0c, 0x08, 0x09, 0x0d, 0x02, 0x0a, 0x0b, 0x07, 0x03, 0x06, 0x05, 0x04, 0x0e, 0x0f, 0x01,
|
|
52
|
+
0x08, 0x00, 0x0f, 0x03, 0x02, 0x05, 0x0e, 0x0b, 0x01, 0x0a, 0x04, 0x07, 0x0c, 0x09, 0x0d, 0x06,
|
|
53
|
+
0x03, 0x00, 0x06, 0x0f, 0x01, 0x0e, 0x09, 0x02, 0x0d, 0x08, 0x0c, 0x04, 0x0b, 0x0a, 0x05, 0x07,
|
|
54
|
+
0x01, 0x0a, 0x06, 0x08, 0x0f, 0x0b, 0x00, 0x04, 0x0c, 0x03, 0x05, 0x09, 0x07, 0x0d, 0x02, 0x0e,
|
|
55
|
+
]);
|
|
56
56
|
/** S-Box from Instruction no. 114 by State Special Communications Service of Ukraine */
|
|
57
|
-
export const DSSZZI_UA_DKE_1 = [
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
];
|
|
57
|
+
export const DSSZZI_UA_DKE_1 = new Uint8Array([
|
|
58
|
+
0x0a, 0x09, 0x0d, 0x06, 0x0e, 0x0b, 0x04, 0x05, 0x0f, 0x01, 0x03, 0x0c, 0x07, 0x00, 0x08, 0x02,
|
|
59
|
+
0x08, 0x00, 0x0c, 0x04, 0x09, 0x06, 0x07, 0x0b, 0x02, 0x03, 0x01, 0x0f, 0x05, 0x0e, 0x0a, 0x0d,
|
|
60
|
+
0x0f, 0x06, 0x05, 0x08, 0x0e, 0x0b, 0x0a, 0x04, 0x0c, 0x00, 0x03, 0x07, 0x02, 0x09, 0x01, 0x0d,
|
|
61
|
+
0x03, 0x08, 0x0d, 0x09, 0x06, 0x0b, 0x0f, 0x00, 0x02, 0x05, 0x0c, 0x0a, 0x04, 0x0e, 0x01, 0x07,
|
|
62
|
+
0x0f, 0x08, 0x0e, 0x09, 0x07, 0x02, 0x00, 0x0d, 0x0c, 0x06, 0x01, 0x05, 0x0b, 0x04, 0x03, 0x0a,
|
|
63
|
+
0x02, 0x08, 0x09, 0x07, 0x05, 0x0f, 0x00, 0x0b, 0x0c, 0x01, 0x0d, 0x0e, 0x0a, 0x03, 0x06, 0x04,
|
|
64
|
+
0x03, 0x08, 0x0b, 0x05, 0x06, 0x04, 0x0e, 0x0a, 0x02, 0x0c, 0x01, 0x07, 0x09, 0x0f, 0x0d, 0x00,
|
|
65
|
+
0x01, 0x02, 0x03, 0x0e, 0x06, 0x0d, 0x0b, 0x08, 0x0f, 0x0a, 0x0c, 0x05, 0x07, 0x09, 0x00, 0x04,
|
|
66
|
+
]);
|
|
67
67
|
// Converted from tables by script, accuracy not guaranteed
|
|
68
68
|
/** S-Box from Instruction no. 114 by State Special Communications Service of Ukraine */
|
|
69
|
-
export const DSSZZI_UA_DKE_2 = [
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
];
|
|
69
|
+
export const DSSZZI_UA_DKE_2 = new Uint8Array([
|
|
70
|
+
0x0e, 0x09, 0x03, 0x07, 0x0f, 0x04, 0x0c, 0x0b, 0x06, 0x0a, 0x0d, 0x01, 0x00, 0x05, 0x08, 0x02,
|
|
71
|
+
0x0a, 0x0d, 0x0c, 0x07, 0x06, 0x0e, 0x08, 0x01, 0x0f, 0x03, 0x0b, 0x04, 0x00, 0x09, 0x05, 0x02,
|
|
72
|
+
0x04, 0x0b, 0x01, 0x0f, 0x09, 0x02, 0x0e, 0x0c, 0x06, 0x0a, 0x08, 0x07, 0x03, 0x05, 0x00, 0x0d,
|
|
73
|
+
0x04, 0x05, 0x01, 0x0c, 0x07, 0x0e, 0x09, 0x02, 0x0a, 0x0f, 0x0b, 0x0d, 0x00, 0x08, 0x06, 0x03,
|
|
74
|
+
0x0c, 0x0b, 0x03, 0x09, 0x0f, 0x00, 0x04, 0x05, 0x07, 0x02, 0x0e, 0x0d, 0x01, 0x0a, 0x08, 0x06,
|
|
75
|
+
0x08, 0x07, 0x03, 0x0a, 0x09, 0x06, 0x0e, 0x05, 0x0d, 0x00, 0x04, 0x0c, 0x01, 0x02, 0x0f, 0x0b,
|
|
76
|
+
0x0f, 0x00, 0x0e, 0x06, 0x08, 0x0d, 0x05, 0x09, 0x0a, 0x03, 0x01, 0x0c, 0x04, 0x0b, 0x07, 0x02,
|
|
77
|
+
0x04, 0x03, 0x0e, 0x0d, 0x05, 0x00, 0x02, 0x0b, 0x01, 0x0a, 0x07, 0x06, 0x09, 0x0f, 0x08, 0x0c,
|
|
78
|
+
]);
|
|
79
79
|
/** S-Box from Instruction no. 114 by State Special Communications Service of Ukraine */
|
|
80
|
-
export const DSSZZI_UA_DKE_3 = [
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
];
|
|
80
|
+
export const DSSZZI_UA_DKE_3 = new Uint8Array([
|
|
81
|
+
0x0d, 0x09, 0x01, 0x0e, 0x07, 0x02, 0x0c, 0x05, 0x04, 0x0b, 0x06, 0x0f, 0x03, 0x08, 0x0a, 0x00,
|
|
82
|
+
0x07, 0x08, 0x06, 0x0b, 0x00, 0x03, 0x04, 0x0d, 0x09, 0x05, 0x0f, 0x0e, 0x0a, 0x0c, 0x02, 0x01,
|
|
83
|
+
0x0a, 0x05, 0x03, 0x0c, 0x09, 0x08, 0x0d, 0x06, 0x04, 0x0f, 0x0e, 0x00, 0x02, 0x0b, 0x01, 0x07,
|
|
84
|
+
0x0b, 0x0a, 0x0c, 0x01, 0x05, 0x06, 0x09, 0x0e, 0x02, 0x0d, 0x0f, 0x07, 0x00, 0x04, 0x03, 0x08,
|
|
85
|
+
0x05, 0x0b, 0x03, 0x00, 0x0f, 0x09, 0x0e, 0x04, 0x01, 0x0c, 0x08, 0x06, 0x02, 0x0a, 0x07, 0x0d,
|
|
86
|
+
0x04, 0x03, 0x0b, 0x0d, 0x01, 0x0f, 0x08, 0x02, 0x07, 0x0e, 0x0c, 0x09, 0x0a, 0x00, 0x06, 0x05,
|
|
87
|
+
0x03, 0x07, 0x08, 0x0b, 0x01, 0x0e, 0x05, 0x00, 0x0d, 0x04, 0x0c, 0x0a, 0x02, 0x09, 0x0f, 0x06,
|
|
88
|
+
0x06, 0x0d, 0x0c, 0x0a, 0x0b, 0x07, 0x09, 0x03, 0x0f, 0x0e, 0x01, 0x02, 0x00, 0x08, 0x04, 0x05,
|
|
89
|
+
]);
|
|
90
90
|
/** S-Box from Instruction no. 114 by State Special Communications Service of Ukraine */
|
|
91
|
-
export const DSSZZI_UA_DKE_4 = [
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
];
|
|
91
|
+
export const DSSZZI_UA_DKE_4 = new Uint8Array([
|
|
92
|
+
0x09, 0x0c, 0x03, 0x0d, 0x07, 0x06, 0x0e, 0x01, 0x0a, 0x02, 0x00, 0x04, 0x08, 0x0f, 0x05, 0x0b,
|
|
93
|
+
0x0a, 0x05, 0x0b, 0x0e, 0x07, 0x06, 0x00, 0x0c, 0x02, 0x08, 0x0f, 0x04, 0x0d, 0x03, 0x09, 0x01,
|
|
94
|
+
0x04, 0x0c, 0x03, 0x00, 0x0d, 0x02, 0x0e, 0x0b, 0x07, 0x0f, 0x05, 0x09, 0x01, 0x08, 0x0a, 0x06,
|
|
95
|
+
0x03, 0x09, 0x04, 0x05, 0x0e, 0x07, 0x08, 0x06, 0x0d, 0x00, 0x02, 0x0f, 0x0b, 0x0c, 0x0a, 0x01,
|
|
96
|
+
0x02, 0x09, 0x0c, 0x0f, 0x0d, 0x0b, 0x04, 0x01, 0x07, 0x05, 0x03, 0x0e, 0x06, 0x08, 0x0a, 0x00,
|
|
97
|
+
0x0e, 0x05, 0x0d, 0x0b, 0x01, 0x09, 0x04, 0x02, 0x0f, 0x08, 0x07, 0x00, 0x03, 0x0c, 0x0a, 0x06,
|
|
98
|
+
0x0e, 0x06, 0x05, 0x0a, 0x09, 0x0d, 0x04, 0x08, 0x0b, 0x0c, 0x00, 0x03, 0x07, 0x01, 0x0f, 0x02,
|
|
99
|
+
0x01, 0x09, 0x0c, 0x0b, 0x07, 0x06, 0x08, 0x03, 0x02, 0x0f, 0x0e, 0x00, 0x05, 0x0a, 0x04, 0x0d,
|
|
100
|
+
]);
|
|
101
101
|
/** S-Box from Instruction no. 114 by State Special Communications Service of Ukraine */
|
|
102
|
-
export const DSSZZI_UA_DKE_5 = [
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
];
|
|
102
|
+
export const DSSZZI_UA_DKE_5 = new Uint8Array([
|
|
103
|
+
0x03, 0x04, 0x0d, 0x08, 0x0c, 0x07, 0x0a, 0x02, 0x00, 0x0e, 0x09, 0x0f, 0x0b, 0x01, 0x05, 0x06,
|
|
104
|
+
0x0c, 0x07, 0x06, 0x09, 0x03, 0x08, 0x0b, 0x05, 0x0f, 0x0a, 0x00, 0x0d, 0x04, 0x02, 0x01, 0x0e,
|
|
105
|
+
0x0e, 0x04, 0x08, 0x07, 0x0b, 0x03, 0x0a, 0x0c, 0x01, 0x02, 0x06, 0x09, 0x0d, 0x0f, 0x00, 0x05,
|
|
106
|
+
0x03, 0x09, 0x06, 0x0d, 0x08, 0x0f, 0x0a, 0x02, 0x07, 0x0e, 0x0c, 0x00, 0x0b, 0x04, 0x01, 0x05,
|
|
107
|
+
0x05, 0x0c, 0x0a, 0x07, 0x02, 0x01, 0x0f, 0x0d, 0x0e, 0x03, 0x0b, 0x04, 0x00, 0x08, 0x09, 0x06,
|
|
108
|
+
0x01, 0x08, 0x0b, 0x0e, 0x07, 0x04, 0x0a, 0x00, 0x0c, 0x03, 0x05, 0x0d, 0x09, 0x0f, 0x06, 0x02,
|
|
109
|
+
0x09, 0x0b, 0x0a, 0x0d, 0x05, 0x0e, 0x02, 0x03, 0x00, 0x06, 0x04, 0x0c, 0x0f, 0x01, 0x07, 0x08,
|
|
110
|
+
0x0e, 0x09, 0x01, 0x08, 0x05, 0x0f, 0x0b, 0x00, 0x06, 0x02, 0x0c, 0x07, 0x0a, 0x04, 0x0d, 0x03,
|
|
111
|
+
]);
|
|
112
112
|
/** S-Box from Instruction no. 114 by State Special Communications Service of Ukraine */
|
|
113
|
-
export const DSSZZI_UA_DKE_6 = [
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
];
|
|
113
|
+
export const DSSZZI_UA_DKE_6 = new Uint8Array([
|
|
114
|
+
0x0f, 0x0c, 0x09, 0x06, 0x0e, 0x02, 0x01, 0x0b, 0x00, 0x0d, 0x04, 0x0a, 0x07, 0x08, 0x03, 0x05,
|
|
115
|
+
0x0e, 0x0c, 0x05, 0x00, 0x07, 0x04, 0x0a, 0x03, 0x02, 0x06, 0x01, 0x0d, 0x09, 0x0b, 0x0f, 0x08,
|
|
116
|
+
0x05, 0x06, 0x0d, 0x09, 0x0b, 0x0e, 0x0a, 0x03, 0x0f, 0x02, 0x08, 0x01, 0x04, 0x00, 0x07, 0x0c,
|
|
117
|
+
0x01, 0x0f, 0x07, 0x04, 0x02, 0x0e, 0x0c, 0x03, 0x06, 0x0b, 0x09, 0x08, 0x00, 0x05, 0x0a, 0x0d,
|
|
118
|
+
0x0f, 0x09, 0x0e, 0x06, 0x0d, 0x01, 0x05, 0x08, 0x04, 0x02, 0x03, 0x0c, 0x0a, 0x0b, 0x00, 0x07,
|
|
119
|
+
0x0b, 0x00, 0x0d, 0x07, 0x0c, 0x0e, 0x01, 0x04, 0x02, 0x03, 0x06, 0x08, 0x0a, 0x05, 0x0f, 0x09,
|
|
120
|
+
0x07, 0x0e, 0x0f, 0x08, 0x0d, 0x00, 0x0b, 0x03, 0x0a, 0x01, 0x04, 0x02, 0x09, 0x0c, 0x06, 0x05,
|
|
121
|
+
0x01, 0x05, 0x0e, 0x0b, 0x02, 0x0c, 0x03, 0x08, 0x0a, 0x00, 0x09, 0x07, 0x0f, 0x06, 0x04, 0x0d,
|
|
122
|
+
]);
|
|
123
123
|
/** S-Box from Instruction no. 114 by State Special Communications Service of Ukraine */
|
|
124
|
-
export const DSSZZI_UA_DKE_7 = [
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
];
|
|
124
|
+
export const DSSZZI_UA_DKE_7 = new Uint8Array([
|
|
125
|
+
0x0f, 0x0d, 0x0a, 0x05, 0x0c, 0x00, 0x01, 0x06, 0x09, 0x02, 0x0e, 0x07, 0x03, 0x0b, 0x04, 0x08,
|
|
126
|
+
0x02, 0x05, 0x0a, 0x00, 0x06, 0x09, 0x01, 0x0f, 0x0d, 0x04, 0x07, 0x0e, 0x0b, 0x03, 0x08, 0x0c,
|
|
127
|
+
0x03, 0x0e, 0x04, 0x0b, 0x05, 0x09, 0x01, 0x02, 0x0f, 0x06, 0x08, 0x0d, 0x07, 0x00, 0x0a, 0x0c,
|
|
128
|
+
0x04, 0x0a, 0x0b, 0x09, 0x0f, 0x02, 0x0e, 0x05, 0x0d, 0x01, 0x03, 0x06, 0x00, 0x07, 0x0c, 0x08,
|
|
129
|
+
0x0f, 0x06, 0x05, 0x08, 0x09, 0x07, 0x0c, 0x0b, 0x00, 0x0a, 0x03, 0x01, 0x02, 0x04, 0x0d, 0x0e,
|
|
130
|
+
0x0c, 0x0b, 0x0f, 0x04, 0x05, 0x01, 0x0e, 0x09, 0x00, 0x08, 0x0d, 0x02, 0x0a, 0x07, 0x03, 0x06,
|
|
131
|
+
0x0d, 0x02, 0x04, 0x08, 0x0b, 0x0c, 0x01, 0x03, 0x0a, 0x05, 0x09, 0x0e, 0x07, 0x0f, 0x00, 0x06,
|
|
132
|
+
0x01, 0x05, 0x00, 0x0f, 0x06, 0x0a, 0x03, 0x0e, 0x07, 0x02, 0x0c, 0x0d, 0x0b, 0x08, 0x09, 0x04,
|
|
133
|
+
]);
|
|
134
134
|
/** S-Box from Instruction no. 114 by State Special Communications Service of Ukraine */
|
|
135
|
-
export const DSSZZI_UA_DKE_8 = [
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
];
|
|
135
|
+
export const DSSZZI_UA_DKE_8 = new Uint8Array([
|
|
136
|
+
0x0e, 0x04, 0x0b, 0x02, 0x08, 0x07, 0x05, 0x0c, 0x09, 0x0d, 0x00, 0x03, 0x01, 0x0f, 0x06, 0x0a,
|
|
137
|
+
0x03, 0x0e, 0x0c, 0x0a, 0x06, 0x02, 0x0d, 0x01, 0x09, 0x08, 0x07, 0x04, 0x00, 0x0f, 0x05, 0x0b,
|
|
138
|
+
0x05, 0x02, 0x08, 0x07, 0x01, 0x0f, 0x0e, 0x06, 0x04, 0x0d, 0x0b, 0x00, 0x0a, 0x03, 0x0c, 0x09,
|
|
139
|
+
0x0c, 0x0a, 0x07, 0x0d, 0x0e, 0x03, 0x00, 0x02, 0x09, 0x05, 0x01, 0x06, 0x0b, 0x04, 0x0f, 0x08,
|
|
140
|
+
0x06, 0x03, 0x0f, 0x07, 0x00, 0x09, 0x0a, 0x08, 0x0b, 0x0c, 0x04, 0x01, 0x05, 0x02, 0x0d, 0x0e,
|
|
141
|
+
0x06, 0x0d, 0x0f, 0x01, 0x05, 0x03, 0x08, 0x00, 0x0b, 0x0a, 0x0e, 0x04, 0x09, 0x0c, 0x02, 0x07,
|
|
142
|
+
0x02, 0x0f, 0x0c, 0x05, 0x0b, 0x01, 0x03, 0x0e, 0x00, 0x06, 0x0d, 0x0a, 0x07, 0x09, 0x04, 0x08,
|
|
143
|
+
0x03, 0x00, 0x05, 0x0c, 0x08, 0x0f, 0x0d, 0x0e, 0x0b, 0x06, 0x02, 0x09, 0x07, 0x01, 0x04, 0x0a,
|
|
144
|
+
]);
|
|
145
145
|
/** S-Box from Instruction no. 114 by State Special Communications Service of Ukraine */
|
|
146
|
-
export const DSSZZI_UA_DKE_9 = [
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
];
|
|
146
|
+
export const DSSZZI_UA_DKE_9 = new Uint8Array([
|
|
147
|
+
0x09, 0x00, 0x0b, 0x0c, 0x02, 0x04, 0x03, 0x0f, 0x0d, 0x06, 0x0e, 0x01, 0x0a, 0x07, 0x05, 0x08,
|
|
148
|
+
0x03, 0x05, 0x00, 0x0f, 0x08, 0x07, 0x0e, 0x0c, 0x0d, 0x0a, 0x01, 0x06, 0x0b, 0x02, 0x04, 0x09,
|
|
149
|
+
0x08, 0x04, 0x05, 0x0a, 0x0e, 0x0b, 0x0d, 0x06, 0x0c, 0x0f, 0x07, 0x09, 0x03, 0x01, 0x02, 0x00,
|
|
150
|
+
0x05, 0x04, 0x0f, 0x00, 0x0c, 0x0b, 0x0a, 0x09, 0x01, 0x0e, 0x08, 0x06, 0x03, 0x02, 0x0d, 0x07,
|
|
151
|
+
0x07, 0x0c, 0x03, 0x00, 0x06, 0x08, 0x0e, 0x0b, 0x01, 0x0f, 0x0d, 0x0a, 0x09, 0x05, 0x02, 0x04,
|
|
152
|
+
0x07, 0x04, 0x03, 0x0b, 0x06, 0x0a, 0x08, 0x01, 0x09, 0x0c, 0x0e, 0x0d, 0x00, 0x0f, 0x02, 0x05,
|
|
153
|
+
0x07, 0x0e, 0x09, 0x0f, 0x01, 0x04, 0x08, 0x03, 0x0b, 0x0d, 0x00, 0x02, 0x06, 0x0a, 0x05, 0x0c,
|
|
154
|
+
0x0e, 0x02, 0x08, 0x0f, 0x03, 0x00, 0x07, 0x0c, 0x0b, 0x0d, 0x01, 0x05, 0x06, 0x04, 0x09, 0x0a,
|
|
155
|
+
]);
|
|
156
156
|
/** S-Box from Instruction no. 114 by State Special Communications Service of Ukraine */
|
|
157
|
-
export const DSSZZI_UA_DKE_10 = [
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
];
|
|
167
|
-
export const ID_GOST_28147_89_TEST_PARAM_SET = [
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
];
|
|
177
|
-
export const ID_GOSTR_3411_94_TEST_PARAM_SET = [
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
];
|
|
187
|
-
export const ID_GOSTR_3411_94_CRYPTOPRO_PARAM_SET = [
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
];
|
|
197
|
-
export const EAC_PARAM_SET = [
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
];
|
|
157
|
+
export const DSSZZI_UA_DKE_10 = new Uint8Array([
|
|
158
|
+
0x08, 0x04, 0x06, 0x09, 0x0b, 0x0c, 0x01, 0x02, 0x03, 0x07, 0x0e, 0x00, 0x0d, 0x0a, 0x0f, 0x05,
|
|
159
|
+
0x07, 0x0d, 0x01, 0x08, 0x0a, 0x0e, 0x04, 0x0f, 0x09, 0x00, 0x06, 0x03, 0x02, 0x0c, 0x0b, 0x05,
|
|
160
|
+
0x0c, 0x08, 0x0d, 0x01, 0x0a, 0x02, 0x09, 0x06, 0x03, 0x04, 0x0e, 0x07, 0x05, 0x0f, 0x00, 0x0b,
|
|
161
|
+
0x02, 0x0b, 0x03, 0x04, 0x0c, 0x07, 0x09, 0x0d, 0x0f, 0x08, 0x05, 0x00, 0x01, 0x0e, 0x0a, 0x06,
|
|
162
|
+
0x08, 0x03, 0x0d, 0x0a, 0x0e, 0x0f, 0x05, 0x01, 0x04, 0x07, 0x0b, 0x0c, 0x02, 0x00, 0x06, 0x09,
|
|
163
|
+
0x04, 0x0c, 0x09, 0x0b, 0x0e, 0x0a, 0x07, 0x06, 0x03, 0x05, 0x00, 0x0f, 0x01, 0x02, 0x08, 0x0d,
|
|
164
|
+
0x05, 0x08, 0x0e, 0x07, 0x03, 0x00, 0x01, 0x0d, 0x0a, 0x06, 0x09, 0x02, 0x0f, 0x0b, 0x0c, 0x04,
|
|
165
|
+
0x0a, 0x03, 0x05, 0x09, 0x00, 0x0d, 0x07, 0x08, 0x0c, 0x04, 0x01, 0x06, 0x0b, 0x0f, 0x02, 0x0e,
|
|
166
|
+
]);
|
|
167
|
+
export const ID_GOST_28147_89_TEST_PARAM_SET = new Uint8Array([
|
|
168
|
+
4, 2, 15, 5, 9, 1, 0, 8, 14, 3, 11, 12, 13, 7, 10, 6,
|
|
169
|
+
12, 9, 15, 14, 8, 1, 3, 10, 2, 7, 4, 13, 6, 0, 11, 5,
|
|
170
|
+
13, 8, 14, 12, 7, 3, 9, 10, 1, 5, 2, 4, 6, 15, 0, 11,
|
|
171
|
+
14, 9, 11, 2, 5, 15, 7, 1, 0, 13, 12, 6, 10, 4, 3, 8,
|
|
172
|
+
3, 14, 5, 9, 6, 8, 0, 13, 10, 11, 7, 12, 2, 1, 15, 4,
|
|
173
|
+
8, 15, 6, 11, 1, 9, 12, 5, 13, 3, 7, 10, 0, 14, 2, 4,
|
|
174
|
+
9, 11, 12, 0, 3, 6, 7, 5, 4, 8, 14, 15, 1, 10, 2, 13,
|
|
175
|
+
12, 6, 5, 2, 11, 0, 9, 13, 3, 14, 7, 10, 15, 4, 1, 8,
|
|
176
|
+
]);
|
|
177
|
+
export const ID_GOSTR_3411_94_TEST_PARAM_SET = new Uint8Array([
|
|
178
|
+
4, 10, 9, 2, 13, 8, 0, 14, 6, 11, 1, 12, 7, 15, 5, 3,
|
|
179
|
+
14, 11, 4, 12, 6, 13, 15, 10, 2, 3, 8, 1, 0, 7, 5, 9,
|
|
180
|
+
5, 8, 1, 13, 10, 3, 4, 2, 14, 15, 12, 7, 6, 0, 9, 11,
|
|
181
|
+
7, 13, 10, 1, 0, 8, 9, 15, 14, 4, 6, 12, 11, 2, 5, 3,
|
|
182
|
+
6, 12, 7, 1, 5, 15, 13, 8, 4, 10, 9, 14, 0, 3, 11, 2,
|
|
183
|
+
4, 11, 10, 0, 7, 2, 1, 13, 3, 6, 8, 5, 9, 12, 15, 14,
|
|
184
|
+
13, 11, 4, 1, 3, 15, 5, 9, 0, 10, 14, 7, 6, 8, 2, 12,
|
|
185
|
+
1, 15, 13, 0, 5, 7, 10, 4, 9, 2, 3, 14, 6, 11, 8, 12,
|
|
186
|
+
]);
|
|
187
|
+
export const ID_GOSTR_3411_94_CRYPTOPRO_PARAM_SET = new Uint8Array([
|
|
188
|
+
10, 4, 5, 6, 8, 1, 3, 7, 13, 12, 14, 0, 9, 2, 11, 15,
|
|
189
|
+
5, 15, 4, 0, 2, 13, 11, 9, 1, 7, 6, 3, 12, 14, 10, 8,
|
|
190
|
+
7, 15, 12, 14, 9, 4, 1, 0, 3, 11, 5, 2, 6, 10, 8, 13,
|
|
191
|
+
4, 10, 7, 12, 0, 15, 2, 8, 14, 1, 6, 5, 13, 11, 9, 3,
|
|
192
|
+
7, 6, 4, 11, 9, 12, 2, 10, 1, 8, 0, 14, 15, 13, 3, 5,
|
|
193
|
+
7, 6, 2, 4, 13, 9, 15, 0, 10, 1, 5, 11, 8, 14, 12, 3,
|
|
194
|
+
13, 14, 4, 1, 7, 0, 5, 10, 3, 12, 8, 15, 6, 2, 9, 11,
|
|
195
|
+
1, 3, 10, 9, 5, 11, 4, 15, 8, 6, 7, 14, 13, 0, 2, 12,
|
|
196
|
+
]);
|
|
197
|
+
export const EAC_PARAM_SET = new Uint8Array([
|
|
198
|
+
11, 4, 8, 10, 9, 7, 0, 3, 1, 6, 2, 15, 14, 5, 12, 13,
|
|
199
|
+
1, 7, 14, 9, 11, 3, 15, 12, 0, 5, 4, 6, 13, 10, 8, 2,
|
|
200
|
+
7, 3, 1, 9, 2, 4, 13, 15, 8, 10, 12, 6, 5, 0, 11, 14,
|
|
201
|
+
10, 5, 15, 7, 14, 11, 3, 9, 2, 8, 1, 12, 0, 4, 6, 13,
|
|
202
|
+
0, 14, 6, 11, 9, 3, 8, 4, 12, 15, 10, 5, 13, 7, 1, 2,
|
|
203
|
+
9, 2, 11, 12, 0, 4, 5, 6, 3, 15, 13, 8, 1, 7, 14, 10,
|
|
204
|
+
4, 0, 14, 1, 5, 11, 8, 3, 12, 2, 9, 7, 6, 10, 13, 15,
|
|
205
|
+
7, 14, 12, 13, 9, 4, 8, 15, 10, 2, 6, 0, 3, 11, 5, 1,
|
|
206
|
+
]);
|
|
207
207
|
/** Implemented S-Boxes */
|
|
208
208
|
export const magmaSboxes = {
|
|
209
209
|
ID_TC26_GOST_28147_PARAM_Z,
|
package/magma/index.d.ts
CHANGED
|
@@ -13,8 +13,7 @@ export declare class Magma implements Cipher {
|
|
|
13
13
|
* @param sbox S-Box
|
|
14
14
|
* @param isLegacy Use GOST 28147-89 instead of GOST R 34.12-2015?
|
|
15
15
|
*/
|
|
16
|
-
constructor(key: TArg<Uint8Array>, sbox?: TArg<Uint8Array
|
|
17
|
-
private regenerateRoundKeys;
|
|
16
|
+
constructor(key: TArg<Uint8Array>, sbox?: TArg<Uint8Array>, isLegacy?: boolean);
|
|
18
17
|
proceedBlock(block: TArg<Uint8Array>, sequence: number[]): TRet<Uint8Array>;
|
|
19
18
|
encrypt(plaintext: TArg<Uint8Array>): TRet<Uint8Array>;
|
|
20
19
|
decrypt(ciphertext: TArg<Uint8Array>): TRet<Uint8Array>;
|
package/magma/index.js
CHANGED
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
import { bytesToNumberBE, concatBytes, copyBytes, numberToBytesBE } from "@noble/curves/utils.js";
|
|
2
2
|
import { ID_TC26_GOST_28147_PARAM_Z, magmaKeySequences } from "./const.js";
|
|
3
3
|
const BLOCKSIZE = 8, KEYSIZE = 32;
|
|
4
|
-
const T = (value, sbox) => ((sbox[
|
|
5
|
-
(sbox[
|
|
6
|
-
(sbox[
|
|
7
|
-
(sbox[
|
|
8
|
-
(sbox[
|
|
9
|
-
(sbox[
|
|
10
|
-
(sbox[
|
|
11
|
-
(sbox[
|
|
4
|
+
const T = (value, sbox) => ((sbox[((value >> 0) & 0x0f)] << 0) |
|
|
5
|
+
(sbox[16 + ((value >> 4) & 0x0f)] << 4) |
|
|
6
|
+
(sbox[32 + ((value >> 8) & 0x0f)] << 8) |
|
|
7
|
+
(sbox[48 + ((value >> 12) & 0x0f)] << 12) |
|
|
8
|
+
(sbox[64 + ((value >> 16) & 0x0f)] << 16) |
|
|
9
|
+
(sbox[80 + ((value >> 20) & 0x0f)] << 20) |
|
|
10
|
+
(sbox[96 + ((value >> 24) & 0x0f)] << 24) |
|
|
11
|
+
(sbox[112 + ((value >> 28) & 0x0f)] << 28)) >>> 0;
|
|
12
12
|
const G = (a, k, sbox) => {
|
|
13
13
|
const substituted = T((a + k) >>> 0, sbox);
|
|
14
14
|
return ((substituted << 11) | (substituted >>> 21)) >>> 0;
|
|
15
15
|
};
|
|
16
|
+
const extendKey = (key, sequence) => {
|
|
17
|
+
const view = new DataView(key.buffer, key.byteOffset, key.byteLength);
|
|
18
|
+
const chunks = new Uint32Array(BLOCKSIZE);
|
|
19
|
+
for (let i = 0; i < BLOCKSIZE; i++)
|
|
20
|
+
chunks[i] = view.getUint32(i * 4);
|
|
21
|
+
return new Uint32Array(sequence.map(i => chunks[i]));
|
|
22
|
+
};
|
|
16
23
|
/** Magma (GOST R 34.12-2015 and GOST 28147-89) cipher */
|
|
17
24
|
export class Magma {
|
|
18
25
|
sbox;
|
|
@@ -33,19 +40,10 @@ export class Magma {
|
|
|
33
40
|
throw new Error("Invalid key length");
|
|
34
41
|
this.key = isLegacy ? Magma.reverseKey(key) : key;
|
|
35
42
|
}
|
|
36
|
-
regenerateRoundKeys(sequence) {
|
|
37
|
-
const keyChunks = [];
|
|
38
|
-
for (let j = 0; j < 8; j++)
|
|
39
|
-
keyChunks.push(Number(bytesToNumberBE(this.key.subarray(j * 4, j * 4 + 4))));
|
|
40
|
-
const roundKeys = new Array(sequence.length);
|
|
41
|
-
for (let i = 0; i < sequence.length; i++)
|
|
42
|
-
roundKeys[i] = keyChunks[sequence[i]];
|
|
43
|
-
return roundKeys;
|
|
44
|
-
}
|
|
45
43
|
proceedBlock(block, sequence) {
|
|
46
44
|
if (block.length !== this.blockSize)
|
|
47
45
|
throw new Error("Invalid block size");
|
|
48
|
-
const roundKeys = this.
|
|
46
|
+
const roundKeys = extendKey(this.key, sequence);
|
|
49
47
|
let a0 = Number(bytesToNumberBE(block.subarray(0, 4)));
|
|
50
48
|
let a1 = Number(bytesToNumberBE(block.subarray(4, 8)));
|
|
51
49
|
for (let i = 0; i < roundKeys.length; i++) {
|
package/modes/_keytransform.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type TArg, type TRet } from "@noble/curves/utils.js";
|
|
2
2
|
import type { Cipher } from "../types.js";
|
|
3
|
-
export declare const cp_kek_diversify: (kek: TArg<Uint8Array>, ukm: TArg<Uint8Array>, sbox?: TArg<Uint8Array>
|
|
3
|
+
export declare const cp_kek_diversify: (kek: TArg<Uint8Array>, ukm: TArg<Uint8Array>, sbox?: TArg<Uint8Array>) => TRet<Uint8Array>;
|
|
4
4
|
export declare const acpkm: (encrypter: (msg: TArg<Uint8Array>) => TRet<Uint8Array>, bs: number) => TRet<Uint8Array>;
|
|
5
5
|
export declare const acpkm_master: (cipher: Cipher, length: number) => TRet<Uint8Array>;
|
package/modes/mac.js
CHANGED
|
@@ -5,6 +5,15 @@ import { magmaKeySequences, Magma } from "../magma/index.js";
|
|
|
5
5
|
import { acpkm_master } from "./_keytransform.js";
|
|
6
6
|
const Rb64 = 0b11011;
|
|
7
7
|
const Rb128 = 0b10000111;
|
|
8
|
+
const shift1 = (src, dst) => {
|
|
9
|
+
let b = 0;
|
|
10
|
+
for (let i = src.length - 1; i >= 0; i--) {
|
|
11
|
+
const bb = src[i] >> 7;
|
|
12
|
+
dst[i] = src[i] << 1 | b;
|
|
13
|
+
b = bb;
|
|
14
|
+
}
|
|
15
|
+
return b;
|
|
16
|
+
};
|
|
8
17
|
/**
|
|
9
18
|
* **EN:** Message Authentication Code (MAC) mode
|
|
10
19
|
*
|
|
@@ -12,36 +21,36 @@ const Rb128 = 0b10000111;
|
|
|
12
21
|
*/
|
|
13
22
|
export const mac = (cipher) => {
|
|
14
23
|
const encrypter = cipher.encrypt.bind(cipher);
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const Rb = cipher.blockSize === 16 ? Rb128 : Rb64;
|
|
18
|
-
const l = encrypter(new Uint8Array(cipher.blockSize));
|
|
19
|
-
let k1;
|
|
20
|
-
if ((l[0] & 0x80) !== 0)
|
|
21
|
-
k1 = macShift(l, Rb);
|
|
22
|
-
else
|
|
23
|
-
k1 = macShift(l);
|
|
24
|
-
let k2;
|
|
25
|
-
if ((k1[0] & 0x80) !== 0)
|
|
26
|
-
k2 = macShift(k1, Rb);
|
|
27
|
-
else
|
|
28
|
-
k2 = macShift(k1);
|
|
29
|
-
return [k1, k2];
|
|
30
|
-
};
|
|
24
|
+
const Rb = cipher.blockSize === 16 ? Rb128 : Rb64;
|
|
25
|
+
const L = encrypter(new Uint8Array(cipher.blockSize));
|
|
31
26
|
return {
|
|
32
27
|
compute: (msg) => {
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
if (
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
28
|
+
const k1 = new Uint8Array(cipher.blockSize);
|
|
29
|
+
const msb = shift1(L, k1);
|
|
30
|
+
if (msb)
|
|
31
|
+
k1[cipher.blockSize - 1] ^= Rb;
|
|
32
|
+
const k2 = new Uint8Array(cipher.blockSize);
|
|
33
|
+
const msb2 = shift1(k1, k2);
|
|
34
|
+
if (msb2)
|
|
35
|
+
k2[cipher.blockSize - 1] ^= Rb;
|
|
36
|
+
const n = Math.ceil(msg.length / cipher.blockSize) || 1;
|
|
37
|
+
const lastBlockComplete = msg.length > 0 && msg.length % cipher.blockSize === 0;
|
|
38
|
+
let buf = new Uint8Array(cipher.blockSize);
|
|
39
|
+
for (let i = 0; i < n - 1; i++) {
|
|
40
|
+
const m = msg.subarray(i * cipher.blockSize, (i + 1) * cipher.blockSize);
|
|
41
|
+
buf = encrypter(xorBytes(buf, m));
|
|
42
|
+
}
|
|
43
|
+
let lastBlock;
|
|
44
|
+
if (lastBlockComplete && msg.length > 0)
|
|
45
|
+
lastBlock = xorBytes(msg.subarray((n - 1) * cipher.blockSize, n * cipher.blockSize), k1);
|
|
46
|
+
else {
|
|
47
|
+
const padded = new Uint8Array(cipher.blockSize);
|
|
48
|
+
const remaining = msg.length - (n - 1) * cipher.blockSize;
|
|
49
|
+
padded.set(msg.subarray((n - 1) * cipher.blockSize));
|
|
50
|
+
padded[remaining] = 0x80;
|
|
51
|
+
lastBlock = xorBytes(padded, k2);
|
|
52
|
+
}
|
|
53
|
+
return encrypter(xorBytes(buf, lastBlock));
|
|
45
54
|
}
|
|
46
55
|
};
|
|
47
56
|
};
|
package/modes/mgm.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { concatBytes } from "@noble/hashes/utils.js";
|
|
2
2
|
import { bytesToNumberBE, equalBytes, numberToBytesBE } from "@noble/curves/utils.js";
|
|
3
3
|
import { pad1, xorBytes } from "../utils.js";
|
|
4
|
+
import { gf64Multiply, gf128Multiply } from "../gf/index.js";
|
|
4
5
|
/**
|
|
5
6
|
* **EN:** Multilinear Galois (MGM) mode (AEAD)
|
|
6
7
|
*
|
|
@@ -15,29 +16,13 @@ export const mgm = (cipher, nonce, tagSize = cipher.blockSize) => {
|
|
|
15
16
|
throw new Error("Invalid tagSize");
|
|
16
17
|
const encrypter = cipher.encrypt.bind(cipher);
|
|
17
18
|
const maxSize = (1n << BigInt(cipher.blockSize * 4)) - 1n;
|
|
18
|
-
const r = (cipher.blockSize == 8 ? 0x1B : 0x87);
|
|
19
19
|
const validateSizes = (plaintext, additional) => {
|
|
20
20
|
if (plaintext.length == 0 && additional.length == 0)
|
|
21
21
|
throw new Error("At least one of plaintext or additional_data required");
|
|
22
22
|
if ((plaintext.length + additional.length) > maxSize)
|
|
23
23
|
throw new Error("plaintext+additional_data are too big");
|
|
24
24
|
};
|
|
25
|
-
const mul = (
|
|
26
|
-
let x = bytesToNumberBE(a);
|
|
27
|
-
let y = bytesToNumberBE(b);
|
|
28
|
-
let z = 0n;
|
|
29
|
-
const max_bit = 1n << (BigInt(cipher.blockSize) * 8n - 1n);
|
|
30
|
-
while (y > 0n) {
|
|
31
|
-
if ((y & 1n) == 1n)
|
|
32
|
-
z ^= x;
|
|
33
|
-
if ((x & max_bit) > 0n)
|
|
34
|
-
x = ((x ^ max_bit) << 1n) ^ BigInt(r);
|
|
35
|
-
else
|
|
36
|
-
x <<= 1n;
|
|
37
|
-
y >>= 1n;
|
|
38
|
-
}
|
|
39
|
-
return numberToBytesBE(z, cipher.blockSize);
|
|
40
|
-
};
|
|
25
|
+
const mul = (cipher.blockSize == 8 ? gf64Multiply : gf128Multiply);
|
|
41
26
|
const crypt = (icn, data) => {
|
|
42
27
|
icn[0] &= 0x7F;
|
|
43
28
|
let enc = encrypter(icn);
|
package/modes/wrap.d.ts
CHANGED
|
@@ -11,4 +11,4 @@ export declare const kexp15: (cipherEnc: Cipher, cipherMac: Cipher, iv: TArg<Uin
|
|
|
11
11
|
*
|
|
12
12
|
* **RU:** Режим обёртки ключей шифрования согласно ГОСТ 28147-89
|
|
13
13
|
*/
|
|
14
|
-
export declare const kwp: (kek: TArg<Uint8Array>, isCryptoPro?: boolean, sbox?: TArg<Uint8Array>
|
|
14
|
+
export declare const kwp: (kek: TArg<Uint8Array>, isCryptoPro?: boolean, sbox?: TArg<Uint8Array>) => WrapModeMagma;
|
package/modes/wrap.js
CHANGED
|
@@ -2,7 +2,7 @@ import { concatBytes } from "@noble/hashes/utils.js";
|
|
|
2
2
|
import { mac as _mac, mac_legacy } from "./mac.js";
|
|
3
3
|
import { ctr } from "./ctr.js";
|
|
4
4
|
import { equalBytes } from "@noble/curves/utils.js";
|
|
5
|
-
import { ID_GOST_28147_89_CRYPTO_PRO_A_PARAM_SET } from "../magma/const";
|
|
5
|
+
import { ID_GOST_28147_89_CRYPTO_PRO_A_PARAM_SET } from "../magma/const.js";
|
|
6
6
|
import { Magma } from "../magma/index.js";
|
|
7
7
|
import { ecb } from "./ecb.js";
|
|
8
8
|
import { cp_kek_diversify } from "./_keytransform.js";
|
package/package.json
CHANGED
package/streebog/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { concatBytes, createHasher } from "@noble/hashes/utils.js";
|
|
1
|
+
import { concatBytes, copyBytes, createHasher } from "@noble/hashes/utils.js";
|
|
2
2
|
import { A, C, TAU } from "./const.js";
|
|
3
3
|
import { PI } from "../kuznyechik/const.js";
|
|
4
4
|
import { pad1, xorBytes } from "../utils.js";
|
|
@@ -122,7 +122,7 @@ class Streebog {
|
|
|
122
122
|
return buffer;
|
|
123
123
|
}
|
|
124
124
|
digestInto(buf) {
|
|
125
|
-
const message = this.buffer
|
|
125
|
+
const message = copyBytes(this.buffer).reverse();
|
|
126
126
|
let n = new Uint8Array(this.blockLen);
|
|
127
127
|
let sigma = new Uint8Array(this.blockLen);
|
|
128
128
|
let hash = new Uint8Array(this.blockLen).fill(this.is512 ? 0 : 1);
|
|
@@ -144,7 +144,7 @@ class Streebog {
|
|
|
144
144
|
}
|
|
145
145
|
hash = G(_0, G(_0, G(n, hash, paddedMsg), add512(n, numberToBytesBE(msg.length * 8, 4))), add512(sigma, paddedMsg));
|
|
146
146
|
if (this.is512)
|
|
147
|
-
buf.set(hash
|
|
147
|
+
buf.set(copyBytes(hash).reverse());
|
|
148
148
|
else
|
|
149
149
|
buf.set(hash.slice(0, 32).reverse());
|
|
150
150
|
this.destroy();
|