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