@li0ard/dstu 0.1.6 → 0.1.8
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/README.md +5 -0
- package/dstu4145/const.d.ts +2 -0
- package/dstu4145/const.js +42 -15
- package/dstu4145/ec/expand.d.ts +4 -3
- package/dstu4145/ec/expand.js +1 -2
- package/dstu4145/ec/index.js +1 -2
- package/dstu4145/{ec/math.d.ts → gf2m/index.d.ts} +1 -0
- package/dstu4145/gf2m/index.js +87 -0
- package/dstu4145/{ec → gf2m}/onb.js +1 -1
- package/dstu4145/gf2m/utils.d.ts +10 -0
- package/dstu4145/gf2m/utils.js +258 -0
- package/dstu4145/index.d.ts +66 -11
- package/dstu4145/index.js +53 -6
- package/dstu9041/curve.js +1 -2
- package/dstu9041/index.d.ts +2 -2
- package/dstu9041/index.js +49 -46
- package/dstu9311/const.d.ts +29 -0
- package/dstu9311/const.js +150 -0
- package/dstu9311/hash.d.ts +41 -0
- package/dstu9311/hash.js +98 -0
- package/dstu9311/index.d.ts +16 -0
- package/dstu9311/index.js +59 -0
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/kalyna/index.d.ts +2 -1
- package/kalyna/index.js +23 -28
- package/keywrap.d.ts +6 -0
- package/keywrap.js +39 -0
- package/modes/cbc.d.ts +2 -3
- package/modes/cbc.js +4 -3
- package/modes/ccm.d.ts +4 -0
- package/modes/ccm.js +47 -0
- package/modes/cfb.d.ts +3 -4
- package/modes/cfb.js +88 -56
- package/modes/cmac.d.ts +2 -0
- package/modes/cmac.js +45 -0
- package/modes/ctr.d.ts +2 -3
- package/modes/ctr.js +25 -14
- package/modes/ecb.d.ts +2 -3
- package/modes/gcm.d.ts +3 -4
- package/modes/gcm.js +19 -16
- package/modes/gmac.d.ts +3 -0
- package/modes/gmac.js +39 -0
- package/modes/index.d.ts +3 -1
- package/modes/index.js +3 -1
- package/modes/kw.d.ts +2 -2
- package/modes/kw.js +2 -0
- package/modes/ofb.d.ts +2 -3
- package/modes/ofb.js +3 -2
- package/modes/xts.d.ts +2 -2
- package/modes/xts.js +32 -21
- package/package.json +4 -4
- package/types.d.ts +5 -3
- package/utils.d.ts +6 -0
- package/utils.js +15 -3
- package/dstu4145/ec/math.js +0 -204
- package/modes/mac.d.ts +0 -6
- package/modes/mac.js +0 -61
- /package/dstu4145/{ec → gf2m}/onb.d.ts +0 -0
package/dstu4145/index.d.ts
CHANGED
|
@@ -3,7 +3,28 @@ import { type DSTUParameters } from "./const.js";
|
|
|
3
3
|
/** Create DSTU 4145-2002 signer (Big-Endian) */
|
|
4
4
|
export declare const dstu4145: (parameters: DSTUParameters) => Readonly<{
|
|
5
5
|
getPublicKey: (secretKey: TArg<Uint8Array>, isCompressed?: boolean) => TRet<Uint8Array>;
|
|
6
|
-
|
|
6
|
+
getSharedSecret: (secretKeyA: TArg<Uint8Array>, publicKeyB: TArg<Uint8Array>, withCofactor?: boolean) => TRet<Uint8Array>;
|
|
7
|
+
sign: (secretKey: TArg<Uint8Array>, digest: TArg<Uint8Array>, rand?: TArg<Uint8Array>) => TRet<Uint8Array>;
|
|
8
|
+
verify: (publicKey: TArg<Uint8Array>, digest: TArg<Uint8Array>, signature: TArg<Uint8Array>) => boolean;
|
|
9
|
+
keygen: (isCompressed?: boolean) => {
|
|
10
|
+
secretKey: TRet<Uint8Array>;
|
|
11
|
+
publicKey: TRet<Uint8Array>;
|
|
12
|
+
};
|
|
13
|
+
lengths: Readonly<{
|
|
14
|
+
fieldByteLength: number;
|
|
15
|
+
pointByteLength: number;
|
|
16
|
+
scalarByteLength: number;
|
|
17
|
+
signatureByteLength: number;
|
|
18
|
+
}>;
|
|
19
|
+
}>;
|
|
20
|
+
/**
|
|
21
|
+
* Create DSTU 4145-2002 signer (Little-Endian)
|
|
22
|
+
*
|
|
23
|
+
* **NOTE:** Parameters MUST be in Big-Endian
|
|
24
|
+
*/
|
|
25
|
+
export declare const dstu4145_le: (parameters: DSTUParameters) => Readonly<{
|
|
26
|
+
getPublicKey: (secretKey: TArg<Uint8Array>, isCompressed?: boolean) => TRet<Uint8Array>;
|
|
27
|
+
getSharedSecret: (secretKeyA: TArg<Uint8Array>, publicKeyB: TArg<Uint8Array>, withCofactor?: boolean) => TRet<Uint8Array>;
|
|
7
28
|
sign: (secretKey: TArg<Uint8Array>, digest: TArg<Uint8Array>, rand?: TArg<Uint8Array>) => TRet<Uint8Array>;
|
|
8
29
|
verify: (publicKey: TArg<Uint8Array>, digest: TArg<Uint8Array>, signature: TArg<Uint8Array>) => boolean;
|
|
9
30
|
keygen: (isCompressed?: boolean) => {
|
|
@@ -22,7 +43,7 @@ export * from "./ec/expand.js";
|
|
|
22
43
|
/** DSTU 4145-2002 163 bit curve */
|
|
23
44
|
export declare const dstu163: Readonly<{
|
|
24
45
|
getPublicKey: (secretKey: TArg<Uint8Array>, isCompressed?: boolean) => TRet<Uint8Array>;
|
|
25
|
-
|
|
46
|
+
getSharedSecret: (secretKeyA: TArg<Uint8Array>, publicKeyB: TArg<Uint8Array>, withCofactor?: boolean) => TRet<Uint8Array>;
|
|
26
47
|
sign: (secretKey: TArg<Uint8Array>, digest: TArg<Uint8Array>, rand?: TArg<Uint8Array>) => TRet<Uint8Array>;
|
|
27
48
|
verify: (publicKey: TArg<Uint8Array>, digest: TArg<Uint8Array>, signature: TArg<Uint8Array>) => boolean;
|
|
28
49
|
keygen: (isCompressed?: boolean) => {
|
|
@@ -39,7 +60,7 @@ export declare const dstu163: Readonly<{
|
|
|
39
60
|
/** DSTU 4145-2002 167 bit curve */
|
|
40
61
|
export declare const dstu167: Readonly<{
|
|
41
62
|
getPublicKey: (secretKey: TArg<Uint8Array>, isCompressed?: boolean) => TRet<Uint8Array>;
|
|
42
|
-
|
|
63
|
+
getSharedSecret: (secretKeyA: TArg<Uint8Array>, publicKeyB: TArg<Uint8Array>, withCofactor?: boolean) => TRet<Uint8Array>;
|
|
43
64
|
sign: (secretKey: TArg<Uint8Array>, digest: TArg<Uint8Array>, rand?: TArg<Uint8Array>) => TRet<Uint8Array>;
|
|
44
65
|
verify: (publicKey: TArg<Uint8Array>, digest: TArg<Uint8Array>, signature: TArg<Uint8Array>) => boolean;
|
|
45
66
|
keygen: (isCompressed?: boolean) => {
|
|
@@ -56,7 +77,7 @@ export declare const dstu167: Readonly<{
|
|
|
56
77
|
/** DSTU 4145-2002 173 bit curve */
|
|
57
78
|
export declare const dstu173: Readonly<{
|
|
58
79
|
getPublicKey: (secretKey: TArg<Uint8Array>, isCompressed?: boolean) => TRet<Uint8Array>;
|
|
59
|
-
|
|
80
|
+
getSharedSecret: (secretKeyA: TArg<Uint8Array>, publicKeyB: TArg<Uint8Array>, withCofactor?: boolean) => TRet<Uint8Array>;
|
|
60
81
|
sign: (secretKey: TArg<Uint8Array>, digest: TArg<Uint8Array>, rand?: TArg<Uint8Array>) => TRet<Uint8Array>;
|
|
61
82
|
verify: (publicKey: TArg<Uint8Array>, digest: TArg<Uint8Array>, signature: TArg<Uint8Array>) => boolean;
|
|
62
83
|
keygen: (isCompressed?: boolean) => {
|
|
@@ -73,7 +94,7 @@ export declare const dstu173: Readonly<{
|
|
|
73
94
|
/** DSTU 4145-2002 179 bit curve */
|
|
74
95
|
export declare const dstu179: Readonly<{
|
|
75
96
|
getPublicKey: (secretKey: TArg<Uint8Array>, isCompressed?: boolean) => TRet<Uint8Array>;
|
|
76
|
-
|
|
97
|
+
getSharedSecret: (secretKeyA: TArg<Uint8Array>, publicKeyB: TArg<Uint8Array>, withCofactor?: boolean) => TRet<Uint8Array>;
|
|
77
98
|
sign: (secretKey: TArg<Uint8Array>, digest: TArg<Uint8Array>, rand?: TArg<Uint8Array>) => TRet<Uint8Array>;
|
|
78
99
|
verify: (publicKey: TArg<Uint8Array>, digest: TArg<Uint8Array>, signature: TArg<Uint8Array>) => boolean;
|
|
79
100
|
keygen: (isCompressed?: boolean) => {
|
|
@@ -90,7 +111,7 @@ export declare const dstu179: Readonly<{
|
|
|
90
111
|
/** DSTU 4145-2002 191 bit curve */
|
|
91
112
|
export declare const dstu191: Readonly<{
|
|
92
113
|
getPublicKey: (secretKey: TArg<Uint8Array>, isCompressed?: boolean) => TRet<Uint8Array>;
|
|
93
|
-
|
|
114
|
+
getSharedSecret: (secretKeyA: TArg<Uint8Array>, publicKeyB: TArg<Uint8Array>, withCofactor?: boolean) => TRet<Uint8Array>;
|
|
94
115
|
sign: (secretKey: TArg<Uint8Array>, digest: TArg<Uint8Array>, rand?: TArg<Uint8Array>) => TRet<Uint8Array>;
|
|
95
116
|
verify: (publicKey: TArg<Uint8Array>, digest: TArg<Uint8Array>, signature: TArg<Uint8Array>) => boolean;
|
|
96
117
|
keygen: (isCompressed?: boolean) => {
|
|
@@ -107,7 +128,7 @@ export declare const dstu191: Readonly<{
|
|
|
107
128
|
/** DSTU 4145-2002 233 bit curve */
|
|
108
129
|
export declare const dstu233: Readonly<{
|
|
109
130
|
getPublicKey: (secretKey: TArg<Uint8Array>, isCompressed?: boolean) => TRet<Uint8Array>;
|
|
110
|
-
|
|
131
|
+
getSharedSecret: (secretKeyA: TArg<Uint8Array>, publicKeyB: TArg<Uint8Array>, withCofactor?: boolean) => TRet<Uint8Array>;
|
|
111
132
|
sign: (secretKey: TArg<Uint8Array>, digest: TArg<Uint8Array>, rand?: TArg<Uint8Array>) => TRet<Uint8Array>;
|
|
112
133
|
verify: (publicKey: TArg<Uint8Array>, digest: TArg<Uint8Array>, signature: TArg<Uint8Array>) => boolean;
|
|
113
134
|
keygen: (isCompressed?: boolean) => {
|
|
@@ -124,7 +145,24 @@ export declare const dstu233: Readonly<{
|
|
|
124
145
|
/** DSTU 4145-2002 257 bit curve */
|
|
125
146
|
export declare const dstu257: Readonly<{
|
|
126
147
|
getPublicKey: (secretKey: TArg<Uint8Array>, isCompressed?: boolean) => TRet<Uint8Array>;
|
|
127
|
-
|
|
148
|
+
getSharedSecret: (secretKeyA: TArg<Uint8Array>, publicKeyB: TArg<Uint8Array>, withCofactor?: boolean) => TRet<Uint8Array>;
|
|
149
|
+
sign: (secretKey: TArg<Uint8Array>, digest: TArg<Uint8Array>, rand?: TArg<Uint8Array>) => TRet<Uint8Array>;
|
|
150
|
+
verify: (publicKey: TArg<Uint8Array>, digest: TArg<Uint8Array>, signature: TArg<Uint8Array>) => boolean;
|
|
151
|
+
keygen: (isCompressed?: boolean) => {
|
|
152
|
+
secretKey: TRet<Uint8Array>;
|
|
153
|
+
publicKey: TRet<Uint8Array>;
|
|
154
|
+
};
|
|
155
|
+
lengths: Readonly<{
|
|
156
|
+
fieldByteLength: number;
|
|
157
|
+
pointByteLength: number;
|
|
158
|
+
scalarByteLength: number;
|
|
159
|
+
signatureByteLength: number;
|
|
160
|
+
}>;
|
|
161
|
+
}>;
|
|
162
|
+
/** DSTU 4145-2002 257 bit curve (LE) */
|
|
163
|
+
export declare const dstu257_le: Readonly<{
|
|
164
|
+
getPublicKey: (secretKey: TArg<Uint8Array>, isCompressed?: boolean) => TRet<Uint8Array>;
|
|
165
|
+
getSharedSecret: (secretKeyA: TArg<Uint8Array>, publicKeyB: TArg<Uint8Array>, withCofactor?: boolean) => TRet<Uint8Array>;
|
|
128
166
|
sign: (secretKey: TArg<Uint8Array>, digest: TArg<Uint8Array>, rand?: TArg<Uint8Array>) => TRet<Uint8Array>;
|
|
129
167
|
verify: (publicKey: TArg<Uint8Array>, digest: TArg<Uint8Array>, signature: TArg<Uint8Array>) => boolean;
|
|
130
168
|
keygen: (isCompressed?: boolean) => {
|
|
@@ -141,7 +179,7 @@ export declare const dstu257: Readonly<{
|
|
|
141
179
|
/** DSTU 4145-2002 307 bit curve */
|
|
142
180
|
export declare const dstu307: Readonly<{
|
|
143
181
|
getPublicKey: (secretKey: TArg<Uint8Array>, isCompressed?: boolean) => TRet<Uint8Array>;
|
|
144
|
-
|
|
182
|
+
getSharedSecret: (secretKeyA: TArg<Uint8Array>, publicKeyB: TArg<Uint8Array>, withCofactor?: boolean) => TRet<Uint8Array>;
|
|
145
183
|
sign: (secretKey: TArg<Uint8Array>, digest: TArg<Uint8Array>, rand?: TArg<Uint8Array>) => TRet<Uint8Array>;
|
|
146
184
|
verify: (publicKey: TArg<Uint8Array>, digest: TArg<Uint8Array>, signature: TArg<Uint8Array>) => boolean;
|
|
147
185
|
keygen: (isCompressed?: boolean) => {
|
|
@@ -158,7 +196,7 @@ export declare const dstu307: Readonly<{
|
|
|
158
196
|
/** DSTU 4145-2002 367 bit curve */
|
|
159
197
|
export declare const dstu367: Readonly<{
|
|
160
198
|
getPublicKey: (secretKey: TArg<Uint8Array>, isCompressed?: boolean) => TRet<Uint8Array>;
|
|
161
|
-
|
|
199
|
+
getSharedSecret: (secretKeyA: TArg<Uint8Array>, publicKeyB: TArg<Uint8Array>, withCofactor?: boolean) => TRet<Uint8Array>;
|
|
162
200
|
sign: (secretKey: TArg<Uint8Array>, digest: TArg<Uint8Array>, rand?: TArg<Uint8Array>) => TRet<Uint8Array>;
|
|
163
201
|
verify: (publicKey: TArg<Uint8Array>, digest: TArg<Uint8Array>, signature: TArg<Uint8Array>) => boolean;
|
|
164
202
|
keygen: (isCompressed?: boolean) => {
|
|
@@ -175,7 +213,24 @@ export declare const dstu367: Readonly<{
|
|
|
175
213
|
/** DSTU 4145-2002 431 bit curve */
|
|
176
214
|
export declare const dstu431: Readonly<{
|
|
177
215
|
getPublicKey: (secretKey: TArg<Uint8Array>, isCompressed?: boolean) => TRet<Uint8Array>;
|
|
178
|
-
|
|
216
|
+
getSharedSecret: (secretKeyA: TArg<Uint8Array>, publicKeyB: TArg<Uint8Array>, withCofactor?: boolean) => TRet<Uint8Array>;
|
|
217
|
+
sign: (secretKey: TArg<Uint8Array>, digest: TArg<Uint8Array>, rand?: TArg<Uint8Array>) => TRet<Uint8Array>;
|
|
218
|
+
verify: (publicKey: TArg<Uint8Array>, digest: TArg<Uint8Array>, signature: TArg<Uint8Array>) => boolean;
|
|
219
|
+
keygen: (isCompressed?: boolean) => {
|
|
220
|
+
secretKey: TRet<Uint8Array>;
|
|
221
|
+
publicKey: TRet<Uint8Array>;
|
|
222
|
+
};
|
|
223
|
+
lengths: Readonly<{
|
|
224
|
+
fieldByteLength: number;
|
|
225
|
+
pointByteLength: number;
|
|
226
|
+
scalarByteLength: number;
|
|
227
|
+
signatureByteLength: number;
|
|
228
|
+
}>;
|
|
229
|
+
}>;
|
|
230
|
+
/** DSTU 4145-2002 431 bit curve (LE) */
|
|
231
|
+
export declare const dstu431_le: Readonly<{
|
|
232
|
+
getPublicKey: (secretKey: TArg<Uint8Array>, isCompressed?: boolean) => TRet<Uint8Array>;
|
|
233
|
+
getSharedSecret: (secretKeyA: TArg<Uint8Array>, publicKeyB: TArg<Uint8Array>, withCofactor?: boolean) => TRet<Uint8Array>;
|
|
179
234
|
sign: (secretKey: TArg<Uint8Array>, digest: TArg<Uint8Array>, rand?: TArg<Uint8Array>) => TRet<Uint8Array>;
|
|
180
235
|
verify: (publicKey: TArg<Uint8Array>, digest: TArg<Uint8Array>, signature: TArg<Uint8Array>) => boolean;
|
|
181
236
|
keygen: (isCompressed?: boolean) => {
|
package/dstu4145/index.js
CHANGED
|
@@ -2,31 +2,42 @@ import { concatBytes, randomBytes } from "@noble/hashes/utils.js";
|
|
|
2
2
|
import { DSTU_163, DSTU_167, DSTU_173, DSTU_179, DSTU_191, DSTU_233, DSTU_257, DSTU_307, DSTU_367, DSTU_431 } from "./const.js";
|
|
3
3
|
import { binaryWeierstrass } from "./ec/index.js";
|
|
4
4
|
import BN from "bn.js";
|
|
5
|
+
import { reverseBytes } from "../utils.js";
|
|
5
6
|
/** Create DSTU 4145-2002 signer (Big-Endian) */
|
|
6
7
|
export const dstu4145 = (parameters) => {
|
|
7
8
|
const curve = binaryWeierstrass(parameters);
|
|
8
9
|
const { Field, Point, MASK, lengths } = curve;
|
|
10
|
+
/**
|
|
11
|
+
* Computes public key for a secret key
|
|
12
|
+
* @param isCompressed - whether to return compact (default), or full key
|
|
13
|
+
* @returns Public key, full when `isCompressed=false`; short when `isCompressed=true`
|
|
14
|
+
*/
|
|
9
15
|
const getPublicKey = (secretKey, isCompressed = false) => Point.BASE.mul(Field.fromHexStringOrBytes(secretKey)).negate().toBytes(isCompressed);
|
|
10
16
|
const randomPrivateKey = () => Field.toBytes(new BN(randomBytes(lengths.scalarByteLength)).imaskn(MASK), lengths.scalarByteLength);
|
|
17
|
+
/**
|
|
18
|
+
* Computes presign (ephermeral keypair)
|
|
19
|
+
* @param rand Predefined secret ephermeral key
|
|
20
|
+
* @returns Ephemeral public key (`Fe`) and secret key (`e`)
|
|
21
|
+
*/
|
|
11
22
|
const computePresign = (rand) => {
|
|
12
|
-
const e = (rand
|
|
13
|
-
? new BN(rand)
|
|
14
|
-
: new BN(randomBytes(lengths.scalarByteLength))).imaskn(MASK);
|
|
23
|
+
const e = new BN(rand ?? randomBytes(lengths.scalarByteLength)).imaskn(MASK);
|
|
15
24
|
if (rand && e.isZero())
|
|
16
25
|
throw new Error("Invalid custom rand for presign (rand = 0)");
|
|
17
|
-
if (e.isZero())
|
|
26
|
+
else if (e.isZero())
|
|
18
27
|
return computePresign(rand);
|
|
19
28
|
const Fe = Point.BASE.mul(e).x;
|
|
20
29
|
if (Fe.isZero())
|
|
21
30
|
return computePresign(rand);
|
|
22
31
|
return { Fe, e };
|
|
23
32
|
};
|
|
33
|
+
/** Converts hash into field element */
|
|
24
34
|
const prepareHash = (digest) => {
|
|
25
35
|
let h = curve.toInternalField(Field.hashToField(digest));
|
|
26
36
|
if (h.isZero())
|
|
27
37
|
h = new BN(1);
|
|
28
38
|
return h;
|
|
29
39
|
};
|
|
40
|
+
/** Signs a message hash with a secret key. */
|
|
30
41
|
const sign = (secretKey, digest, rand) => {
|
|
31
42
|
const d = new BN(secretKey), h = prepareHash(digest), { Fe, e } = computePresign(rand);
|
|
32
43
|
if (d.isZero() || d.gte(curve.ORDER))
|
|
@@ -39,6 +50,7 @@ export const dstu4145 = (parameters) => {
|
|
|
39
50
|
return sign(secretKey, digest, rand);
|
|
40
51
|
return concatBytes(Field.toBytes(s, lengths.scalarByteLength), Field.toBytes(r, lengths.scalarByteLength));
|
|
41
52
|
};
|
|
53
|
+
/** Verifies a signature against message hash and public key. */
|
|
42
54
|
const verify = (publicKey, digest, signature) => {
|
|
43
55
|
if (signature.length != lengths.signatureByteLength)
|
|
44
56
|
throw new Error("Invalid signature length");
|
|
@@ -51,7 +63,11 @@ export const dstu4145 = (parameters) => {
|
|
|
51
63
|
const y = curve.toExternalField(Field.mul(h, R.x)).imaskn(MASK);
|
|
52
64
|
return y.eq(r);
|
|
53
65
|
};
|
|
54
|
-
|
|
66
|
+
/**
|
|
67
|
+
* Computes shared secret key
|
|
68
|
+
* @param withCofactor Multiply result by curve cofactor? (default - `true`)
|
|
69
|
+
*/
|
|
70
|
+
const getSharedSecret = (secretKeyA, publicKeyB, withCofactor = true) => {
|
|
55
71
|
const d = new BN(secretKeyA), Q = Point.fromBytes(publicKeyB);
|
|
56
72
|
if (d.isZero() || d.gte(curve.ORDER))
|
|
57
73
|
throw new Error("Invalid private key, must be in range 1 < key < order");
|
|
@@ -69,13 +85,40 @@ export const dstu4145 = (parameters) => {
|
|
|
69
85
|
};
|
|
70
86
|
return Object.freeze({
|
|
71
87
|
getPublicKey,
|
|
72
|
-
|
|
88
|
+
getSharedSecret,
|
|
73
89
|
sign,
|
|
74
90
|
verify,
|
|
75
91
|
keygen,
|
|
76
92
|
lengths
|
|
77
93
|
});
|
|
78
94
|
};
|
|
95
|
+
/**
|
|
96
|
+
* Create DSTU 4145-2002 signer (Little-Endian)
|
|
97
|
+
*
|
|
98
|
+
* **NOTE:** Parameters MUST be in Big-Endian
|
|
99
|
+
*/
|
|
100
|
+
export const dstu4145_le = (parameters) => {
|
|
101
|
+
const signer = dstu4145(parameters);
|
|
102
|
+
const getPublicKey = (secretKey, isCompressed = false) => reverseBytes(signer.getPublicKey(reverseBytes(secretKey), isCompressed));
|
|
103
|
+
const sign = (secretKey, digest, rand) => reverseBytes(signer.sign(reverseBytes(secretKey), reverseBytes(digest), rand ? reverseBytes(rand) : undefined));
|
|
104
|
+
const verify = (publicKey, digest, signature) => signer.verify(reverseBytes(publicKey), reverseBytes(digest), reverseBytes(signature));
|
|
105
|
+
const getSharedSecret = (secretKeyA, publicKeyB, withCofactor = true) => reverseBytes(signer.getSharedSecret(reverseBytes(secretKeyA), reverseBytes(publicKeyB), withCofactor));
|
|
106
|
+
const keygen = (isCompressed = false) => {
|
|
107
|
+
const { secretKey, publicKey } = signer.keygen(isCompressed);
|
|
108
|
+
return {
|
|
109
|
+
secretKey: reverseBytes(secretKey),
|
|
110
|
+
publicKey: reverseBytes(publicKey)
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
return Object.freeze({
|
|
114
|
+
getPublicKey,
|
|
115
|
+
getSharedSecret,
|
|
116
|
+
sign,
|
|
117
|
+
verify,
|
|
118
|
+
keygen,
|
|
119
|
+
lengths: signer.lengths
|
|
120
|
+
});
|
|
121
|
+
};
|
|
79
122
|
export * from "./const.js";
|
|
80
123
|
export * from "./ec/expand.js";
|
|
81
124
|
// ONB curves don't preinitialized because `multiplyOnb` is slow O(m^3) function
|
|
@@ -94,9 +137,13 @@ export const dstu191 = dstu4145(DSTU_191);
|
|
|
94
137
|
export const dstu233 = dstu4145(DSTU_233);
|
|
95
138
|
/** DSTU 4145-2002 257 bit curve */
|
|
96
139
|
export const dstu257 = dstu4145(DSTU_257);
|
|
140
|
+
/** DSTU 4145-2002 257 bit curve (LE) */
|
|
141
|
+
export const dstu257_le = dstu4145_le(DSTU_257);
|
|
97
142
|
/** DSTU 4145-2002 307 bit curve */
|
|
98
143
|
export const dstu307 = dstu4145(DSTU_307);
|
|
99
144
|
/** DSTU 4145-2002 367 bit curve */
|
|
100
145
|
export const dstu367 = dstu4145(DSTU_367);
|
|
101
146
|
/** DSTU 4145-2002 431 bit curve */
|
|
102
147
|
export const dstu431 = dstu4145(DSTU_431);
|
|
148
|
+
/** DSTU 4145-2002 431 bit curve (LE) */
|
|
149
|
+
export const dstu431_le = dstu4145_le(DSTU_431);
|
package/dstu9041/curve.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Field, mod } from "@noble/curves/abstract/modular.js";
|
|
2
|
-
import { bitGet, bitLen, bytesToNumberBE, randomBytes } from "@noble/curves/utils.js";
|
|
3
|
-
import { concatBytes } from "@noble/hashes/utils.js";
|
|
2
|
+
import { concatBytes, bitGet, bitLen, bytesToNumberBE, randomBytes } from "@noble/curves/utils.js";
|
|
4
3
|
export const dstu9041Curve = (parameters) => {
|
|
5
4
|
if (parameters.a != 2n)
|
|
6
5
|
throw new Error("Unsuppored `a` parameter, must be 2");
|
package/dstu9041/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export declare const dstu9041_256: Readonly<{
|
|
|
6
6
|
secretKey: TRet<Uint8Array>;
|
|
7
7
|
publicKey: TRet<Uint8Array>;
|
|
8
8
|
};
|
|
9
|
-
encrypt: (
|
|
9
|
+
encrypt: (plaintext: TArg<Uint8Array>, publicKey: TArg<Uint8Array>, rand?: TArg<Uint8Array>) => TRet<Uint8Array>;
|
|
10
10
|
decrypt: (ciphertext: TArg<Uint8Array>, privateKey: TArg<Uint8Array>) => TRet<Uint8Array>;
|
|
11
11
|
}>;
|
|
12
12
|
/** DSTU 9041:2020 (512 bit) */
|
|
@@ -16,6 +16,6 @@ export declare const dstu9041_512: Readonly<{
|
|
|
16
16
|
secretKey: TRet<Uint8Array>;
|
|
17
17
|
publicKey: TRet<Uint8Array>;
|
|
18
18
|
};
|
|
19
|
-
encrypt: (
|
|
19
|
+
encrypt: (plaintext: TArg<Uint8Array>, publicKey: TArg<Uint8Array>, rand?: TArg<Uint8Array>) => TRet<Uint8Array>;
|
|
20
20
|
decrypt: (ciphertext: TArg<Uint8Array>, privateKey: TArg<Uint8Array>) => TRet<Uint8Array>;
|
|
21
21
|
}>;
|
package/dstu9041/index.js
CHANGED
|
@@ -1,34 +1,44 @@
|
|
|
1
|
-
import { bytesToNumberBE, concatBytes, equalBytes, numberToBytesBE } from "@noble/curves/utils.js";
|
|
1
|
+
import { randomBytes, bytesToNumberBE, concatBytes, equalBytes, numberToBytesBE } from "@noble/curves/utils.js";
|
|
2
2
|
import { kupyna256 } from "../kupyna/index.js";
|
|
3
|
-
import { curve256, curve512 } from "./curve.js";
|
|
3
|
+
import { curve256, curve512, dstu9041Curve } from "./curve.js";
|
|
4
4
|
import { kw } from "../modes/index.js";
|
|
5
5
|
import { Kalyna256, Kalyna512 } from "../kalyna/index.js";
|
|
6
|
-
import { randomBytes } from "@noble/hashes/utils.js";
|
|
7
6
|
const ID_KUPYNA256 = 1;
|
|
8
7
|
const dstu9041 = (length) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
8
|
+
let MAX_LENGTH, HASH_LENGTH_BYTES, curve, Сipher;
|
|
9
|
+
switch (length) {
|
|
10
|
+
case 256:
|
|
11
|
+
MAX_LENGTH = 200;
|
|
12
|
+
HASH_LENGTH_BYTES = 4;
|
|
13
|
+
curve = curve256;
|
|
14
|
+
Сipher = Kalyna256;
|
|
15
|
+
break;
|
|
16
|
+
case 512:
|
|
17
|
+
MAX_LENGTH = 424;
|
|
18
|
+
HASH_LENGTH_BYTES = 8;
|
|
19
|
+
curve = curve512;
|
|
20
|
+
Сipher = Kalyna512;
|
|
21
|
+
break;
|
|
22
|
+
default:
|
|
23
|
+
throw new Error("Invalid length, supported only 256 and 512 bits");
|
|
24
|
+
}
|
|
25
|
+
const PADDED_MESSAGE_BYTES = MAX_LENGTH / 8, STRUCT_BYTES = 1 + HASH_LENGTH_BYTES + 2 + PADDED_MESSAGE_BYTES, { Point } = curve, { Fp, Fn } = Point;
|
|
26
|
+
const padMessage = (message) => {
|
|
27
|
+
if (message.length == 0)
|
|
17
28
|
throw new Error("Invalid message length");
|
|
18
|
-
if (
|
|
29
|
+
if (message.length > PADDED_MESSAGE_BYTES)
|
|
19
30
|
throw new Error("Message too long");
|
|
20
|
-
const messageBytes = Math.ceil(messageBits / 8);
|
|
21
|
-
if (message.length != messageBytes)
|
|
22
|
-
throw new Error("Message length mismatch");
|
|
23
31
|
const paddedMessage = new Uint8Array(PADDED_MESSAGE_BYTES);
|
|
24
|
-
paddedMessage.set(message, PADDED_MESSAGE_BYTES -
|
|
32
|
+
paddedMessage.set(message, PADDED_MESSAGE_BYTES - message.length);
|
|
25
33
|
return paddedMessage;
|
|
26
34
|
};
|
|
27
|
-
const buildStruct = (
|
|
28
|
-
const
|
|
35
|
+
const buildStruct = (message) => {
|
|
36
|
+
const paddedMessage = padMessage(message);
|
|
37
|
+
const messageLength = numberToBytesBE(message.length * 8, 2);
|
|
38
|
+
const digest = kupyna256(concatBytes(messageLength, paddedMessage)).subarray(-HASH_LENGTH_BYTES);
|
|
29
39
|
const struct = new Uint8Array(STRUCT_BYTES);
|
|
30
|
-
struct[0] =
|
|
31
|
-
struct.set(digest
|
|
40
|
+
struct[0] = ID_KUPYNA256;
|
|
41
|
+
struct.set(digest, 1);
|
|
32
42
|
struct.set(messageLength, 1 + HASH_LENGTH_BYTES);
|
|
33
43
|
struct.set(paddedMessage, 3 + HASH_LENGTH_BYTES);
|
|
34
44
|
return struct;
|
|
@@ -36,20 +46,19 @@ const dstu9041 = (length) => {
|
|
|
36
46
|
const parseStruct = (struct) => {
|
|
37
47
|
if (struct.length != STRUCT_BYTES)
|
|
38
48
|
throw new Error("Invalid ciphertext");
|
|
39
|
-
|
|
40
|
-
if (hashId != ID_KUPYNA256)
|
|
49
|
+
if (struct[0] != ID_KUPYNA256)
|
|
41
50
|
throw new Error("Invalid hash ID");
|
|
42
51
|
const embeddedHash = struct.subarray(1, HASH_LENGTH_BYTES + 1);
|
|
43
52
|
const messageLength = struct.subarray(1 + HASH_LENGTH_BYTES, 3 + HASH_LENGTH_BYTES);
|
|
44
|
-
const paddedMessage =
|
|
45
|
-
paddedMessage.set(struct.subarray(3 + HASH_LENGTH_BYTES));
|
|
53
|
+
const paddedMessage = struct.subarray(3 + HASH_LENGTH_BYTES);
|
|
46
54
|
const messageBits = Number(bytesToNumberBE(messageLength));
|
|
47
55
|
if (messageBits == 0)
|
|
48
56
|
throw new Error("Invalid message length");
|
|
49
57
|
if (messageBits > MAX_LENGTH)
|
|
50
58
|
throw new Error("Message too long");
|
|
51
|
-
|
|
52
|
-
|
|
59
|
+
// message len + padded message
|
|
60
|
+
const digest = kupyna256(struct.subarray(1 + HASH_LENGTH_BYTES)).subarray(-HASH_LENGTH_BYTES);
|
|
61
|
+
if (!equalBytes(embeddedHash, digest))
|
|
53
62
|
throw new Error("Integrity check failed, hash mismatch");
|
|
54
63
|
const messageBytes = Math.ceil(messageBits / 8);
|
|
55
64
|
const paddingLen = PADDED_MESSAGE_BYTES - messageBytes;
|
|
@@ -58,37 +67,31 @@ const dstu9041 = (length) => {
|
|
|
58
67
|
invalidPadding |= (i < paddingLen ? 1 : 0) & (paddedMessage[i] != 0 ? 1 : 0);
|
|
59
68
|
if (invalidPadding != 0)
|
|
60
69
|
throw new Error("Invalid padding");
|
|
61
|
-
return paddedMessage.
|
|
70
|
+
return paddedMessage.slice(paddingLen);
|
|
62
71
|
};
|
|
63
72
|
return Object.freeze({
|
|
64
73
|
getPublicKey: curve.getPublicKey,
|
|
65
74
|
keygen: curve.keygen,
|
|
66
|
-
encrypt: (
|
|
67
|
-
const
|
|
68
|
-
const
|
|
69
|
-
const
|
|
70
|
-
const
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
const
|
|
74
|
-
const key = curve.Point.Fp.toBytes(T.x);
|
|
75
|
-
const plaintext = new Uint8Array(2 * STRUCT_BYTES);
|
|
76
|
-
plaintext.set(struct);
|
|
77
|
-
const ciphertext = kw(new cipher(key)).wrap(plaintext);
|
|
75
|
+
encrypt: (plaintext, publicKey, rand) => {
|
|
76
|
+
const struct = buildStruct(plaintext);
|
|
77
|
+
const e = Fn.create(bytesToNumberBE(rand ?? randomBytes(STRUCT_BYTES)));
|
|
78
|
+
const r = Fp.toBytes(Point.BASE.multiply(e).x);
|
|
79
|
+
const key = Fp.toBytes(Point.fromBytes(publicKey).multiply(e).x);
|
|
80
|
+
const plaintext_kw = new Uint8Array(2 * STRUCT_BYTES);
|
|
81
|
+
plaintext_kw.set(struct);
|
|
82
|
+
const ciphertext = kw(new Сipher(key)).wrap(plaintext_kw);
|
|
78
83
|
return concatBytes(r, ciphertext);
|
|
79
84
|
},
|
|
80
85
|
decrypt: (ciphertext, privateKey) => {
|
|
81
86
|
if (ciphertext.length != length / 2)
|
|
82
87
|
throw new Error("Invalid ciphertext length");
|
|
83
88
|
const r = bytesToNumberBE(ciphertext.subarray(0, STRUCT_BYTES));
|
|
84
|
-
if (!
|
|
89
|
+
if (!Fp.isValidNot0(r))
|
|
85
90
|
throw new Error("Invalid ciphertext");
|
|
86
|
-
const
|
|
87
|
-
const
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
const plaintext = kw(new cipher(key)).unwrap(ciphertext.subarray(STRUCT_BYTES));
|
|
91
|
-
return parseStruct(plaintext);
|
|
91
|
+
const T = Point.fromX(r).multiply(bytesToNumberBE(privateKey));
|
|
92
|
+
const key = Fp.toBytes(T.x);
|
|
93
|
+
const plaintext = kw(new Сipher(key)).unwrap(ciphertext.subarray(STRUCT_BYTES));
|
|
94
|
+
return parseStruct(plaintext.subarray(0, STRUCT_BYTES));
|
|
92
95
|
}
|
|
93
96
|
});
|
|
94
97
|
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** S-Box #1 */
|
|
2
|
+
export declare const DKE_1: Uint8Array<ArrayBuffer>;
|
|
3
|
+
/** S-Box #2 */
|
|
4
|
+
export declare const DKE_2: Uint8Array<ArrayBuffer>;
|
|
5
|
+
/** S-Box #3 */
|
|
6
|
+
export declare const DKE_3: Uint8Array<ArrayBuffer>;
|
|
7
|
+
/** S-Box #4 */
|
|
8
|
+
export declare const DKE_4: Uint8Array<ArrayBuffer>;
|
|
9
|
+
/** S-Box #5 */
|
|
10
|
+
export declare const DKE_5: Uint8Array<ArrayBuffer>;
|
|
11
|
+
/** S-Box #6 */
|
|
12
|
+
export declare const DKE_6: Uint8Array<ArrayBuffer>;
|
|
13
|
+
/** S-Box #7 */
|
|
14
|
+
export declare const DKE_7: Uint8Array<ArrayBuffer>;
|
|
15
|
+
/** S-Box #8 */
|
|
16
|
+
export declare const DKE_8: Uint8Array<ArrayBuffer>;
|
|
17
|
+
/** S-Box #9 */
|
|
18
|
+
export declare const DKE_9: Uint8Array<ArrayBuffer>;
|
|
19
|
+
/** S-Box #10 */
|
|
20
|
+
export declare const DKE_10: Uint8Array<ArrayBuffer>;
|
|
21
|
+
/** Test S-Box for DSTU GOST 28147:2009 */
|
|
22
|
+
export declare const GOST_28147_89_TEST_PARAM_SET: Uint8Array<ArrayBuffer>;
|
|
23
|
+
/** Test S-Box #2 for DSTU GOST 28147:2009 */
|
|
24
|
+
export declare const GOSTR_3411_94_TEST_PARAM_SET: Uint8Array<ArrayBuffer>;
|
|
25
|
+
export declare const keySequences: {
|
|
26
|
+
ENCRYPT: number[];
|
|
27
|
+
DECRYPT: number[];
|
|
28
|
+
MAC: number[];
|
|
29
|
+
};
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/** S-Box #1 */
|
|
2
|
+
export const DKE_1 = new Uint8Array([
|
|
3
|
+
0xA9, 0xD6, 0xEB, 0x45, 0xF1, 0x3C, 0x70, 0x82,
|
|
4
|
+
0x80, 0xC4, 0x96, 0x7B, 0x23, 0x1F, 0x5E, 0xAD,
|
|
5
|
+
0xF6, 0x58, 0xEB, 0xA4, 0xC0, 0x37, 0x29, 0x1D,
|
|
6
|
+
0x38, 0xD9, 0x6B, 0xF0, 0x25, 0xCA, 0x4E, 0x17,
|
|
7
|
+
0xF8, 0xE9, 0x72, 0x0D, 0xC6, 0x15, 0xB4, 0x3A,
|
|
8
|
+
0x28, 0x97, 0x5F, 0x0B, 0xC1, 0xDE, 0xA3, 0x64,
|
|
9
|
+
0x38, 0xB5, 0x64, 0xEA, 0x2C, 0x17, 0x9F, 0xD0,
|
|
10
|
+
0x12, 0x3E, 0x6D, 0xB8, 0xFA, 0xC5, 0x79, 0x04
|
|
11
|
+
]);
|
|
12
|
+
/** S-Box #2 */
|
|
13
|
+
export const DKE_2 = new Uint8Array([
|
|
14
|
+
0xE9, 0x37, 0xF4, 0xCB, 0x6A, 0xD1, 0x05, 0x82,
|
|
15
|
+
0xAD, 0xC7, 0x6E, 0x81, 0xF3, 0xB4, 0x09, 0x52,
|
|
16
|
+
0x4B, 0x1F, 0x92, 0xEC, 0x6A, 0x87, 0x35, 0x0D,
|
|
17
|
+
0x45, 0x1C, 0x7E, 0x92, 0xAF, 0xBD, 0x08, 0x63,
|
|
18
|
+
0xCB, 0x39, 0xF0, 0x45, 0x72, 0xED, 0x1A, 0x86,
|
|
19
|
+
0x87, 0x3A, 0x96, 0xE5, 0xD0, 0x4C, 0x12, 0xFB,
|
|
20
|
+
0xF0, 0xE6, 0x8D, 0x59, 0xA3, 0x1C, 0x4B, 0x72,
|
|
21
|
+
0x43, 0xED, 0x50, 0x2B, 0x1A, 0x76, 0x9F, 0x8C
|
|
22
|
+
]);
|
|
23
|
+
/** S-Box #3 */
|
|
24
|
+
export const DKE_3 = new Uint8Array([
|
|
25
|
+
0xD9, 0x1E, 0x72, 0xC5, 0x4B, 0x6F, 0x38, 0xA0,
|
|
26
|
+
0x78, 0x6B, 0x03, 0x4D, 0x95, 0xFE, 0xAC, 0x21,
|
|
27
|
+
0xA5, 0x3C, 0x98, 0xD6, 0x4F, 0xE0, 0x2B, 0x17,
|
|
28
|
+
0xBA, 0xC1, 0x56, 0x9E, 0x2D, 0xF7, 0x04, 0x38,
|
|
29
|
+
0x5B, 0x30, 0xF9, 0xE4, 0x1C, 0x86, 0x2A, 0x7D,
|
|
30
|
+
0x43, 0xBD, 0x1F, 0x82, 0x7E, 0xC9, 0xA0, 0x65,
|
|
31
|
+
0x37, 0x8B, 0x1E, 0x50, 0xD4, 0xCA, 0x29, 0xF6,
|
|
32
|
+
0x6D, 0xCA, 0xB7, 0x93, 0xFE, 0x12, 0x08, 0x45
|
|
33
|
+
]);
|
|
34
|
+
/** S-Box #4 */
|
|
35
|
+
export const DKE_4 = new Uint8Array([
|
|
36
|
+
0x9C, 0x3D, 0x76, 0xE1, 0xA2, 0x04, 0x8F, 0x5B,
|
|
37
|
+
0xA5, 0xBE, 0x76, 0x0C, 0x28, 0xF4, 0xD3, 0x91,
|
|
38
|
+
0x4C, 0x30, 0xD2, 0xEB, 0x7F, 0x59, 0x18, 0xA6,
|
|
39
|
+
0x39, 0x45, 0xE7, 0x86, 0xD0, 0x2F, 0xBC, 0xA1,
|
|
40
|
+
0x29, 0xCF, 0xDB, 0x41, 0x75, 0x3E, 0x68, 0xA0,
|
|
41
|
+
0xE5, 0xDB, 0x19, 0x42, 0xF8, 0x70, 0x3C, 0xA6,
|
|
42
|
+
0xE6, 0x5A, 0x9D, 0x48, 0xBC, 0x03, 0x71, 0xF2,
|
|
43
|
+
0x19, 0xCB, 0x76, 0x83, 0x2F, 0xE0, 0x5A, 0x4D
|
|
44
|
+
]);
|
|
45
|
+
/** S-Box #5 */
|
|
46
|
+
export const DKE_5 = new Uint8Array([
|
|
47
|
+
0x34, 0xD8, 0xC7, 0xA2, 0x0E, 0x9F, 0xB1, 0x56,
|
|
48
|
+
0xC7, 0x69, 0x38, 0xB5, 0xFA, 0x0D, 0x42, 0x1E,
|
|
49
|
+
0xE4, 0x87, 0xB3, 0xAC, 0x12, 0x69, 0xDF, 0x05,
|
|
50
|
+
0x39, 0x6D, 0x8F, 0xA2, 0x7E, 0xC0, 0xB4, 0x15,
|
|
51
|
+
0x5C, 0xA7, 0x21, 0xFD, 0xE3, 0xB4, 0x08, 0x96,
|
|
52
|
+
0x18, 0xBE, 0x74, 0xA0, 0xC3, 0x5D, 0x9F, 0x62,
|
|
53
|
+
0x9B, 0xAD, 0x5E, 0x23, 0x06, 0x4C, 0xF1, 0x78,
|
|
54
|
+
0xE9, 0x18, 0x5F, 0xB0, 0x62, 0xC7, 0xA4, 0xD3
|
|
55
|
+
]);
|
|
56
|
+
/** S-Box #6 */
|
|
57
|
+
export const DKE_6 = new Uint8Array([
|
|
58
|
+
0xFC, 0x96, 0xE2, 0x1B, 0x0D, 0x4A, 0x78, 0x35,
|
|
59
|
+
0xEC, 0x50, 0x74, 0xA3, 0x26, 0x1D, 0x9B, 0xF8,
|
|
60
|
+
0x56, 0xD9, 0xBE, 0xA3, 0xF2, 0x81, 0x40, 0x7C,
|
|
61
|
+
0x1F, 0x74, 0x2E, 0xC3, 0x6B, 0x98, 0x05, 0xAD,
|
|
62
|
+
0xF9, 0xE6, 0xD1, 0x58, 0x42, 0x3C, 0xAB, 0x07,
|
|
63
|
+
0xB0, 0xD7, 0xCE, 0x14, 0x23, 0x68, 0xA5, 0xF9,
|
|
64
|
+
0x7E, 0xF8, 0xD0, 0xB3, 0xA1, 0x42, 0x9C, 0x65,
|
|
65
|
+
0x15, 0xEB, 0x2C, 0x38, 0xA0, 0x97, 0xF6, 0x4D
|
|
66
|
+
]);
|
|
67
|
+
/** S-Box #7 */
|
|
68
|
+
export const DKE_7 = new Uint8Array([
|
|
69
|
+
0xFD, 0xA5, 0xC0, 0x16, 0x92, 0xE7, 0x3B, 0x48,
|
|
70
|
+
0x25, 0xA0, 0x69, 0x1F, 0xD4, 0x7E, 0xB3, 0x8C,
|
|
71
|
+
0x3E, 0x4B, 0x59, 0x12, 0xF6, 0x8D, 0x70, 0xAC,
|
|
72
|
+
0x4A, 0xB9, 0xF2, 0xE5, 0xD1, 0x36, 0x07, 0xC8,
|
|
73
|
+
0xF6, 0x58, 0x97, 0xCB, 0x0A, 0x31, 0x24, 0xDE,
|
|
74
|
+
0xCB, 0xF4, 0x51, 0xE9, 0x08, 0xD2, 0xA7, 0x36,
|
|
75
|
+
0xD2, 0x48, 0xBC, 0x13, 0xA5, 0x9E, 0x7F, 0x06,
|
|
76
|
+
0x15, 0x0F, 0x6A, 0x3E, 0x72, 0xCD, 0xB8, 0x94
|
|
77
|
+
]);
|
|
78
|
+
/** S-Box #8 */
|
|
79
|
+
export const DKE_8 = new Uint8Array([
|
|
80
|
+
0xE4, 0xB2, 0x87, 0x5C, 0x9D, 0x03, 0x1F, 0x6A,
|
|
81
|
+
0x3E, 0xCA, 0x62, 0xD1, 0x98, 0x74, 0x0F, 0x5B,
|
|
82
|
+
0x52, 0x87, 0x1F, 0xE6, 0x4D, 0xB0, 0xA3, 0xC9,
|
|
83
|
+
0xCA, 0x7D, 0xE3, 0x02, 0x95, 0x16, 0xB4, 0xF8,
|
|
84
|
+
0x63, 0xF7, 0x09, 0xA8, 0xBC, 0x41, 0x52, 0xDE,
|
|
85
|
+
0x6D, 0xF1, 0x53, 0x80, 0xBA, 0xE4, 0x9C, 0x27,
|
|
86
|
+
0x2F, 0xC5, 0xB1, 0x3E, 0x06, 0xDA, 0x79, 0x48,
|
|
87
|
+
0x30, 0x5C, 0x8F, 0xDE, 0xB6, 0x29, 0x71, 0x4A
|
|
88
|
+
]);
|
|
89
|
+
/** S-Box #9 */
|
|
90
|
+
export const DKE_9 = new Uint8Array([
|
|
91
|
+
0x90, 0xBC, 0x24, 0x3F, 0xD6, 0xE1, 0xA7, 0x58,
|
|
92
|
+
0x35, 0x0F, 0x87, 0xEC, 0xDA, 0x16, 0xB2, 0x49,
|
|
93
|
+
0x84, 0x5A, 0xEB, 0xD6, 0xCF, 0x79, 0x31, 0x20,
|
|
94
|
+
0x54, 0xF0, 0xCB, 0xA9, 0x1E, 0x86, 0x32, 0xD7,
|
|
95
|
+
0x7C, 0x30, 0x68, 0xEB, 0x1F, 0xDA, 0x95, 0x24,
|
|
96
|
+
0x74, 0x3B, 0x6A, 0x81, 0x9C, 0xED, 0x0F, 0x25,
|
|
97
|
+
0x7E, 0x9F, 0x14, 0x83, 0xBD, 0x02, 0x6A, 0x5C,
|
|
98
|
+
0xE2, 0x8F, 0x30, 0x7C, 0xBD, 0x15, 0x64, 0x9A
|
|
99
|
+
]);
|
|
100
|
+
/** S-Box #10 */
|
|
101
|
+
export const DKE_10 = new Uint8Array([
|
|
102
|
+
0x84, 0x69, 0xBC, 0x12, 0x37, 0xE0, 0xDA, 0xF5,
|
|
103
|
+
0x7D, 0x18, 0xAE, 0x4F, 0x90, 0x63, 0x2C, 0xB5,
|
|
104
|
+
0xC8, 0xD1, 0xA2, 0x96, 0x34, 0xE7, 0x5F, 0x0B,
|
|
105
|
+
0x2B, 0x34, 0xC7, 0x9D, 0xF8, 0x50, 0x1E, 0xA6,
|
|
106
|
+
0x83, 0xDA, 0xEF, 0x51, 0x47, 0xBC, 0x20, 0x69,
|
|
107
|
+
0x4C, 0x9B, 0xEA, 0x76, 0x35, 0x0F, 0x12, 0x8D,
|
|
108
|
+
0x58, 0xE7, 0x30, 0x1D, 0xA6, 0x92, 0xFB, 0xC4,
|
|
109
|
+
0xA3, 0x59, 0x0D, 0x78, 0xC4, 0x16, 0xBF, 0x2E
|
|
110
|
+
]);
|
|
111
|
+
/** Test S-Box for DSTU GOST 28147:2009 */
|
|
112
|
+
export const GOST_28147_89_TEST_PARAM_SET = new Uint8Array([
|
|
113
|
+
0x42, 0xF5, 0x91, 0x08, 0xE3, 0xBC, 0xD7, 0xA6,
|
|
114
|
+
0xC9, 0xFE, 0x81, 0x3A, 0x27, 0x4D, 0x60, 0xB5,
|
|
115
|
+
0xD8, 0xEC, 0x73, 0x9A, 0x15, 0x24, 0x6F, 0x0B,
|
|
116
|
+
0xE9, 0xB2, 0x5F, 0x71, 0x0D, 0xC6, 0xA4, 0x38,
|
|
117
|
+
0x3E, 0x59, 0x68, 0x0D, 0xAB, 0x7C, 0x21, 0xF4,
|
|
118
|
+
0x8F, 0x6B, 0x19, 0xC5, 0xD3, 0x7A, 0x0E, 0x24,
|
|
119
|
+
0x9B, 0xC0, 0x36, 0x75, 0x48, 0xEF, 0x1A, 0x2D,
|
|
120
|
+
0xC6, 0x52, 0xB0, 0x9D, 0x3E, 0x7A, 0xF4, 0x18
|
|
121
|
+
]);
|
|
122
|
+
/** Test S-Box #2 for DSTU GOST 28147:2009 */
|
|
123
|
+
export const GOSTR_3411_94_TEST_PARAM_SET = new Uint8Array([
|
|
124
|
+
0x4A, 0x92, 0xD8, 0x0E, 0x6B, 0x1C, 0x7F, 0x53,
|
|
125
|
+
0xEB, 0x4C, 0x6D, 0xFA, 0x23, 0x81, 0x07, 0x59,
|
|
126
|
+
0x58, 0x1D, 0xA3, 0x42, 0xEF, 0xC7, 0x60, 0x9B,
|
|
127
|
+
0x7D, 0xA1, 0x08, 0x9F, 0xE4, 0x6C, 0xB2, 0x53,
|
|
128
|
+
0x6C, 0x71, 0x5F, 0xD8, 0x4A, 0x9E, 0x03, 0xB2,
|
|
129
|
+
0x4B, 0xA0, 0x72, 0x1D, 0x36, 0x85, 0x9C, 0xFE,
|
|
130
|
+
0xDB, 0x41, 0x3F, 0x59, 0x0A, 0xE7, 0x68, 0x2C,
|
|
131
|
+
0x1F, 0xD0, 0x57, 0xA4, 0x92, 0x3E, 0x6B, 0x8C
|
|
132
|
+
]);
|
|
133
|
+
export const keySequences = {
|
|
134
|
+
ENCRYPT: [
|
|
135
|
+
0, 1, 2, 3, 4, 5, 6, 7,
|
|
136
|
+
0, 1, 2, 3, 4, 5, 6, 7,
|
|
137
|
+
0, 1, 2, 3, 4, 5, 6, 7,
|
|
138
|
+
7, 6, 5, 4, 3, 2, 1, 0
|
|
139
|
+
],
|
|
140
|
+
DECRYPT: [
|
|
141
|
+
0, 1, 2, 3, 4, 5, 6, 7,
|
|
142
|
+
7, 6, 5, 4, 3, 2, 1, 0,
|
|
143
|
+
7, 6, 5, 4, 3, 2, 1, 0,
|
|
144
|
+
7, 6, 5, 4, 3, 2, 1, 0
|
|
145
|
+
],
|
|
146
|
+
MAC: [
|
|
147
|
+
0, 1, 2, 3, 4, 5, 6, 7,
|
|
148
|
+
0, 1, 2, 3, 4, 5, 6, 7
|
|
149
|
+
]
|
|
150
|
+
};
|