@li0ard/dstu 0.1.9 → 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/README.md +1 -1
- package/const.d.ts +5 -14
- package/const.js +47 -1010
- package/dstu4145/const.js +15 -15
- package/dstu4145/ec/index.d.ts +4 -0
- package/dstu4145/ec/index.js +28 -27
- package/dstu4145/ecies.d.ts +2 -2
- package/dstu4145/ecies.js +13 -2
- package/dstu4145/gf2m/utils.js +1 -1
- package/dstu4145/index.js +26 -17
- package/dstu9041/curve.d.ts +1 -1
- package/dstu9041/curve.js +16 -29
- package/dstu9041/index.js +21 -25
- package/dstu9311/const.js +12 -12
- package/dstu9311/index.d.ts +1 -2
- package/dstu9311/index.js +37 -34
- 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.d.ts +1 -1
- package/iso15946.js +11 -6
- package/kalyna/index.d.ts +3 -5
- package/kalyna/index.js +119 -98
- package/keywrap.js +11 -13
- package/kupyna/index.d.ts +100 -133
- package/kupyna/index.js +192 -180
- package/modes/_guard.d.ts +4 -0
- package/modes/_guard.js +6 -0
- package/modes/cbc.d.ts +1 -1
- package/modes/cbc.js +6 -7
- package/modes/ccm.js +13 -4
- package/modes/cfb.js +43 -51
- package/modes/cmac.js +6 -2
- package/modes/ctr.js +6 -4
- package/modes/ecb.js +2 -2
- package/modes/gcm.d.ts +4 -1
- package/modes/gcm.js +33 -5
- package/modes/gmac.js +8 -9
- package/modes/index.d.ts +1 -1
- package/modes/index.js +1 -1
- package/modes/kw.js +10 -17
- package/modes/ofb.js +5 -4
- package/modes/xts.js +15 -25
- package/package.json +12 -9
- package/strumok/index.d.ts +4 -5
- package/strumok/index.js +132 -87
- package/utils.d.ts +7 -13
- package/utils.js +31 -61
- package/dstu9311/hash.d.ts +0 -41
- package/dstu9311/hash.js +0 -98
- package/kupyna/kmac.d.ts +0 -46
- package/kupyna/kmac.js +0 -125
package/kupyna/kmac.js
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { uint64sToBytesLE } from "../utils.js";
|
|
2
|
-
import { Kupyna256, Kupyna384, Kupyna512 } from "./index.js";
|
|
3
|
-
import { numberToBytesLE } from "@noble/curves/utils.js";
|
|
4
|
-
const dpad = numberToBytesLE(128, 128);
|
|
5
|
-
const kpad32 = new Uint8Array([
|
|
6
|
-
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
7
|
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
8
|
-
]);
|
|
9
|
-
const kpad48 = new Uint8Array([
|
|
10
|
-
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
11
|
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
12
|
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
13
|
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
14
|
-
0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
15
|
-
]);
|
|
16
|
-
const kpad64 = new Uint8Array([
|
|
17
|
-
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
18
|
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
19
|
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
20
|
-
0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
21
|
-
]);
|
|
22
|
-
class KupynaKMAC {
|
|
23
|
-
outputLen;
|
|
24
|
-
blockLen;
|
|
25
|
-
canXOF = false;
|
|
26
|
-
threshold;
|
|
27
|
-
h;
|
|
28
|
-
ik;
|
|
29
|
-
len;
|
|
30
|
-
constructor(hash, kpad, key) {
|
|
31
|
-
this.len = 0n;
|
|
32
|
-
this.h = hash();
|
|
33
|
-
this.outputLen = this.h.outputLen;
|
|
34
|
-
this.blockLen = this.h.blockLen;
|
|
35
|
-
if (key.length != this.h.outputLen)
|
|
36
|
-
throw new Error("Invalid key length");
|
|
37
|
-
this.h.update(key);
|
|
38
|
-
this.h.update(kpad);
|
|
39
|
-
this.ik = new Uint8Array(key.length);
|
|
40
|
-
for (let i = 0; i < key.length; i++)
|
|
41
|
-
this.ik[i] = ~key[i] & 0xFF;
|
|
42
|
-
this.threshold = BigInt(this.blockLen - 12);
|
|
43
|
-
}
|
|
44
|
-
update(data) {
|
|
45
|
-
this.len += BigInt(data.length);
|
|
46
|
-
this.h.update(data);
|
|
47
|
-
return this;
|
|
48
|
-
}
|
|
49
|
-
digest() {
|
|
50
|
-
const buffer = new Uint8Array(this.outputLen);
|
|
51
|
-
this.digestInto(buffer);
|
|
52
|
-
return buffer;
|
|
53
|
-
}
|
|
54
|
-
digestInto(buffer) {
|
|
55
|
-
let n = this.len;
|
|
56
|
-
let pad_size;
|
|
57
|
-
if (n < this.threshold)
|
|
58
|
-
pad_size = this.threshold - 1n - n;
|
|
59
|
-
else
|
|
60
|
-
pad_size = (BigInt(this.blockLen) - 1n) - ((n - this.threshold) % BigInt(this.blockLen));
|
|
61
|
-
n *= 8n;
|
|
62
|
-
this.h.update(dpad.slice(0, Number(pad_size + 1n)));
|
|
63
|
-
this.h.update(uint64sToBytesLE(new BigUint64Array([n])));
|
|
64
|
-
this.h.update(dpad.slice(16, 20));
|
|
65
|
-
this.h.update(this.ik);
|
|
66
|
-
this.h.digestInto(buffer);
|
|
67
|
-
}
|
|
68
|
-
destroy() {
|
|
69
|
-
throw new Error("Not implemented");
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
/** Kupyna KMAC (256 version) */
|
|
73
|
-
export class KupynaKMAC256 extends KupynaKMAC {
|
|
74
|
-
key;
|
|
75
|
-
constructor(key) {
|
|
76
|
-
super(Kupyna256.create, kpad32, key);
|
|
77
|
-
this.key = key;
|
|
78
|
-
}
|
|
79
|
-
_cloneInto(to) {
|
|
80
|
-
to ||= new KupynaKMAC256(this.key);
|
|
81
|
-
to.h = this.h.clone();
|
|
82
|
-
to.len = this.len;
|
|
83
|
-
to.ik = new Uint8Array(this.ik);
|
|
84
|
-
return to;
|
|
85
|
-
}
|
|
86
|
-
clone() { return this._cloneInto(); }
|
|
87
|
-
}
|
|
88
|
-
/** Kupyna KMAC (384 bit version) */
|
|
89
|
-
export class KupynaKMAC384 extends KupynaKMAC {
|
|
90
|
-
key;
|
|
91
|
-
constructor(key) {
|
|
92
|
-
super(Kupyna384.create, kpad48, key);
|
|
93
|
-
this.key = key;
|
|
94
|
-
}
|
|
95
|
-
_cloneInto(to) {
|
|
96
|
-
to ||= new KupynaKMAC384(this.key);
|
|
97
|
-
to.h = this.h.clone();
|
|
98
|
-
to.len = this.len;
|
|
99
|
-
to.ik = new Uint8Array(this.ik);
|
|
100
|
-
return to;
|
|
101
|
-
}
|
|
102
|
-
clone() { return this._cloneInto(); }
|
|
103
|
-
}
|
|
104
|
-
/** Kupyna KMAC (512 bit version) */
|
|
105
|
-
export class KupynaKMAC512 extends KupynaKMAC {
|
|
106
|
-
key;
|
|
107
|
-
constructor(key) {
|
|
108
|
-
super(Kupyna512.create, kpad64, key);
|
|
109
|
-
this.key = key;
|
|
110
|
-
}
|
|
111
|
-
_cloneInto(to) {
|
|
112
|
-
to ||= new KupynaKMAC512(this.key);
|
|
113
|
-
to.h = this.h.clone();
|
|
114
|
-
to.len = this.len;
|
|
115
|
-
to.ik = new Uint8Array(this.ik);
|
|
116
|
-
return to;
|
|
117
|
-
}
|
|
118
|
-
clone() { return this._cloneInto(); }
|
|
119
|
-
}
|
|
120
|
-
/** Kupyna KMAC (256 version) */
|
|
121
|
-
export const kmac256 = (key, msg) => new KupynaKMAC256(key).update(msg).digest();
|
|
122
|
-
/** Kupyna KMAC (384 version) */
|
|
123
|
-
export const kmac384 = (key, msg) => new KupynaKMAC384(key).update(msg).digest();
|
|
124
|
-
/** Kupyna KMAC (512 version) */
|
|
125
|
-
export const kmac512 = (key, msg) => new KupynaKMAC512(key).update(msg).digest();
|