@li0ard/gost 0.0.1 → 0.1.2
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/gost3410/const.d.ts +47 -0
- package/gost3410/const.js +126 -0
- package/gost3410/conversion.d.ts +19 -0
- package/gost3410/conversion.js +35 -0
- package/gost3410/index.d.ts +29 -0
- package/gost3410/index.js +84 -0
- package/gost3410/vko.d.ts +38 -0
- package/gost3410/vko.js +47 -0
- package/gost341194/index.d.ts +23 -0
- package/gost341194/index.js +193 -0
- package/hmac.d.ts +15 -0
- package/hmac.js +22 -0
- package/index.d.ts +9 -0
- package/index.js +9 -0
- package/kdf.d.ts +7 -0
- package/kdf.js +59 -0
- package/kuznyechik/const.d.ts +4 -0
- package/kuznyechik/const.js +78 -0
- package/kuznyechik/index.d.ts +12 -0
- package/kuznyechik/index.js +207 -0
- package/magma/const.d.ts +62 -0
- package/magma/const.js +244 -0
- package/magma/index.d.ts +24 -0
- package/magma/index.js +86 -0
- package/modes/_keytransform.d.ts +5 -0
- package/modes/_keytransform.js +35 -0
- package/modes/cbc.d.ts +8 -0
- package/modes/cbc.js +42 -0
- package/modes/cfb.d.ts +8 -0
- package/modes/cfb.js +37 -0
- package/modes/ctr.d.ts +15 -0
- package/modes/ctr.js +62 -0
- package/modes/ecb.d.ts +7 -0
- package/modes/ecb.js +21 -0
- package/modes/index.d.ts +8 -0
- package/modes/index.js +8 -0
- package/modes/mac.d.ts +21 -0
- package/modes/mac.js +119 -0
- package/modes/mgm.d.ts +8 -0
- package/modes/mgm.js +90 -0
- package/modes/ofb.d.ts +8 -0
- package/modes/ofb.js +25 -0
- package/modes/wrap.d.ts +14 -0
- package/modes/wrap.js +57 -0
- package/package.json +48 -7
- package/streebog/const.d.ts +4 -0
- package/streebog/const.js +102 -0
- package/streebog/index.d.ts +66 -0
- package/streebog/index.js +295 -0
- package/types.d.ts +50 -0
- package/types.js +1 -0
- package/utils.d.ts +7 -0
- package/utils.js +47 -0
- package/README.md +0 -45
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** Parameters for GOST curves */
|
|
2
|
+
export interface GostCurveParameters {
|
|
3
|
+
/** Prime field (`Fp`) */
|
|
4
|
+
p: bigint;
|
|
5
|
+
/** Curve order (`Fn`) */
|
|
6
|
+
n: bigint;
|
|
7
|
+
/** Param `a` */
|
|
8
|
+
a: bigint;
|
|
9
|
+
/** Param `b` */
|
|
10
|
+
b: bigint;
|
|
11
|
+
/** Base point `X` coordinate */
|
|
12
|
+
Gx: bigint;
|
|
13
|
+
/** Base point `Y` coordinate */
|
|
14
|
+
Gy: bigint;
|
|
15
|
+
/** Cofactor */
|
|
16
|
+
h: bigint;
|
|
17
|
+
/** Curve point length */
|
|
18
|
+
length: number;
|
|
19
|
+
/** Param `e` (`a`) for representation as Twisted Edwards */
|
|
20
|
+
e?: bigint;
|
|
21
|
+
/** Param `d` for representation as Twisted Edwards */
|
|
22
|
+
d?: bigint;
|
|
23
|
+
/** Precomputed parameters for point conversion */
|
|
24
|
+
st?: bigint[];
|
|
25
|
+
/** Curve OIDs */
|
|
26
|
+
oids?: string[];
|
|
27
|
+
}
|
|
28
|
+
/** GOST R 34.10-2001 CryptoCom param set */
|
|
29
|
+
export declare const ID_GOSTR3410_2001_PARAM_SET_CC: Readonly<GostCurveParameters>;
|
|
30
|
+
/** GOST R 34.10-2001 test param set */
|
|
31
|
+
export declare const ID_GOSTR3410_2001_TEST_PARAM_SET: Readonly<GostCurveParameters>;
|
|
32
|
+
/** GOST R 34.10-2012 256 bit `A` param set */
|
|
33
|
+
export declare const ID_GOSTR3410_2012_256_PARAM_SET_A: Readonly<GostCurveParameters>;
|
|
34
|
+
/** GOST R 34.10-2012 256 bit `B` param set (aka CryptoPro `A` (`XchA`) param set) */
|
|
35
|
+
export declare const ID_GOSTR3410_2012_256_PARAM_SET_B: Readonly<GostCurveParameters>;
|
|
36
|
+
/** GOST R 34.10-2012 256 bit `C` param set (aka CryptoPro `B` param set) */
|
|
37
|
+
export declare const ID_GOSTR3410_2012_256_PARAM_SET_C: Readonly<GostCurveParameters>;
|
|
38
|
+
/** GOST R 34.10-2012 256 bit `D` param set (aka CryptoPro `C` (`XchB`) param set) */
|
|
39
|
+
export declare const ID_GOSTR3410_2012_256_PARAM_SET_D: Readonly<GostCurveParameters>;
|
|
40
|
+
/** GOST R 34.10-2012 512 bit test param set */
|
|
41
|
+
export declare const ID_GOSTR3410_2012_512_TEST_PARAM_SET: Readonly<GostCurveParameters>;
|
|
42
|
+
/** GOST R 34.10-2012 512 bit `A` param set */
|
|
43
|
+
export declare const ID_GOSTR3410_2012_512_PARAM_SET_A: Readonly<GostCurveParameters>;
|
|
44
|
+
/** GOST R 34.10-2012 512 bit `B` param set */
|
|
45
|
+
export declare const ID_GOSTR3410_2012_512_PARAM_SET_B: Readonly<GostCurveParameters>;
|
|
46
|
+
/** GOST R 34.10-2012 512 bit `C` param set */
|
|
47
|
+
export declare const ID_GOSTR3410_2012_512_PARAM_SET_C: Readonly<GostCurveParameters>;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/** GOST R 34.10-2001 CryptoCom param set */
|
|
2
|
+
export const ID_GOSTR3410_2001_PARAM_SET_CC = ({
|
|
3
|
+
p: 0xc0000000000000000000000000000000000000000000000000000000000003c7n,
|
|
4
|
+
n: 0x5fffffffffffffffffffffffffffffff606117a2f4bde428b7458a54b6e87b85n,
|
|
5
|
+
a: 0xc0000000000000000000000000000000000000000000000000000000000003c4n,
|
|
6
|
+
b: 0x2d06b4265ebc749ff7d0f1f1f88232e81632e9088fd44b7787d5e407e955080cn,
|
|
7
|
+
Gx: 2n,
|
|
8
|
+
Gy: 0xa20e034bf8813ef5c18d01105e726a17eb248b264ae9706f440bedc8ccb6b22cn,
|
|
9
|
+
h: 1n,
|
|
10
|
+
length: 32,
|
|
11
|
+
oids: ["1.2.643.2.9.1.8.1"]
|
|
12
|
+
});
|
|
13
|
+
/** GOST R 34.10-2001 test param set */
|
|
14
|
+
export const ID_GOSTR3410_2001_TEST_PARAM_SET = ({
|
|
15
|
+
p: 0x8000000000000000000000000000000000000000000000000000000000000431n,
|
|
16
|
+
n: 0x8000000000000000000000000000000150fe8a1892976154c59cfc193accf5b3n,
|
|
17
|
+
a: 7n,
|
|
18
|
+
b: 0x5fbff498aa938ce739b8e022fbafef40563f6e6a3472fc2a514c0ce9dae23b7en,
|
|
19
|
+
Gx: 2n,
|
|
20
|
+
Gy: 0x08e2a8a0e65147d4bd6316030e16d19c85c97f0a9ca267122b96abbcea7e8fc8n,
|
|
21
|
+
h: 1n,
|
|
22
|
+
length: 32,
|
|
23
|
+
oids: ["1.2.643.2.2.35.0"]
|
|
24
|
+
});
|
|
25
|
+
/** GOST R 34.10-2012 256 bit `A` param set */
|
|
26
|
+
export const ID_GOSTR3410_2012_256_PARAM_SET_A = ({
|
|
27
|
+
p: 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd97n,
|
|
28
|
+
n: 0x400000000000000000000000000000000fd8cddfc87b6635c115af556c360c67n,
|
|
29
|
+
a: 0xc2173f1513981673af4892c23035a27ce25e2013bf95aa33b22c656f277e7335n,
|
|
30
|
+
b: 0x295f9bae7428ed9ccc20e7c359a9d41a22fccd9108e17bf7ba9337a6f8ae9513n,
|
|
31
|
+
Gx: 0x91e38443a5e82c0d880923425712b2bb658b9196932e02c78b2582fe742daa28n,
|
|
32
|
+
Gy: 0x32879423ab1a0375895786c4bb46e9565fde0b5344766740af268adb32322e5cn,
|
|
33
|
+
h: 4n,
|
|
34
|
+
e: 1n,
|
|
35
|
+
d: 0x0605f6b7c183fa81578bc39cfad518132b9df62897009af7e522c32d6dc7bffbn,
|
|
36
|
+
length: 32,
|
|
37
|
+
st: [0x7e7e82520f9f015faa1d0f18c14ab9fb35188275da3fd94206b74f34a48e0ecdn, 0x0100fe73f595ff158e974b44d478d9588744fe5c192ac47ea63075dce7a14aaan],
|
|
38
|
+
oids: ["1.2.643.7.1.2.1.1.1"]
|
|
39
|
+
});
|
|
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 = ({
|
|
42
|
+
p: 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd97n,
|
|
43
|
+
n: 0xffffffffffffffffffffffffffffffff6c611070995ad10045841b09b761b893n,
|
|
44
|
+
a: 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd94n,
|
|
45
|
+
b: 0xa6n,
|
|
46
|
+
Gx: 1n,
|
|
47
|
+
Gy: 0x8d91e471e0989cda27df505a453f2b7635294f2ddf23e3b122acc99c9e9f1e14n,
|
|
48
|
+
h: 1n,
|
|
49
|
+
length: 32,
|
|
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
|
+
});
|
|
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 = ({
|
|
54
|
+
p: 0x8000000000000000000000000000000000000000000000000000000000000c99n,
|
|
55
|
+
n: 0x800000000000000000000000000000015f700cfff1a624e5e497161bcc8a198fn,
|
|
56
|
+
a: 0x8000000000000000000000000000000000000000000000000000000000000c96n,
|
|
57
|
+
b: 0x3e1af419a269a5f866a7d3c25c3df80ae979259373ff2b182f49d4ce7e1bbc8bn,
|
|
58
|
+
Gx: 1n,
|
|
59
|
+
Gy: 0x3fa8124359f96680b83d1c3eb2c070e5c545c9858d03ecfb744bf8d717717efcn,
|
|
60
|
+
h: 1n,
|
|
61
|
+
length: 32,
|
|
62
|
+
oids: ["1.2.643.7.1.2.1.1.3", "1.2.643.2.2.35.2"]
|
|
63
|
+
});
|
|
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 = ({
|
|
66
|
+
p: 0x9b9f605f5a858107ab1ec85e6b41c8aacf846e86789051d37998f7b9022d759bn,
|
|
67
|
+
n: 0x9b9f605f5a858107ab1ec85e6b41c8aa582ca3511eddfb74f02f3a6598980bb9n,
|
|
68
|
+
a: 0x9b9f605f5a858107ab1ec85e6b41c8aacf846e86789051d37998f7b9022d7598n,
|
|
69
|
+
b: 0x0805an,
|
|
70
|
+
Gx: 0n,
|
|
71
|
+
Gy: 0x41ece55743711a8c3cbf3783cd08c0ee4d4dc440d4641a8f366e550dfdb3bb67n,
|
|
72
|
+
h: 1n,
|
|
73
|
+
length: 32,
|
|
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
|
+
});
|
|
76
|
+
/** GOST R 34.10-2012 512 bit test param set */
|
|
77
|
+
export const ID_GOSTR3410_2012_512_TEST_PARAM_SET = ({
|
|
78
|
+
p: 0x4531acd1fe0023c7550d267b6b2fee80922b14b2ffb90f04d4eb7c09b5d2d15df1d852741af4704a0458047e80e4546d35b8336fac224dd81664bbf528be6373n,
|
|
79
|
+
n: 0x4531acd1fe0023c7550d267b6b2fee80922b14b2ffb90f04d4eb7c09b5d2d15da82f2d7ecb1dbac719905c5eecc423f1d86e25edbe23c595d644aaf187e6e6dfn,
|
|
80
|
+
a: 7n,
|
|
81
|
+
b: 0x1cff0806a31116da29d8cfa54e57eb748bc5f377e49400fdd788b649eca1ac4361834013b2ad7322480a89ca58e0cf74bc9e540c2add6897fad0a3084f302adcn,
|
|
82
|
+
Gx: 0x24d19cc64572ee30f396bf6ebbfd7a6c5213b3b3d7057cc825f91093a68cd762fd60611262cd838dc6b60aa7eee804e28bc849977fac33b4b530f1b120248a9an,
|
|
83
|
+
Gy: 0x2bb312a43bd2ce6e0d020613c857acddcfbf061e91e5f2c3f32447c259f39b2c83ab156d77f1496bf7eb3351e1ee4e43dc1a18b91b24640b6dbb92cb1add371en,
|
|
84
|
+
h: 1n,
|
|
85
|
+
length: 64,
|
|
86
|
+
oids: ["1.2.643.7.1.2.1.2.0"]
|
|
87
|
+
});
|
|
88
|
+
/** GOST R 34.10-2012 512 bit `A` param set */
|
|
89
|
+
export const ID_GOSTR3410_2012_512_PARAM_SET_A = ({
|
|
90
|
+
p: 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdc7n,
|
|
91
|
+
n: 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff27e69532f48d89116ff22b8d4e0560609b4b38abfad2b85dcacdb1411f10b275n,
|
|
92
|
+
a: 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdc4n,
|
|
93
|
+
b: 0xe8c2505dedfc86ddc1bd0b2b6667f1da34b82574761cb0e879bd081cfd0b6265ee3cb090f30d27614cb4574010da90dd862ef9d4ebee4761503190785a71c760n,
|
|
94
|
+
Gx: 3n,
|
|
95
|
+
Gy: 0x7503cfe87a836ae3a61b8816e25450e6ce5e1c93acf1abc1778064fdcbefa921df1626be4fd036e93d75e6a50e3a41e98028fe5fc235f5b889a589cb5215f2a4n,
|
|
96
|
+
h: 1n,
|
|
97
|
+
length: 64,
|
|
98
|
+
oids: ["1.2.643.7.1.2.1.2.1"]
|
|
99
|
+
});
|
|
100
|
+
/** GOST R 34.10-2012 512 bit `B` param set */
|
|
101
|
+
export const ID_GOSTR3410_2012_512_PARAM_SET_B = ({
|
|
102
|
+
p: 0x8000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006fn,
|
|
103
|
+
n: 0x800000000000000000000000000000000000000000000000000000000000000149a1ec142565a545acfdb77bd9d40cfa8b996712101bea0ec6346c54374f25bdn,
|
|
104
|
+
a: 0x8000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006cn,
|
|
105
|
+
b: 0x687d1b459dc841457e3e06cf6f5e2517b97c7d614af138bcbf85dc806c4b289f3e965d2db1416d217f8b276fad1ab69c50f78bee1fa3106efb8ccbc7c5140116n,
|
|
106
|
+
Gx: 2n,
|
|
107
|
+
Gy: 0x1a8f7eda389b094c2c071e3647a8940f3c123b697578c213be6dd9e6c8ec7335dcb228fd1edf4a39152cbcaaf8c0398828041055f94ceeec7e21340780fe41bdn,
|
|
108
|
+
h: 1n,
|
|
109
|
+
length: 64,
|
|
110
|
+
oids: ["1.2.643.7.1.2.1.2.2"]
|
|
111
|
+
});
|
|
112
|
+
/** GOST R 34.10-2012 512 bit `C` param set */
|
|
113
|
+
export const ID_GOSTR3410_2012_512_PARAM_SET_C = ({
|
|
114
|
+
p: 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdc7n,
|
|
115
|
+
n: 0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc98cdba46506ab004c33a9ff5147502cc8eda9e7a769a12694623cef47f023edn,
|
|
116
|
+
a: 0xdc9203e514a721875485a529d2c722fb187bc8980eb866644de41c68e143064546e861c0e2c9edd92ade71f46fcf50ff2ad97f951fda9f2a2eb6546f39689bd3n,
|
|
117
|
+
b: 0xb4c4ee28cebc6c2c8ac12952cf37f16ac7efb6a9f69f4b57ffda2e4f0de5ade038cbc2fff719d2c18de0284b8bfef3b52b8cc7a5f5bf0a3c8d2319a5312557e1n,
|
|
118
|
+
Gx: 0xe2e31edfc23de7bdebe241ce593ef5de2295b7a9cbaef021d385f7074cea043aa27272a7ae602bf2a7b9033db9ed3610c6fb85487eae97aac5bc7928c1950148n,
|
|
119
|
+
Gy: 0xf5ce40d95b5eb899abbccff5911cb8577939804d6527378b8c108c3d2090ff9be18e2d33e3021ed2ef32d85822423b6304f726aa854bae07d0396e9a9addc40fn,
|
|
120
|
+
h: 4n,
|
|
121
|
+
e: 1n,
|
|
122
|
+
d: 0x9e4f5d8c017d8d9f13a5cf3cdf5bfe4dab402d54198e31ebde28a0621050439ca6b39e0a515c06b304e2ce43e79e369e91a0cfc2bc2a22b4ca302dbb33ee7550n,
|
|
123
|
+
length: 64,
|
|
124
|
+
st: [0x186c289cffa09c983b168c30c829006c952ff4aaf99c73850875d7e77bebef18d653187d6ba8fe533ec74c6f061872585b97cc0f50f57752cd73f4913304621en, 0x9a628f975594ecefd89ba28a2539ffb79c8ab238aeed0851fa5c1abb02b80b44c6734501b83a011dd625cd0b5145091a6d9acd4b1f5c5b1e21b2b249ddfd1271n],
|
|
125
|
+
oids: ["1.2.643.7.1.2.1.2.3"]
|
|
126
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { AffinePoint } from "@noble/curves/abstract/curve.js";
|
|
2
|
+
import type { GostCurveParameters } from "./const.js";
|
|
3
|
+
/**
|
|
4
|
+
* Compute parameters (`s`, `t`) for conversion
|
|
5
|
+
* @param curve Curve to use
|
|
6
|
+
*/
|
|
7
|
+
export declare const computeST: (curve: GostCurveParameters) => bigint[];
|
|
8
|
+
/**
|
|
9
|
+
* Convert Twisted Edwards point (`u`, `v`) to Weierstrass (`x`, `y`)
|
|
10
|
+
* @param curve Curve to use
|
|
11
|
+
* @param point Twisted Edwards point
|
|
12
|
+
*/
|
|
13
|
+
export declare const uv2xy: (curve: GostCurveParameters, point: AffinePoint<bigint>) => AffinePoint<bigint>;
|
|
14
|
+
/**
|
|
15
|
+
* Convert Weierstrass point (`x`, `y`) to Twisted Edwards (`u`, `v`)
|
|
16
|
+
* @param curve Curve to use
|
|
17
|
+
* @param point Weierstrass point
|
|
18
|
+
*/
|
|
19
|
+
export declare const xy2uv: (curve: GostCurveParameters, point: AffinePoint<bigint>) => AffinePoint<bigint>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Field } from "@noble/curves/abstract/modular.js";
|
|
2
|
+
/**
|
|
3
|
+
* Compute parameters (`s`, `t`) for conversion
|
|
4
|
+
* @param curve Curve to use
|
|
5
|
+
*/
|
|
6
|
+
export const computeST = (curve) => {
|
|
7
|
+
if (!curve.e || !curve.d)
|
|
8
|
+
throw new Error("No Twisted Edwards parameters");
|
|
9
|
+
if (curve.st && curve.st.length != 0)
|
|
10
|
+
return curve.st;
|
|
11
|
+
const Fp = Field(curve.p);
|
|
12
|
+
return [Fp.div(Fp.sub(curve.e, curve.d), 4n), Fp.div(Fp.add(curve.e, curve.d), 6n)];
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Convert Twisted Edwards point (`u`, `v`) to Weierstrass (`x`, `y`)
|
|
16
|
+
* @param curve Curve to use
|
|
17
|
+
* @param point Twisted Edwards point
|
|
18
|
+
*/
|
|
19
|
+
export const uv2xy = (curve, point) => {
|
|
20
|
+
const Fp = Field(curve.p);
|
|
21
|
+
const [s, t] = computeST(curve);
|
|
22
|
+
const s1v = Fp.mul(s, Fp.add(1n, point.y)), onev = Fp.sub(1n, point.y);
|
|
23
|
+
return { x: Fp.add(t, Fp.div(s1v, onev)), y: Fp.div(s1v, Fp.mul(point.x, onev)) };
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Convert Weierstrass point (`x`, `y`) to Twisted Edwards (`u`, `v`)
|
|
27
|
+
* @param curve Curve to use
|
|
28
|
+
* @param point Weierstrass point
|
|
29
|
+
*/
|
|
30
|
+
export const xy2uv = (curve, point) => {
|
|
31
|
+
const Fp = Field(curve.p);
|
|
32
|
+
const [s, t] = computeST(curve);
|
|
33
|
+
const xt = Fp.sub(point.x, t);
|
|
34
|
+
return { x: Fp.div(xt, point.y), y: Fp.div(Fp.sub(xt, s), Fp.add(xt, s)) };
|
|
35
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type TArg, type TRet } from "@noble/curves/utils.js";
|
|
2
|
+
import { type GostCurveParameters } from "./const.js";
|
|
3
|
+
/**
|
|
4
|
+
* Generate public key from private.
|
|
5
|
+
* @param parameters Curve parameters
|
|
6
|
+
* @param prv Private key
|
|
7
|
+
* @returns {TRet<Uint8Array>} Uncompressed public key in ANSI X9.62 format
|
|
8
|
+
*/
|
|
9
|
+
export declare const getPublicKey: (parameters: GostCurveParameters, prv: TArg<Uint8Array>) => TRet<Uint8Array>;
|
|
10
|
+
/**
|
|
11
|
+
* Generate signature of provided digest
|
|
12
|
+
* @param parameters Curve parameters
|
|
13
|
+
* @param prv Private key
|
|
14
|
+
* @param digest Digest to sign
|
|
15
|
+
* @param rand Optional. Predefined random data for `r` and `k` generation
|
|
16
|
+
* @returns {TRet<Uint8Array>} Concated `r` and `s`
|
|
17
|
+
*/
|
|
18
|
+
export declare const sign: (parameters: GostCurveParameters, prv: TArg<Uint8Array>, digest: TArg<Uint8Array>, rand?: TArg<Uint8Array>) => TRet<Uint8Array>;
|
|
19
|
+
/**
|
|
20
|
+
* Verify signature of provided digest
|
|
21
|
+
* @param parameters Curve parameters
|
|
22
|
+
* @param pub Public key
|
|
23
|
+
* @param digest Digest to verify
|
|
24
|
+
* @param signature Signature (Concated `r` and `s`)
|
|
25
|
+
*/
|
|
26
|
+
export declare const verify: (parameters: GostCurveParameters, pub: TArg<Uint8Array>, digest: TArg<Uint8Array>, signature: TArg<Uint8Array>) => boolean;
|
|
27
|
+
export * from "./const.js";
|
|
28
|
+
export * from "./vko.js";
|
|
29
|
+
export * from "./conversion.js";
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { bytesToNumberBE, concatBytes, numberToBytesBE, randomBytes } from "@noble/curves/utils.js";
|
|
2
|
+
import {} from "./const.js";
|
|
3
|
+
import { mod } from "@noble/curves/abstract/modular.js";
|
|
4
|
+
import { weierstrass } from "@noble/curves/abstract/weierstrass.js";
|
|
5
|
+
/**
|
|
6
|
+
* Generate public key from private.
|
|
7
|
+
* @param parameters Curve parameters
|
|
8
|
+
* @param prv Private key
|
|
9
|
+
* @returns {TRet<Uint8Array>} Uncompressed public key in ANSI X9.62 format
|
|
10
|
+
*/
|
|
11
|
+
export const getPublicKey = (parameters, prv) => weierstrass(parameters).BASE.multiply(bytesToNumberBE(prv)).toBytes(false);
|
|
12
|
+
/**
|
|
13
|
+
* Generate signature of provided digest
|
|
14
|
+
* @param parameters Curve parameters
|
|
15
|
+
* @param prv Private key
|
|
16
|
+
* @param digest Digest to sign
|
|
17
|
+
* @param rand Optional. Predefined random data for `r` and `k` generation
|
|
18
|
+
* @returns {TRet<Uint8Array>} Concated `r` and `s`
|
|
19
|
+
*/
|
|
20
|
+
export const sign = (parameters, prv, digest, rand) => {
|
|
21
|
+
const size = parameters.length;
|
|
22
|
+
const curve = weierstrass(parameters);
|
|
23
|
+
const Fn = curve.Fn;
|
|
24
|
+
let e = Fn.fromBytes(digest);
|
|
25
|
+
if (e === 0n)
|
|
26
|
+
e = 1n;
|
|
27
|
+
const prvNum = Fn.fromBytes(prv);
|
|
28
|
+
while (true) {
|
|
29
|
+
rand ||= randomBytes(size);
|
|
30
|
+
const k = mod(bytesToNumberBE(rand), parameters.n);
|
|
31
|
+
if (k === 0n)
|
|
32
|
+
continue;
|
|
33
|
+
try {
|
|
34
|
+
let { x: r } = curve.BASE.multiply(k);
|
|
35
|
+
r = Fn.create(r);
|
|
36
|
+
if (r === 0n)
|
|
37
|
+
continue;
|
|
38
|
+
const s = Fn.add(Fn.mul(r, prvNum), Fn.mul(k, e));
|
|
39
|
+
if (s === 0n)
|
|
40
|
+
continue;
|
|
41
|
+
return concatBytes(numberToBytesBE(r, parameters.length), numberToBytesBE(s, parameters.length));
|
|
42
|
+
}
|
|
43
|
+
catch (e) {
|
|
44
|
+
if (e instanceof Error && e.message === "invalid scalar: out of range")
|
|
45
|
+
continue;
|
|
46
|
+
throw e;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Verify signature of provided digest
|
|
52
|
+
* @param parameters Curve parameters
|
|
53
|
+
* @param pub Public key
|
|
54
|
+
* @param digest Digest to verify
|
|
55
|
+
* @param signature Signature (Concated `r` and `s`)
|
|
56
|
+
*/
|
|
57
|
+
export const verify = (parameters, pub, digest, signature) => {
|
|
58
|
+
const size = parameters.length;
|
|
59
|
+
const curve = weierstrass(parameters);
|
|
60
|
+
const Fn = curve.Fn;
|
|
61
|
+
if (signature.length != size * 2)
|
|
62
|
+
throw new Error("Invalid signature");
|
|
63
|
+
const r = bytesToNumberBE(signature.slice(0, size));
|
|
64
|
+
const s = bytesToNumberBE(signature.slice(size));
|
|
65
|
+
if (r <= 0 || r >= parameters.n || s <= 0 || s >= parameters.n)
|
|
66
|
+
return false;
|
|
67
|
+
let e = Fn.fromBytes(digest);
|
|
68
|
+
if (e === 0n)
|
|
69
|
+
e = 1n;
|
|
70
|
+
const v = Fn.inv(e);
|
|
71
|
+
const z1 = Fn.mul(s, v), z2 = Fn.mul(r, v);
|
|
72
|
+
let P, Q;
|
|
73
|
+
try {
|
|
74
|
+
P = curve.BASE.multiply(z1);
|
|
75
|
+
Q = curve.fromBytes(pub).multiply(z2).negate();
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
return Fn.create(P.add(Q).x) === r;
|
|
81
|
+
};
|
|
82
|
+
export * from "./const.js";
|
|
83
|
+
export * from "./vko.js";
|
|
84
|
+
export * from "./conversion.js";
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { GostCurveParameters } from "./const.js";
|
|
2
|
+
import { type TArg, type TRet } from "@noble/curves/utils.js";
|
|
3
|
+
/**
|
|
4
|
+
* Key agreement function
|
|
5
|
+
* @param parameters Curve parameters
|
|
6
|
+
* @param prv Private key
|
|
7
|
+
* @param pub Public key
|
|
8
|
+
* @param ukm User keying material (aka salt)
|
|
9
|
+
* @returns {TRet<Uint8Array>} Shared key
|
|
10
|
+
*/
|
|
11
|
+
export declare const kek: (parameters: GostCurveParameters, prv: TArg<Uint8Array>, pub: TArg<Uint8Array>, ukm: TArg<Uint8Array>) => TRet<Uint8Array>;
|
|
12
|
+
/**
|
|
13
|
+
* Key agreement function over GOST R 34.11-94 hash
|
|
14
|
+
* @param parameters Curve parameters
|
|
15
|
+
* @param prv Private key
|
|
16
|
+
* @param pub Public key
|
|
17
|
+
* @param ukm User keying material (aka salt)
|
|
18
|
+
* @returns {TRet<Uint8Array>} Shared key
|
|
19
|
+
*/
|
|
20
|
+
export declare const kek_34102001: (parameters: GostCurveParameters, prv: TArg<Uint8Array>, pub: TArg<Uint8Array>, ukm: TArg<Uint8Array>) => TRet<Uint8Array>;
|
|
21
|
+
/**
|
|
22
|
+
* Key agreement function over Streebog (GOST R 34.11-2012) 256 bit hash
|
|
23
|
+
* @param parameters Curve parameters
|
|
24
|
+
* @param prv Private key
|
|
25
|
+
* @param pub Public key
|
|
26
|
+
* @param ukm User keying material (aka salt)
|
|
27
|
+
* @returns {TRet<Uint8Array>} Shared key
|
|
28
|
+
*/
|
|
29
|
+
export declare const kek_34102012256: (parameters: GostCurveParameters, prv: TArg<Uint8Array>, pub: TArg<Uint8Array>, ukm: TArg<Uint8Array>) => TRet<Uint8Array>;
|
|
30
|
+
/**
|
|
31
|
+
* Key agreement function over Streebog (GOST R 34.11-2012) 512 bit hash
|
|
32
|
+
* @param parameters Curve parameters
|
|
33
|
+
* @param prv Private key
|
|
34
|
+
* @param pub Public key
|
|
35
|
+
* @param ukm User keying material (aka salt)
|
|
36
|
+
* @returns {TRet<Uint8Array>} Shared key
|
|
37
|
+
*/
|
|
38
|
+
export declare const kek_34102012512: (parameters: GostCurveParameters, prv: TArg<Uint8Array>, pub: TArg<Uint8Array>, ukm: TArg<Uint8Array>) => TRet<Uint8Array>;
|
package/gost3410/vko.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Field } from "@noble/curves/abstract/modular.js";
|
|
2
|
+
import { weierstrass } from "@noble/curves/abstract/weierstrass.js";
|
|
3
|
+
import { gost341194 } from "../gost341194";
|
|
4
|
+
import { streebog256, streebog512 } from "../streebog/index.js";
|
|
5
|
+
import { bytesToNumberBE, concatBytes, numberToBytesLE } from "@noble/curves/utils.js";
|
|
6
|
+
/**
|
|
7
|
+
* Key agreement function
|
|
8
|
+
* @param parameters Curve parameters
|
|
9
|
+
* @param prv Private key
|
|
10
|
+
* @param pub Public key
|
|
11
|
+
* @param ukm User keying material (aka salt)
|
|
12
|
+
* @returns {TRet<Uint8Array>} Shared key
|
|
13
|
+
*/
|
|
14
|
+
export const kek = (parameters, prv, pub, ukm) => {
|
|
15
|
+
const Fn = Field(parameters.n);
|
|
16
|
+
const key = weierstrass(parameters).fromBytes(pub)
|
|
17
|
+
.multiply(bytesToNumberBE(prv))
|
|
18
|
+
.multiply(Fn.mulN(parameters.h, bytesToNumberBE(ukm)));
|
|
19
|
+
return concatBytes(numberToBytesLE(key.x, parameters.length), numberToBytesLE(key.y, parameters.length));
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Key agreement function over GOST R 34.11-94 hash
|
|
23
|
+
* @param parameters Curve parameters
|
|
24
|
+
* @param prv Private key
|
|
25
|
+
* @param pub Public key
|
|
26
|
+
* @param ukm User keying material (aka salt)
|
|
27
|
+
* @returns {TRet<Uint8Array>} Shared key
|
|
28
|
+
*/
|
|
29
|
+
export const kek_34102001 = (parameters, prv, pub, ukm) => gost341194(kek(parameters, prv, pub, ukm));
|
|
30
|
+
/**
|
|
31
|
+
* Key agreement function over Streebog (GOST R 34.11-2012) 256 bit hash
|
|
32
|
+
* @param parameters Curve parameters
|
|
33
|
+
* @param prv Private key
|
|
34
|
+
* @param pub Public key
|
|
35
|
+
* @param ukm User keying material (aka salt)
|
|
36
|
+
* @returns {TRet<Uint8Array>} Shared key
|
|
37
|
+
*/
|
|
38
|
+
export const kek_34102012256 = (parameters, prv, pub, ukm) => streebog256(kek(parameters, prv, pub, ukm));
|
|
39
|
+
/**
|
|
40
|
+
* Key agreement function over Streebog (GOST R 34.11-2012) 512 bit hash
|
|
41
|
+
* @param parameters Curve parameters
|
|
42
|
+
* @param prv Private key
|
|
43
|
+
* @param pub Public key
|
|
44
|
+
* @param ukm User keying material (aka salt)
|
|
45
|
+
* @returns {TRet<Uint8Array>} Shared key
|
|
46
|
+
*/
|
|
47
|
+
export const kek_34102012512 = (parameters, prv, pub, ukm) => streebog512(kek(parameters, prv, pub, ukm));
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type Hash, type TArg, type TRet } from "@noble/hashes/utils.js";
|
|
2
|
+
/** GOST R 34.11-94 hash function */
|
|
3
|
+
export declare class Gost341194 implements Hash<Gost341194> {
|
|
4
|
+
private data;
|
|
5
|
+
private sbox;
|
|
6
|
+
readonly blockLen: number;
|
|
7
|
+
readonly outputLen = 32;
|
|
8
|
+
readonly canXOF = false;
|
|
9
|
+
/** GOST R 34.11-94 hash function */
|
|
10
|
+
constructor(data?: TArg<Uint8Array>, sbox?: TArg<Uint8Array>[]);
|
|
11
|
+
/** Create hash instance */
|
|
12
|
+
static create(): Gost341194;
|
|
13
|
+
destroy(): void;
|
|
14
|
+
clone(): Gost341194;
|
|
15
|
+
_cloneInto(to?: Gost341194): Gost341194;
|
|
16
|
+
update(data: TArg<Uint8Array>): this;
|
|
17
|
+
digestInto(buf: TArg<Uint8Array>): void;
|
|
18
|
+
digest(): TRet<Uint8Array>;
|
|
19
|
+
}
|
|
20
|
+
/** GOST R 34.11-94 hash function */
|
|
21
|
+
export declare const gost341194: (msg: TArg<Uint8Array>, sbox?: TArg<Uint8Array>[]) => TRet<Uint8Array>;
|
|
22
|
+
/** DSTU GOST 34.311-95 */
|
|
23
|
+
export declare const gost3431195: (msg: TArg<Uint8Array>) => TRet<Uint8Array>;
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { concatBytes } from "@noble/hashes/utils.js";
|
|
2
|
+
import { Magma } from "../magma/index.js";
|
|
3
|
+
import { DSSZZI_UA_DKE_1, ID_GOSTR_3411_94_CRYPTOPRO_PARAM_SET } from "../magma/const.js";
|
|
4
|
+
import { bytesToNumberBE, numberToBytesBE } from "@noble/curves/utils.js";
|
|
5
|
+
import { xorBytes } from "../utils.js";
|
|
6
|
+
const BLOCKSIZE = 32;
|
|
7
|
+
const r = (1n << 256n) - 1n;
|
|
8
|
+
const C2 = new Uint8Array(32);
|
|
9
|
+
const C3 = new Uint8Array([
|
|
10
|
+
0xff, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff,
|
|
11
|
+
0xff, 0x00, 0x00, 0xff, 0x00, 0xff, 0xff, 0x00,
|
|
12
|
+
0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff,
|
|
13
|
+
0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00
|
|
14
|
+
]);
|
|
15
|
+
const C4 = new Uint8Array(32);
|
|
16
|
+
const A = (x) => {
|
|
17
|
+
const x2 = x.subarray(16, 24);
|
|
18
|
+
return concatBytes(xorBytes(x.subarray(24, 32), x2), x.subarray(0, 8), x.subarray(8, 16), x2);
|
|
19
|
+
};
|
|
20
|
+
const P = (x) => new Uint8Array([
|
|
21
|
+
x[0], x[8], x[16], x[24], x[1], x[9], x[17], x[25],
|
|
22
|
+
x[2], x[10], x[18], x[26], x[3], x[11], x[19], x[27],
|
|
23
|
+
x[4], x[12], x[20], x[28], x[5], x[13], x[21], x[29],
|
|
24
|
+
x[6], x[14], x[22], x[30], x[7], x[15], x[23], x[31]
|
|
25
|
+
]);
|
|
26
|
+
/*const chi = (Y: TArg<Uint8Array>): TRet<Uint8Array> => {
|
|
27
|
+
const byx = new Uint8Array(2);
|
|
28
|
+
byx[0] = Y[30] ^ Y[28] ^ Y[26] ^ Y[24] ^ Y[6] ^ Y[0];
|
|
29
|
+
byx[1] = Y[31] ^ Y[29] ^ Y[27] ^ Y[25] ^ Y[7] ^ Y[1];
|
|
30
|
+
|
|
31
|
+
const result = new Uint8Array(BLOCKSIZE);
|
|
32
|
+
result.set(byx, 0);
|
|
33
|
+
result.set(Y.slice(0,30), 2);
|
|
34
|
+
|
|
35
|
+
return result;
|
|
36
|
+
}*/
|
|
37
|
+
const chi = (Y) => new Uint8Array([
|
|
38
|
+
Y[30] ^ Y[28] ^ Y[26] ^ Y[24] ^ Y[6] ^ Y[0],
|
|
39
|
+
Y[31] ^ Y[29] ^ Y[27] ^ Y[25] ^ Y[7] ^ Y[1],
|
|
40
|
+
...Y.subarray(0, 30)
|
|
41
|
+
]);
|
|
42
|
+
const _step = (hin, m, sbox) => {
|
|
43
|
+
let u = hin;
|
|
44
|
+
let v = m;
|
|
45
|
+
let w = xorBytes(hin, m);
|
|
46
|
+
const k1 = new Magma(P(w).reverse(), sbox, true);
|
|
47
|
+
u = xorBytes(A(u), C2);
|
|
48
|
+
v = A(A(v));
|
|
49
|
+
w = xorBytes(u, v);
|
|
50
|
+
const k2 = new Magma(P(w).reverse(), sbox, true);
|
|
51
|
+
u = xorBytes(A(u), C3);
|
|
52
|
+
v = A(A(v));
|
|
53
|
+
w = xorBytes(u, v);
|
|
54
|
+
const k3 = new Magma(P(w).reverse(), sbox, true);
|
|
55
|
+
u = xorBytes(A(u), C4);
|
|
56
|
+
v = A(A(v));
|
|
57
|
+
w = xorBytes(u, v);
|
|
58
|
+
const k4 = new Magma(P(w).reverse(), sbox, true);
|
|
59
|
+
const s = concatBytes(k4.encrypt(hin.slice(0, 8).reverse()).reverse(), k3.encrypt(hin.slice(8, 16).reverse()).reverse(), k2.encrypt(hin.slice(16, 24).reverse()).reverse(), k1.encrypt(hin.slice(24, 32).reverse()).reverse());
|
|
60
|
+
//let x = new Uint8Array(s);
|
|
61
|
+
//for(let i = 0; i < 12; i++) x = chi(x);
|
|
62
|
+
let x = chi(s);
|
|
63
|
+
x = chi(x);
|
|
64
|
+
x = chi(x);
|
|
65
|
+
x = chi(x);
|
|
66
|
+
x = chi(x);
|
|
67
|
+
x = chi(x);
|
|
68
|
+
x = chi(x);
|
|
69
|
+
x = chi(x);
|
|
70
|
+
x = chi(x);
|
|
71
|
+
x = chi(x);
|
|
72
|
+
x = chi(x);
|
|
73
|
+
x = chi(x);
|
|
74
|
+
x = xorBytes(x, m);
|
|
75
|
+
x = chi(x);
|
|
76
|
+
x = xorBytes(hin, x);
|
|
77
|
+
//for(let i = 0; i < 61; i++) x = chi(x);
|
|
78
|
+
x = chi(x);
|
|
79
|
+
x = chi(x);
|
|
80
|
+
x = chi(x);
|
|
81
|
+
x = chi(x);
|
|
82
|
+
x = chi(x);
|
|
83
|
+
x = chi(x);
|
|
84
|
+
x = chi(x);
|
|
85
|
+
x = chi(x);
|
|
86
|
+
x = chi(x);
|
|
87
|
+
x = chi(x);
|
|
88
|
+
x = chi(x);
|
|
89
|
+
x = chi(x);
|
|
90
|
+
x = chi(x);
|
|
91
|
+
x = chi(x);
|
|
92
|
+
x = chi(x);
|
|
93
|
+
x = chi(x);
|
|
94
|
+
x = chi(x);
|
|
95
|
+
x = chi(x);
|
|
96
|
+
x = chi(x);
|
|
97
|
+
x = chi(x);
|
|
98
|
+
x = chi(x);
|
|
99
|
+
x = chi(x);
|
|
100
|
+
x = chi(x);
|
|
101
|
+
x = chi(x);
|
|
102
|
+
x = chi(x);
|
|
103
|
+
x = chi(x);
|
|
104
|
+
x = chi(x);
|
|
105
|
+
x = chi(x);
|
|
106
|
+
x = chi(x);
|
|
107
|
+
x = chi(x);
|
|
108
|
+
x = chi(x);
|
|
109
|
+
x = chi(x);
|
|
110
|
+
x = chi(x);
|
|
111
|
+
x = chi(x);
|
|
112
|
+
x = chi(x);
|
|
113
|
+
x = chi(x);
|
|
114
|
+
x = chi(x);
|
|
115
|
+
x = chi(x);
|
|
116
|
+
x = chi(x);
|
|
117
|
+
x = chi(x);
|
|
118
|
+
x = chi(x);
|
|
119
|
+
x = chi(x);
|
|
120
|
+
x = chi(x);
|
|
121
|
+
x = chi(x);
|
|
122
|
+
x = chi(x);
|
|
123
|
+
x = chi(x);
|
|
124
|
+
x = chi(x);
|
|
125
|
+
x = chi(x);
|
|
126
|
+
x = chi(x);
|
|
127
|
+
x = chi(x);
|
|
128
|
+
x = chi(x);
|
|
129
|
+
x = chi(x);
|
|
130
|
+
x = chi(x);
|
|
131
|
+
x = chi(x);
|
|
132
|
+
x = chi(x);
|
|
133
|
+
x = chi(x);
|
|
134
|
+
x = chi(x);
|
|
135
|
+
x = chi(x);
|
|
136
|
+
x = chi(x);
|
|
137
|
+
x = chi(x);
|
|
138
|
+
x = chi(x);
|
|
139
|
+
return x;
|
|
140
|
+
};
|
|
141
|
+
/** GOST R 34.11-94 hash function */
|
|
142
|
+
export class Gost341194 {
|
|
143
|
+
data;
|
|
144
|
+
sbox;
|
|
145
|
+
blockLen = BLOCKSIZE;
|
|
146
|
+
outputLen = 32;
|
|
147
|
+
canXOF = false;
|
|
148
|
+
/** GOST R 34.11-94 hash function */
|
|
149
|
+
constructor(data = new Uint8Array(), sbox = ID_GOSTR_3411_94_CRYPTOPRO_PARAM_SET) {
|
|
150
|
+
this.data = data;
|
|
151
|
+
this.sbox = sbox;
|
|
152
|
+
}
|
|
153
|
+
/** Create hash instance */
|
|
154
|
+
static create() { return new Gost341194(); }
|
|
155
|
+
destroy() { this.data = new Uint8Array(); }
|
|
156
|
+
clone() { return this._cloneInto(); }
|
|
157
|
+
_cloneInto(to) {
|
|
158
|
+
to ||= new Gost341194();
|
|
159
|
+
to.data = new Uint8Array(this.data);
|
|
160
|
+
to.sbox = this.sbox;
|
|
161
|
+
return to;
|
|
162
|
+
}
|
|
163
|
+
update(data) {
|
|
164
|
+
this.data = concatBytes(this.data, data);
|
|
165
|
+
return this;
|
|
166
|
+
}
|
|
167
|
+
digestInto(buf) {
|
|
168
|
+
let len = 0n;
|
|
169
|
+
let checksum = 0n;
|
|
170
|
+
const h = new Uint8Array(BLOCKSIZE);
|
|
171
|
+
const m = new Uint8Array(this.data);
|
|
172
|
+
for (let i = 0; i < m.length; i += BLOCKSIZE) {
|
|
173
|
+
let part = m.slice(i, i + BLOCKSIZE).reverse();
|
|
174
|
+
len += BigInt(part.length) * 8n;
|
|
175
|
+
checksum = (checksum + bytesToNumberBE(part)) & r;
|
|
176
|
+
if (part.length < BLOCKSIZE)
|
|
177
|
+
part = numberToBytesBE(bytesToNumberBE(part), BLOCKSIZE);
|
|
178
|
+
h.set(_step(h, part, this.sbox));
|
|
179
|
+
}
|
|
180
|
+
h.set(_step(_step(h, numberToBytesBE(len, BLOCKSIZE), this.sbox), numberToBytesBE(checksum, BLOCKSIZE), this.sbox));
|
|
181
|
+
buf.set(h.reverse());
|
|
182
|
+
this.destroy();
|
|
183
|
+
}
|
|
184
|
+
digest() {
|
|
185
|
+
const buffer = new Uint8Array(this.outputLen);
|
|
186
|
+
this.digestInto(buffer);
|
|
187
|
+
return buffer;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
/** GOST R 34.11-94 hash function */
|
|
191
|
+
export const gost341194 = (msg, sbox) => new Gost341194(msg, sbox).digest();
|
|
192
|
+
/** DSTU GOST 34.311-95 */
|
|
193
|
+
export const gost3431195 = (msg) => gost341194(msg, DSSZZI_UA_DKE_1);
|
package/hmac.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type TArg, type TRet } from "@noble/hashes/utils.js";
|
|
2
|
+
import { _HMAC } from "@noble/hashes/hmac.js";
|
|
3
|
+
import { Gost341194 } from "./gost341194/index.js";
|
|
4
|
+
export declare class Streebog256HMAC extends _HMAC<Streebog256HMAC> {
|
|
5
|
+
constructor(key: TArg<Uint8Array>);
|
|
6
|
+
}
|
|
7
|
+
export declare class Streebog512HMAC extends _HMAC<Streebog512HMAC> {
|
|
8
|
+
constructor(key: TArg<Uint8Array>);
|
|
9
|
+
}
|
|
10
|
+
export declare class Gost341194HMAC extends _HMAC<Gost341194> {
|
|
11
|
+
constructor(key: TArg<Uint8Array>);
|
|
12
|
+
}
|
|
13
|
+
export declare const streebog256hmac: (key: TArg<Uint8Array>, message: TArg<Uint8Array>) => TRet<Uint8Array>;
|
|
14
|
+
export declare const streebog512hmac: (key: TArg<Uint8Array>, message: TArg<Uint8Array>) => TRet<Uint8Array>;
|
|
15
|
+
export declare const gost341194hmac: (key: TArg<Uint8Array>, message: TArg<Uint8Array>) => TRet<Uint8Array>;
|