@li0ard/dstu 0.2.0 → 0.2.1
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/const.d.ts +5 -14
- package/const.js +47 -1010
- package/dstu4145/const.js +15 -15
- package/dstu4145/ec/index.js +9 -27
- package/dstu4145/ecies.d.ts +2 -2
- package/dstu4145/ecies.js +2 -1
- package/dstu4145/gf2m/utils.js +1 -1
- package/dstu4145/index.js +12 -12
- package/dstu9041/curve.d.ts +1 -1
- package/dstu9041/curve.js +14 -27
- package/dstu9041/index.js +12 -20
- package/dstu9311/const.js +12 -12
- package/dstu9311/index.d.ts +1 -2
- package/dstu9311/index.js +34 -30
- package/gf/index.d.ts +5 -0
- package/gf/index.js +62 -0
- package/gost34311/index.d.ts +55 -0
- package/gost34311/index.js +167 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/iso15946.js +4 -6
- package/kalyna/index.d.ts +2 -4
- package/kalyna/index.js +113 -92
- package/keywrap.js +5 -10
- package/kupyna/index.d.ts +21 -103
- package/kupyna/index.js +104 -153
- package/modes/_guard.d.ts +4 -0
- package/modes/_guard.js +6 -0
- package/modes/cbc.js +2 -1
- package/modes/ccm.js +1 -1
- package/modes/cfb.js +2 -1
- package/modes/cmac.js +2 -1
- package/modes/ctr.js +2 -1
- package/modes/gcm.js +2 -1
- package/modes/gmac.js +4 -8
- package/modes/kw.js +1 -1
- package/modes/ofb.js +2 -1
- package/modes/xts.js +11 -25
- package/package.json +12 -9
- package/padding.d.ts +1 -1
- package/padding.js +0 -5
- package/strumok/index.d.ts +3 -4
- package/strumok/index.js +128 -85
- package/utils.d.ts +6 -13
- package/utils.js +27 -70
- package/dstu9311/hash.d.ts +0 -75
- package/dstu9311/hash.js +0 -159
- package/kupyna/kmac.d.ts +0 -46
- package/kupyna/kmac.js +0 -130
package/kalyna/index.js
CHANGED
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
import { abool, abytes, anumber } from "@noble/hashes/utils.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
const swap_block = (k,
|
|
5
|
-
if (
|
|
2
|
+
import { T, S, MDS_MATRIX_inv, genTable } from "../const.js";
|
|
3
|
+
import { _U32, u32ToBytesLE, bytesToU32LE } from "../utils.js";
|
|
4
|
+
const swap_block = (k, words) => {
|
|
5
|
+
if (words <= 1)
|
|
6
6
|
return;
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
k[
|
|
7
|
+
const l = k[0], h = k[1];
|
|
8
|
+
k.copyWithin(0, 2, words * 2);
|
|
9
|
+
k[words * 2 - 2] = l;
|
|
10
|
+
k[words * 2 - 1] = h;
|
|
11
11
|
};
|
|
12
|
-
export const column = (x, i, N,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
table[
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
export const column = (x, i, N, offs, out, o, table = T, sign = -1) => {
|
|
13
|
+
const m = N - 1;
|
|
14
|
+
const j0 = ((i + sign * offs[0]) & m) << 1, j1 = ((i + sign * offs[1]) & m) << 1, j2 = ((i + sign * offs[2]) & m) << 1, j3 = ((i + sign * offs[3]) & m) << 1, j4 = (((i + sign * offs[4]) & m) << 1) | 1, j5 = (((i + sign * offs[5]) & m) << 1) | 1, j6 = (((i + sign * offs[6]) & m) << 1) | 1, j7 = (((i + sign * offs[7]) & m) << 1) | 1;
|
|
15
|
+
const b0 = (x[j0] & 0xFF) << 1, b1 = ((x[j1] >>> 8) & 0xFF) << 1, b2 = ((x[j2] >>> 16) & 0xFF) << 1, b3 = (x[j3] >>> 24) << 1, b4 = (x[j4] & 0xFF) << 1, b5 = ((x[j5] >>> 8) & 0xFF) << 1, b6 = ((x[j6] >>> 16) & 0xFF) << 1, b7 = (x[j7] >>> 24) << 1;
|
|
16
|
+
const t0 = table[0], t1 = table[1], t2 = table[2], t3 = table[3], t4 = table[4], t5 = table[5], t6 = table[6], t7 = table[7];
|
|
17
|
+
out[o] = t0[b0] ^ t1[b1] ^ t2[b2] ^ t3[b3] ^ t4[b4] ^ t5[b5] ^ t6[b6] ^ t7[b7];
|
|
18
|
+
out[o + 1] = t0[b0 | 1] ^ t1[b1 | 1] ^ t2[b2 | 1] ^ t3[b3 | 1] ^
|
|
19
|
+
t4[b4 | 1] ^ t5[b5 | 1] ^ t6[b6 | 1] ^ t7[b7 | 1];
|
|
20
|
+
};
|
|
21
|
+
const IS = /* @__PURE__ */ S.map(i => i.map((_, j) => i.indexOf(j))), IT = /* @__PURE__ */ genTable(MDS_MATRIX_inv, IS);
|
|
20
22
|
export class Kalyna {
|
|
21
23
|
N;
|
|
22
24
|
/** Block size */
|
|
@@ -47,140 +49,159 @@ export class Kalyna {
|
|
|
47
49
|
this.expandKey(key);
|
|
48
50
|
}
|
|
49
51
|
expandKey(key) {
|
|
50
|
-
const log2N = Math.log2(this.N), isDoubleKey = (this.keySize === this.blockSize * 2), R = isDoubleKey ? (6 + 2 * log2N) : (4 + 2 * log2N), rk = new
|
|
51
|
-
t1[0] = isDoubleKey ?
|
|
52
|
-
const keys =
|
|
53
|
-
|
|
54
|
-
const _0 = new BigUint64Array(this.N);
|
|
52
|
+
const N2 = this.N * 2, log2N = Math.log2(this.N), isDoubleKey = (this.keySize === this.blockSize * 2), R = isDoubleKey ? (6 + 2 * log2N) : (4 + 2 * log2N), rk = new Uint32Array(R * this.N * 4), ks = new Uint32Array(N2), ksc = new Uint32Array(N2), t1 = new Uint32Array(N2), t2 = new Uint32Array(N2);
|
|
53
|
+
t1[0] = isDoubleKey ? (N2 + 2 * log2N + 1) : (N2 + 1);
|
|
54
|
+
const keys = bytesToU32LE(key), _0 = new Uint32Array(N2);
|
|
55
|
+
const k = new Uint32Array(isDoubleKey ? N2 * 2 : N2);
|
|
55
56
|
if (isDoubleKey) {
|
|
56
|
-
const ka = keys.subarray(0,
|
|
57
|
+
const ka = keys.subarray(0, N2);
|
|
57
58
|
this.addkey(t1, t2, ka);
|
|
58
|
-
this.G(t2, t1, keys.subarray(
|
|
59
|
+
this.G(t2, t1, keys.subarray(N2));
|
|
59
60
|
this.GL(t1, t2, ka);
|
|
60
61
|
this.G(t2, ks, _0);
|
|
61
62
|
k.set(keys);
|
|
62
63
|
}
|
|
63
64
|
else {
|
|
64
|
-
k.set(keys.subarray(0,
|
|
65
|
+
k.set(keys.subarray(0, N2));
|
|
65
66
|
this.addkey(t1, t2, keys);
|
|
66
67
|
this.G(t2, t1, keys);
|
|
67
68
|
this.GL(t1, t2, keys);
|
|
68
69
|
this.G(t2, ks, _0);
|
|
69
70
|
}
|
|
70
|
-
let
|
|
71
|
+
let cl = 0x00010001, ch = 0x00010001;
|
|
71
72
|
for (let i = 0; i < R; i++) {
|
|
72
|
-
const offset = i *
|
|
73
|
+
const offset = i * N2;
|
|
73
74
|
if (i > 0) {
|
|
74
75
|
if (!isDoubleKey)
|
|
75
76
|
swap_block(k, this.N);
|
|
76
77
|
else if (i % 2 === 0)
|
|
77
|
-
swap_block(k,
|
|
78
|
+
swap_block(k, N2);
|
|
78
79
|
}
|
|
79
80
|
const keySource = isDoubleKey
|
|
80
|
-
? (i % 2 === 0 ? k.subarray(0,
|
|
81
|
+
? (i % 2 === 0 ? k.subarray(0, N2) : k.subarray(N2))
|
|
81
82
|
: k;
|
|
82
|
-
for (let
|
|
83
|
-
|
|
83
|
+
for (let j = 0; j < N2; j += 2) {
|
|
84
|
+
const lo = ks[j] + cl;
|
|
85
|
+
ksc[j] = lo;
|
|
86
|
+
ksc[j + 1] = ks[j + 1] + ch + (lo > _U32 ? 1 : 0);
|
|
87
|
+
}
|
|
84
88
|
this.addkey(keySource, t2, ksc);
|
|
85
89
|
this.G(t2, t1, ksc);
|
|
86
|
-
this.GL(t1, rk.subarray(offset), ksc);
|
|
90
|
+
this.GL(t1, rk.subarray(offset * 2), ksc);
|
|
87
91
|
if (i < R - 1)
|
|
88
|
-
this.makeOddKey(rk.subarray(offset), rk.subarray(offset + this.N));
|
|
89
|
-
|
|
92
|
+
this.makeOddKey(rk.subarray(offset * 2), rk.subarray((offset + this.N) * 2));
|
|
93
|
+
ch = ((ch << 1) | (cl >>> 31)) >>> 0;
|
|
94
|
+
cl = (cl << 1) >>> 0;
|
|
90
95
|
}
|
|
91
96
|
this.erk = rk.slice();
|
|
92
97
|
for (let i = ((R * 2 - 3) * this.N); i > 0; i -= this.N)
|
|
93
|
-
this.IMC(rk.subarray(i));
|
|
98
|
+
this.IMC(rk.subarray(i * 2));
|
|
94
99
|
this.drk = rk;
|
|
95
100
|
}
|
|
96
101
|
makeOddKey(evenkey, oddkey) {
|
|
97
|
-
const offset = 2 * this.N + 3;
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
oddkeys.set(evenkeys.subarray(0, offset), this.blockSize - offset);
|
|
102
|
-
oddkey.set(bytesToUint64sLE(oddkeys));
|
|
102
|
+
const offset = 2 * this.N + 3, ev = u32ToBytesLE(evenkey.subarray(0, this.N * 2)), od = new Uint8Array(this.blockSize);
|
|
103
|
+
od.set(ev.subarray(offset, this.blockSize));
|
|
104
|
+
od.set(ev.subarray(0, offset), this.blockSize - offset);
|
|
105
|
+
oddkey.set(bytesToU32LE(od));
|
|
103
106
|
}
|
|
104
|
-
addkey(x, y, k) {
|
|
105
|
-
for (let
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
y[i] = x[i] - k[i];
|
|
107
|
+
addkey(x, y, k, ko = 0) {
|
|
108
|
+
for (let j = 0, e = this.N * 2; j < e; j += 2) {
|
|
109
|
+
const lo = x[j] + k[ko + j];
|
|
110
|
+
y[j + 1] = x[j + 1] + k[ko + j + 1] + (lo > _U32 ? 1 : 0);
|
|
111
|
+
y[j] = lo;
|
|
112
|
+
}
|
|
111
113
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
+
subkey(x, y, k, ko = 0) {
|
|
115
|
+
for (let j = 0, e = this.N * 2; j < e; j += 2) {
|
|
116
|
+
const lo = x[j] - k[ko + j];
|
|
117
|
+
y[j + 1] = x[j + 1] - k[ko + j + 1] - (lo < 0 ? 1 : 0);
|
|
118
|
+
y[j] = lo;
|
|
119
|
+
}
|
|
114
120
|
}
|
|
115
|
-
|
|
116
|
-
|
|
121
|
+
G(x, y, k, ko = 0) {
|
|
122
|
+
for (let i = 0; i < this.N; i++) {
|
|
123
|
+
const j = i << 1;
|
|
124
|
+
column(x, i, this.N, this.wordOffsets, y, j);
|
|
125
|
+
y[j] ^= k[ko + j];
|
|
126
|
+
y[j + 1] ^= k[ko + j + 1];
|
|
127
|
+
}
|
|
117
128
|
}
|
|
118
|
-
|
|
119
|
-
for (let i = 0; i < this.N; i++)
|
|
120
|
-
|
|
129
|
+
GL(x, y, k, ko = 0) {
|
|
130
|
+
for (let i = 0; i < this.N; i++) {
|
|
131
|
+
const j = i << 1;
|
|
132
|
+
column(x, i, this.N, this.wordOffsets, y, j);
|
|
133
|
+
const lo = y[j] + k[ko + j];
|
|
134
|
+
y[j + 1] += k[ko + j + 1] + (lo > _U32 ? 1 : 0);
|
|
135
|
+
y[j] = lo;
|
|
136
|
+
}
|
|
121
137
|
}
|
|
122
|
-
|
|
123
|
-
for (let i = 0; i < this.N; i++)
|
|
124
|
-
|
|
138
|
+
IG(x, y, k, ko = 0) {
|
|
139
|
+
for (let i = 0; i < this.N; i++) {
|
|
140
|
+
const j = i << 1;
|
|
141
|
+
column(x, i, this.N, this.wordOffsets, y, j, IT, 1);
|
|
142
|
+
y[j] ^= k[ko + j];
|
|
143
|
+
y[j + 1] ^= k[ko + j + 1];
|
|
144
|
+
}
|
|
125
145
|
}
|
|
126
146
|
IMC(x) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}
|
|
137
|
-
IG(x, y, k) {
|
|
138
|
-
for (let i = 0; i < this.N; i++)
|
|
139
|
-
y[i] = k[i] ^ this.invColumn(x, i);
|
|
147
|
+
const [s0, s1, s2, s3] = S;
|
|
148
|
+
const [i0, i1, i2, i3, i4, i5, i6, i7] = IT;
|
|
149
|
+
for (let j = 0, e = this.N * 2; j < e; j += 2) {
|
|
150
|
+
const l = x[j], h = x[j + 1];
|
|
151
|
+
const a0 = s0[l & 0xFF] << 1, a1 = s1[(l >>> 8) & 0xFF] << 1, a2 = s2[(l >>> 16) & 0xFF] << 1, a3 = s3[l >>> 24] << 1, a4 = s0[h & 0xFF] << 1, a5 = s1[(h >>> 8) & 0xFF] << 1, a6 = s2[(h >>> 16) & 0xFF] << 1, a7 = s3[h >>> 24] << 1;
|
|
152
|
+
x[j] = i0[a0] ^ i1[a1] ^ i2[a2] ^ i3[a3] ^ i4[a4] ^ i5[a5] ^ i6[a6] ^ i7[a7];
|
|
153
|
+
x[j + 1] = i0[a0 | 1] ^ i1[a1 | 1] ^ i2[a2 | 1] ^ i3[a3 | 1] ^
|
|
154
|
+
i4[a4 | 1] ^ i5[a5 | 1] ^ i6[a6 | 1] ^ i7[a7 | 1];
|
|
155
|
+
}
|
|
140
156
|
}
|
|
141
157
|
IGL(x, y) {
|
|
158
|
+
const m = this.N - 1;
|
|
159
|
+
const [is0, is1, is2, is3] = IS;
|
|
142
160
|
for (let i = 0; i < this.N; i++) {
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
(
|
|
146
|
-
(
|
|
147
|
-
(
|
|
148
|
-
|
|
149
|
-
(
|
|
150
|
-
(
|
|
151
|
-
|
|
161
|
+
const j0 = ((i + this.wordOffsets[0]) & m) << 1, j1 = ((i + this.wordOffsets[1]) & m) << 1, j2 = ((i + this.wordOffsets[2]) & m) << 1, j3 = ((i + this.wordOffsets[3]) & m) << 1, j4 = (((i + this.wordOffsets[4]) & m) << 1) | 1, j5 = (((i + this.wordOffsets[5]) & m) << 1) | 1, j6 = (((i + this.wordOffsets[6]) & m) << 1) | 1, j7 = (((i + this.wordOffsets[7]) & m) << 1) | 1;
|
|
162
|
+
const lo = is0[x[j0] & 0xFF] |
|
|
163
|
+
(is1[(x[j1] >>> 8) & 0xFF] << 8) |
|
|
164
|
+
(is2[(x[j2] >>> 16) & 0xFF] << 16) |
|
|
165
|
+
(is3[x[j3] >>> 24] << 24);
|
|
166
|
+
const hi = is0[x[j4] & 0xFF] |
|
|
167
|
+
(is1[(x[j5] >>> 8) & 0xFF] << 8) |
|
|
168
|
+
(is2[(x[j6] >>> 16) & 0xFF] << 16) |
|
|
169
|
+
(is3[x[j7] >>> 24] << 24);
|
|
170
|
+
const d = i << 1, l = (lo >>> 0) - this.drk[d];
|
|
171
|
+
y[d + 1] = (hi >>> 0) - this.drk[d + 1] - (l < 0 ? 1 : 0);
|
|
172
|
+
y[d] = l;
|
|
152
173
|
}
|
|
153
174
|
}
|
|
154
175
|
/** Encrypt block */
|
|
155
176
|
encrypt(block) {
|
|
156
177
|
abytes(block, this.blockSize, "block");
|
|
157
|
-
const t1 = new
|
|
158
|
-
this.addkey(
|
|
178
|
+
const t1 = new Uint32Array(this.N * 2), t2 = new Uint32Array(this.N * 2);
|
|
179
|
+
this.addkey(bytesToU32LE(block), t1, this.erk);
|
|
159
180
|
for (let i = 0; i < this.numRounds; i++) {
|
|
160
|
-
const
|
|
181
|
+
const ko = (this.N + i * this.N) * 2;
|
|
161
182
|
if (i % 2 === 0)
|
|
162
|
-
this.G(t1, t2,
|
|
183
|
+
this.G(t1, t2, this.erk, ko);
|
|
163
184
|
else
|
|
164
|
-
this.G(t2, t1,
|
|
185
|
+
this.G(t2, t1, this.erk, ko);
|
|
165
186
|
}
|
|
166
|
-
this.GL(t2, t1, this.erk
|
|
167
|
-
return
|
|
187
|
+
this.GL(t2, t1, this.erk, this.glOffset * 2);
|
|
188
|
+
return u32ToBytesLE(t1);
|
|
168
189
|
}
|
|
169
190
|
/** Decrypt block */
|
|
170
191
|
decrypt(block) {
|
|
171
192
|
abytes(block, this.blockSize, "block");
|
|
172
|
-
const t1 = new
|
|
173
|
-
this.subkey(
|
|
193
|
+
const t1 = new Uint32Array(this.N * 2), t2 = new Uint32Array(this.N * 2);
|
|
194
|
+
this.subkey(bytesToU32LE(block), t1, this.drk, this.glOffset * 2);
|
|
174
195
|
this.IMC(t1);
|
|
175
196
|
for (let i = 0; i < this.numRounds; i++) {
|
|
176
|
-
const
|
|
197
|
+
const ko = (this.glOffset - this.N - i * this.N) * 2;
|
|
177
198
|
if (i % 2 === 0)
|
|
178
|
-
this.IG(t1, t2,
|
|
199
|
+
this.IG(t1, t2, this.drk, ko);
|
|
179
200
|
else
|
|
180
|
-
this.IG(t2, t1,
|
|
201
|
+
this.IG(t2, t1, this.drk, ko);
|
|
181
202
|
}
|
|
182
203
|
this.IGL(t2, t1);
|
|
183
|
-
return
|
|
204
|
+
return u32ToBytesLE(t1);
|
|
184
205
|
}
|
|
185
206
|
}
|
|
186
207
|
/** Kalyna 128/128 bit version */
|
package/keywrap.js
CHANGED
|
@@ -2,11 +2,11 @@ import { equalBytes, concatBytes, randomBytes, abytes, abool } from "@noble/curv
|
|
|
2
2
|
import { Kalyna256 } from "./kalyna/index.js";
|
|
3
3
|
import { cfb, cmac } from "./modes/index.js";
|
|
4
4
|
import { Dstu9311 } from "./dstu9311/index.js";
|
|
5
|
-
const IV1_KALYNA = new Uint8Array([
|
|
5
|
+
const IV1_KALYNA = /* @__PURE__ */ new Uint8Array([
|
|
6
6
|
0x69, 0x73, 0x27, 0x1D, 0x6E, 0x61, 0x1D, 0x06, 0x61, 0x67, 0x15, 0x04, 0x6C, 0x65, 0x50, 0x4C,
|
|
7
7
|
0x20, 0x20, 0x00, 0x4F, 0x6D, 0x68, 0x01, 0x1F, 0x65, 0x61, 0x0C, 0x0C, 0x73, 0x73, 0x47, 0x14
|
|
8
8
|
]);
|
|
9
|
-
const IV1_9311 = new Uint8Array([
|
|
9
|
+
const IV1_9311 = /* @__PURE__ */ new Uint8Array([
|
|
10
10
|
0x4a, 0xdd, 0xa2, 0x2c, 0x79, 0xe8, 0x21, 0x05
|
|
11
11
|
]);
|
|
12
12
|
/** Key wrap (`Dstu7624Wrap`/`GOST28147Wrap`) */
|
|
@@ -17,8 +17,7 @@ export const keyWrap = (kek, useDstu9311 = false) => {
|
|
|
17
17
|
abool(useDstu9311, "useDstu9311");
|
|
18
18
|
const cipher = new (useDstu9311 ? Dstu9311 : Kalyna256)(kek);
|
|
19
19
|
const ivLength = useDstu9311 ? 8 : 32, macLength = useDstu9311 ? 4 : 32;
|
|
20
|
-
const macMode = cmac(cipher, macLength);
|
|
21
|
-
const finalMode = cfb(cipher, useDstu9311 ? IV1_9311 : IV1_KALYNA, 32);
|
|
20
|
+
const macMode = cmac(cipher, macLength), finalMode = cfb(cipher, useDstu9311 ? IV1_9311 : IV1_KALYNA, 32);
|
|
22
21
|
return Object.freeze({
|
|
23
22
|
wrap: (key, iv) => {
|
|
24
23
|
abytes(key, undefined, "key");
|
|
@@ -29,12 +28,8 @@ export const keyWrap = (kek, useDstu9311 = false) => {
|
|
|
29
28
|
},
|
|
30
29
|
unwrap: (wrappedKey) => {
|
|
31
30
|
abytes(wrappedKey, undefined, "wrappedKey");
|
|
32
|
-
const dec_wrapped = finalMode.decrypt(wrappedKey).reverse();
|
|
33
|
-
|
|
34
|
-
const key_mac = cfb(cipher, iv, 32).decrypt(dec_wrapped.subarray(ivLength));
|
|
35
|
-
const key = key_mac.slice(0, -macLength), mac = key_mac.subarray(-macLength);
|
|
36
|
-
const actualMac = macMode.compute(key);
|
|
37
|
-
if (!equalBytes(actualMac, mac))
|
|
31
|
+
const dec_wrapped = finalMode.decrypt(wrappedKey).reverse(), iv = dec_wrapped.subarray(0, ivLength), key_mac = cfb(cipher, iv, 32).decrypt(dec_wrapped.subarray(ivLength)), key = key_mac.slice(0, -macLength);
|
|
32
|
+
if (!equalBytes(macMode.compute(key), key_mac.subarray(-macLength)))
|
|
38
33
|
throw new Error("Invalid MAC");
|
|
39
34
|
return key;
|
|
40
35
|
}
|
package/kupyna/index.d.ts
CHANGED
|
@@ -1,28 +1,26 @@
|
|
|
1
1
|
import { type CHash, type Hash, type TArg, type TRet } from "@noble/hashes/utils.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
readonly outputLen: number;
|
|
5
|
-
readonly canXOF = false;
|
|
2
|
+
import { HashMD } from "@noble/hashes/_md.js";
|
|
3
|
+
declare abstract class Kupyna<T extends Kupyna<T>> extends HashMD<T> {
|
|
6
4
|
private readonly rounds;
|
|
7
5
|
private readonly stSize;
|
|
8
|
-
private readonly
|
|
9
|
-
protected s:
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
private readonly offs;
|
|
7
|
+
protected s: Uint32Array;
|
|
8
|
+
private readonly m;
|
|
9
|
+
private readonly ap;
|
|
10
|
+
private readonly aq;
|
|
11
|
+
private readonly tmp;
|
|
13
12
|
constructor(blockLen: number);
|
|
13
|
+
protected get(): number[];
|
|
14
|
+
protected set(..._args: number[]): void;
|
|
15
|
+
protected process(buf: DataView, offset?: number): void;
|
|
16
|
+
protected roundClean(): void;
|
|
14
17
|
destroy(): void;
|
|
15
|
-
|
|
16
|
-
digest(): TRet<Uint8Array>;
|
|
17
|
-
digestInto(buffer: TArg<Uint8Array>): void;
|
|
18
|
-
private column;
|
|
18
|
+
digestInto(out: TArg<Uint8Array>): void;
|
|
19
19
|
private G;
|
|
20
20
|
private P;
|
|
21
21
|
private Q;
|
|
22
22
|
private outputTransform;
|
|
23
|
-
|
|
24
|
-
clone(): Kupyna<T>;
|
|
25
|
-
abstract _cloneInto(to?: Kupyna<T>): Kupyna<T>;
|
|
23
|
+
_cloneInto(to?: T): T;
|
|
26
24
|
}
|
|
27
25
|
declare abstract class KupynaDerived<T extends Kupyna<T>> implements Hash<KupynaDerived<T>> {
|
|
28
26
|
private readonly slice;
|
|
@@ -32,7 +30,7 @@ declare abstract class KupynaDerived<T extends Kupyna<T>> implements Hash<Kupyna
|
|
|
32
30
|
protected h: Hash<T>;
|
|
33
31
|
constructor(hash: CHash, slice: number);
|
|
34
32
|
destroy(): void;
|
|
35
|
-
|
|
33
|
+
_cloneInto(to?: KupynaDerived<T>): KupynaDerived<T>;
|
|
36
34
|
clone(): KupynaDerived<T>;
|
|
37
35
|
update(data: TArg<Uint8Array>): this;
|
|
38
36
|
digest(): TRet<Uint8Array>;
|
|
@@ -41,16 +39,10 @@ declare abstract class KupynaDerived<T extends Kupyna<T>> implements Hash<Kupyna
|
|
|
41
39
|
/** Internal Kupyna-256 hash class */
|
|
42
40
|
export declare class _Kupyna256 extends Kupyna<_Kupyna256> {
|
|
43
41
|
constructor();
|
|
44
|
-
_cloneInto(to?: _Kupyna256): _Kupyna256;
|
|
45
|
-
/** Create hash instance */
|
|
46
|
-
static create(): _Kupyna256;
|
|
47
42
|
}
|
|
48
43
|
/** Internal Kupyna-512 hash class */
|
|
49
44
|
export declare class _Kupyna512 extends Kupyna<_Kupyna512> {
|
|
50
45
|
constructor();
|
|
51
|
-
_cloneInto(to?: _Kupyna512): _Kupyna512;
|
|
52
|
-
/** Create hash instance */
|
|
53
|
-
static create(): _Kupyna512;
|
|
54
46
|
}
|
|
55
47
|
/**
|
|
56
48
|
* Kupyna-256 hash function
|
|
@@ -65,20 +57,7 @@ export declare class _Kupyna512 extends Kupyna<_Kupyna512> {
|
|
|
65
57
|
* kupyna256.create().update(new Uint8Array([97, 98, 99])).digest();
|
|
66
58
|
* ```
|
|
67
59
|
*/
|
|
68
|
-
export declare const kupyna256:
|
|
69
|
-
outputLen: number;
|
|
70
|
-
blockLen: number;
|
|
71
|
-
canXOF: boolean;
|
|
72
|
-
} & import("@noble/hashes/utils.js").HashInfo & {
|
|
73
|
-
(msg: TArg<Uint8Array>): TRet<Uint8Array>;
|
|
74
|
-
create(): _Kupyna256;
|
|
75
|
-
} & ((msg: TArg<TArg<Uint8Array<ArrayBufferLike>>>) => Uint8Array<ArrayBufferLike> & Uint8Array<ArrayBuffer>) & {
|
|
76
|
-
outputLen: number;
|
|
77
|
-
blockLen: number;
|
|
78
|
-
canXOF: boolean;
|
|
79
|
-
oid?: TRet<Uint8Array> | undefined;
|
|
80
|
-
create: () => _Kupyna256;
|
|
81
|
-
};
|
|
60
|
+
export declare const kupyna256: TRet<CHash<_Kupyna256>>;
|
|
82
61
|
/**
|
|
83
62
|
* Kupyna-512 hash function
|
|
84
63
|
*
|
|
@@ -92,40 +71,18 @@ export declare const kupyna256: {
|
|
|
92
71
|
* kupyna512.create().update(new Uint8Array([97, 98, 99])).digest();
|
|
93
72
|
* ```
|
|
94
73
|
*/
|
|
95
|
-
export declare const kupyna512:
|
|
96
|
-
outputLen: number;
|
|
97
|
-
blockLen: number;
|
|
98
|
-
canXOF: boolean;
|
|
99
|
-
} & import("@noble/hashes/utils.js").HashInfo & {
|
|
100
|
-
(msg: TArg<Uint8Array>): TRet<Uint8Array>;
|
|
101
|
-
create(): _Kupyna512;
|
|
102
|
-
} & ((msg: TArg<TArg<Uint8Array<ArrayBufferLike>>>) => Uint8Array<ArrayBufferLike> & Uint8Array<ArrayBuffer>) & {
|
|
103
|
-
outputLen: number;
|
|
104
|
-
blockLen: number;
|
|
105
|
-
canXOF: boolean;
|
|
106
|
-
oid?: TRet<Uint8Array> | undefined;
|
|
107
|
-
create: () => _Kupyna512;
|
|
108
|
-
};
|
|
74
|
+
export declare const kupyna512: TRet<CHash<_Kupyna512>>;
|
|
109
75
|
/** Internal Kupyna-48 hash class */
|
|
110
76
|
export declare class _Kupyna48 extends KupynaDerived<_Kupyna256> {
|
|
111
77
|
constructor();
|
|
112
|
-
_cloneInto(to?: _Kupyna48): _Kupyna48;
|
|
113
|
-
/** Create hash instance */
|
|
114
|
-
static create(): _Kupyna48;
|
|
115
78
|
}
|
|
116
79
|
/** Internal Kupyna-304 hash class */
|
|
117
80
|
export declare class _Kupyna304 extends KupynaDerived<_Kupyna512> {
|
|
118
81
|
constructor();
|
|
119
|
-
_cloneInto(to?: _Kupyna304): _Kupyna304;
|
|
120
|
-
/** Create hash instance */
|
|
121
|
-
static create(): _Kupyna304;
|
|
122
82
|
}
|
|
123
83
|
/** Internal Kupyna-384 hash class */
|
|
124
84
|
export declare class _Kupyna384 extends KupynaDerived<_Kupyna512> {
|
|
125
85
|
constructor();
|
|
126
|
-
_cloneInto(to?: _Kupyna384): _Kupyna384;
|
|
127
|
-
/** Create hash instance */
|
|
128
|
-
static create(): _Kupyna384;
|
|
129
86
|
}
|
|
130
87
|
/**
|
|
131
88
|
* Kupyna-48 hash function
|
|
@@ -140,20 +97,7 @@ export declare class _Kupyna384 extends KupynaDerived<_Kupyna512> {
|
|
|
140
97
|
* kupyna48.create().update(new Uint8Array([97, 98, 99])).digest();
|
|
141
98
|
* ```
|
|
142
99
|
*/
|
|
143
|
-
export declare const kupyna48:
|
|
144
|
-
outputLen: number;
|
|
145
|
-
blockLen: number;
|
|
146
|
-
canXOF: boolean;
|
|
147
|
-
} & import("@noble/hashes/utils.js").HashInfo & {
|
|
148
|
-
(msg: TArg<Uint8Array>): TRet<Uint8Array>;
|
|
149
|
-
create(): _Kupyna48;
|
|
150
|
-
} & ((msg: TArg<TArg<Uint8Array<ArrayBufferLike>>>) => Uint8Array<ArrayBufferLike> & Uint8Array<ArrayBuffer>) & {
|
|
151
|
-
outputLen: number;
|
|
152
|
-
blockLen: number;
|
|
153
|
-
canXOF: boolean;
|
|
154
|
-
oid?: TRet<Uint8Array> | undefined;
|
|
155
|
-
create: () => _Kupyna48;
|
|
156
|
-
};
|
|
100
|
+
export declare const kupyna48: TRet<CHash<_Kupyna48>>;
|
|
157
101
|
/**
|
|
158
102
|
* Kupyna-304 hash function
|
|
159
103
|
*
|
|
@@ -167,20 +111,7 @@ export declare const kupyna48: {
|
|
|
167
111
|
* kupyna304.create().update(new Uint8Array([97, 98, 99])).digest();
|
|
168
112
|
* ```
|
|
169
113
|
*/
|
|
170
|
-
export declare const kupyna304:
|
|
171
|
-
outputLen: number;
|
|
172
|
-
blockLen: number;
|
|
173
|
-
canXOF: boolean;
|
|
174
|
-
} & import("@noble/hashes/utils.js").HashInfo & {
|
|
175
|
-
(msg: TArg<Uint8Array>): TRet<Uint8Array>;
|
|
176
|
-
create(): _Kupyna304;
|
|
177
|
-
} & ((msg: TArg<TArg<Uint8Array<ArrayBufferLike>>>) => Uint8Array<ArrayBufferLike> & Uint8Array<ArrayBuffer>) & {
|
|
178
|
-
outputLen: number;
|
|
179
|
-
blockLen: number;
|
|
180
|
-
canXOF: boolean;
|
|
181
|
-
oid?: TRet<Uint8Array> | undefined;
|
|
182
|
-
create: () => _Kupyna304;
|
|
183
|
-
};
|
|
114
|
+
export declare const kupyna304: TRet<CHash<_Kupyna304>>;
|
|
184
115
|
/**
|
|
185
116
|
* Kupyna-384 hash function
|
|
186
117
|
*
|
|
@@ -194,18 +125,5 @@ export declare const kupyna304: {
|
|
|
194
125
|
* kupyna384.create().update(new Uint8Array([97, 98, 99])).digest();
|
|
195
126
|
* ```
|
|
196
127
|
*/
|
|
197
|
-
export declare const kupyna384:
|
|
198
|
-
|
|
199
|
-
blockLen: number;
|
|
200
|
-
canXOF: boolean;
|
|
201
|
-
} & import("@noble/hashes/utils.js").HashInfo & {
|
|
202
|
-
(msg: TArg<Uint8Array>): TRet<Uint8Array>;
|
|
203
|
-
create(): _Kupyna384;
|
|
204
|
-
} & ((msg: TArg<TArg<Uint8Array<ArrayBufferLike>>>) => Uint8Array<ArrayBufferLike> & Uint8Array<ArrayBuffer>) & {
|
|
205
|
-
outputLen: number;
|
|
206
|
-
blockLen: number;
|
|
207
|
-
canXOF: boolean;
|
|
208
|
-
oid?: TRet<Uint8Array> | undefined;
|
|
209
|
-
create: () => _Kupyna384;
|
|
210
|
-
};
|
|
211
|
-
export * from "./kmac.js";
|
|
128
|
+
export declare const kupyna384: TRet<CHash<_Kupyna384>>;
|
|
129
|
+
export {};
|