aegis-aead 0.1.0

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.
@@ -0,0 +1,115 @@
1
+ /**
2
+ * AEGIS-256 cipher state.
3
+ * Uses 6 AES blocks (96 bytes) of internal state and processes 16-byte blocks.
4
+ */
5
+ export declare class Aegis256State {
6
+ private s0;
7
+ private s1;
8
+ private s2;
9
+ private s3;
10
+ private s4;
11
+ private s5;
12
+ private tmp;
13
+ private z;
14
+ private newS;
15
+ private tBuf;
16
+ constructor();
17
+ get s(): Uint8Array[];
18
+ set s(states: Uint8Array[]);
19
+ /**
20
+ * Initializes the state with a key and nonce.
21
+ * @param key - 32-byte encryption key
22
+ * @param nonce - 32-byte nonce (must be unique per message)
23
+ */
24
+ init(key: Uint8Array, nonce: Uint8Array): void;
25
+ /**
26
+ * Updates the state with a 16-byte message block.
27
+ * @param m - ArrayLike<number> - 16-byte message block
28
+ */
29
+ update(m: ArrayLike<number>): void;
30
+ /**
31
+ * Absorbs a 16-byte associated data block into the state.
32
+ * @param ai - 16-byte associated data block
33
+ */
34
+ absorb(ai: Uint8Array): void;
35
+ /**
36
+ * Encrypts a 16-byte plaintext block and writes to output.
37
+ * @param xi - 16-byte plaintext block
38
+ * @param out - 16-byte output buffer
39
+ */
40
+ encTo(xi: Uint8Array, out: Uint8Array): void;
41
+ /**
42
+ * Encrypts a 16-byte plaintext block.
43
+ * @param xi - 16-byte plaintext block
44
+ * @returns 16-byte ciphertext block
45
+ */
46
+ enc(xi: Uint8Array): Uint8Array;
47
+ /**
48
+ * Decrypts a 16-byte ciphertext block and writes to output.
49
+ * @param ci - 16-byte ciphertext block
50
+ * @param out - 16-byte output buffer
51
+ */
52
+ decTo(ci: Uint8Array, out: Uint8Array): void;
53
+ /**
54
+ * Decrypts a 16-byte ciphertext block.
55
+ * @param ci - 16-byte ciphertext block
56
+ * @returns 16-byte plaintext block
57
+ */
58
+ dec(ci: Uint8Array): Uint8Array;
59
+ /**
60
+ * Decrypts a partial (final) ciphertext block smaller than 16 bytes.
61
+ * @param cn - Partial ciphertext block (1-15 bytes)
62
+ * @returns Decrypted plaintext of the same length
63
+ */
64
+ decPartial(cn: Uint8Array): Uint8Array;
65
+ /**
66
+ * Finalizes encryption/decryption and produces an authentication tag.
67
+ * @param adLenBits - Associated data length in bits
68
+ * @param msgLenBits - Message length in bits
69
+ * @param tagLen - Tag length (16 or 32 bytes)
70
+ * @returns Authentication tag
71
+ */
72
+ finalize(adLenBits: bigint, msgLenBits: bigint, tagLen?: 16 | 32): Uint8Array;
73
+ }
74
+ /**
75
+ * Encrypts a message using AEGIS-256.
76
+ * @param msg - Plaintext message
77
+ * @param ad - Associated data (authenticated but not encrypted)
78
+ * @param key - 32-byte encryption key
79
+ * @param nonce - 32-byte nonce (must be unique per message with the same key)
80
+ * @param tagLen - Authentication tag length: 16 or 32 bytes (default: 16)
81
+ * @returns Object containing ciphertext and authentication tag
82
+ */
83
+ export declare function aegis256Encrypt(msg: Uint8Array, ad: Uint8Array, key: Uint8Array, nonce: Uint8Array, tagLen?: 16 | 32): {
84
+ ciphertext: Uint8Array;
85
+ tag: Uint8Array;
86
+ };
87
+ /**
88
+ * Decrypts a message using AEGIS-256.
89
+ * @param ct - Ciphertext
90
+ * @param tag - Authentication tag (16 or 32 bytes)
91
+ * @param ad - Associated data (must match what was used during encryption)
92
+ * @param key - 32-byte encryption key
93
+ * @param nonce - 32-byte nonce (must match what was used during encryption)
94
+ * @returns Decrypted plaintext, or null if authentication fails
95
+ */
96
+ export declare function aegis256Decrypt(ct: Uint8Array, tag: Uint8Array, ad: Uint8Array, key: Uint8Array, nonce: Uint8Array): Uint8Array | null;
97
+ /**
98
+ * Computes a MAC (Message Authentication Code) using AEGIS-256.
99
+ * @param data - Data to authenticate
100
+ * @param key - 32-byte key
101
+ * @param nonce - 32-byte nonce (optional, uses zero nonce if null)
102
+ * @param tagLen - Tag length: 16 or 32 bytes (default: 16)
103
+ * @returns Authentication tag
104
+ */
105
+ export declare function aegis256Mac(data: Uint8Array, key: Uint8Array, nonce?: Uint8Array | null, tagLen?: 16 | 32): Uint8Array;
106
+ /**
107
+ * Verifies a MAC computed using AEGIS-256.
108
+ * @param data - Data to verify
109
+ * @param tag - Expected authentication tag (16 or 32 bytes)
110
+ * @param key - 32-byte key
111
+ * @param nonce - 32-byte nonce (optional, uses zero nonce if null)
112
+ * @returns True if the tag is valid, false otherwise
113
+ */
114
+ export declare function aegis256MacVerify(data: Uint8Array, tag: Uint8Array, key: Uint8Array, nonce?: Uint8Array | null): boolean;
115
+ //# sourceMappingURL=aegis256.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aegis256.d.ts","sourceRoot":"","sources":["../src/aegis256.ts"],"names":[],"mappings":"AAWA;;;GAGG;AACH,qBAAa,aAAa;IACzB,OAAO,CAAC,EAAE,CAAa;IACvB,OAAO,CAAC,EAAE,CAAa;IACvB,OAAO,CAAC,EAAE,CAAa;IACvB,OAAO,CAAC,EAAE,CAAa;IACvB,OAAO,CAAC,EAAE,CAAa;IACvB,OAAO,CAAC,EAAE,CAAa;IACvB,OAAO,CAAC,GAAG,CAAa;IACxB,OAAO,CAAC,CAAC,CAAa;IACtB,OAAO,CAAC,IAAI,CAAe;IAC3B,OAAO,CAAC,IAAI,CAAa;;IAezB,IAAI,CAAC,IAAI,UAAU,EAAE,CAEpB;IAED,IAAI,CAAC,CAAC,MAAM,EAAE,UAAU,EAAE,EAOzB;IAED;;;;OAIG;IACH,IAAI,CAAC,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,GAAG,IAAI;IA0B9C;;;OAGG;IACH,MAAM,CAAC,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG,IAAI;IAmBlC;;;OAGG;IACH,MAAM,CAAC,EAAE,EAAE,UAAU,GAAG,IAAI;IAI5B;;;;OAIG;IACH,KAAK,CAAC,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,UAAU,GAAG,IAAI;I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locksTo, C0, C1, constantTimeEqual, le64To, xorBlocksTo, zeroPad, } from "./aes.js";
2
+ /**
3
+ * AEGIS-256 cipher state.
4
+ * Uses 6 AES blocks (96 bytes) of internal state and processes 16-byte blocks.
5
+ */
6
+ export class Aegis256State {
7
+ constructor() {
8
+ this.s0 = new Uint8Array(16);
9
+ this.s1 = new Uint8Array(16);
10
+ this.s2 = new Uint8Array(16);
11
+ this.s3 = new Uint8Array(16);
12
+ this.s4 = new Uint8Array(16);
13
+ this.s5 = new Uint8Array(16);
14
+ this.tmp = new Uint8Array(16);
15
+ this.z = new Uint8Array(16);
16
+ this.newS = Array.from({ length: 6 }, () => new Uint8Array(16));
17
+ this.tBuf = new Uint8Array(16);
18
+ }
19
+ get s() {
20
+ return [this.s0, this.s1, this.s2, this.s3, this.s4, this.s5];
21
+ }
22
+ set s(states) {
23
+ this.s0.set(states[0]);
24
+ this.s1.set(states[1]);
25
+ this.s2.set(states[2]);
26
+ this.s3.set(states[3]);
27
+ this.s4.set(states[4]);
28
+ this.s5.set(states[5]);
29
+ }
30
+ /**
31
+ * Initializes the state with a key and nonce.
32
+ * @param key - 32-byte encryption key
33
+ * @param nonce - 32-byte nonce (must be unique per message)
34
+ */
35
+ init(key, nonce) {
36
+ const k0 = key.subarray(0, 16);
37
+ const k1 = key.subarray(16, 32);
38
+ const n0 = nonce.subarray(0, 16);
39
+ const n1 = nonce.subarray(16, 32);
40
+ xorBlocksTo(k0, n0, this.s0);
41
+ xorBlocksTo(k1, n1, this.s1);
42
+ this.s2.set(C1);
43
+ this.s3.set(C0);
44
+ xorBlocksTo(k0, C0, this.s4);
45
+ xorBlocksTo(k1, C1, this.s5);
46
+ const k0Xorn0 = new Uint8Array(16);
47
+ const k1Xorn1 = new Uint8Array(16);
48
+ xorBlocksTo(k0, n0, k0Xorn0);
49
+ xorBlocksTo(k1, n1, k1Xorn1);
50
+ for (let i = 0; i < 4; i++) {
51
+ this.update(k0);
52
+ this.update(k1);
53
+ this.update(k0Xorn0);
54
+ this.update(k1Xorn1);
55
+ }
56
+ }
57
+ /**
58
+ * Updates the state with a 16-byte message block.
59
+ * @param m - ArrayLike<number> - 16-byte message block
60
+ */
61
+ update(m) {
62
+ const newS = this.newS;
63
+ xorBlocksTo(this.s0, m, this.tmp);
64
+ aesRoundTo(this.s5, this.tmp, newS[0]);
65
+ aesRoundTo(this.s0, this.s1, newS[1]);
66
+ aesRoundTo(this.s1, this.s2, newS[2]);
67
+ aesRoundTo(this.s2, this.s3, newS[3]);
68
+ aesRoundTo(this.s3, this.s4, newS[4]);
69
+ aesRoundTo(this.s4, this.s5, newS[5]);
70
+ this.s0.set(newS[0]);
71
+ this.s1.set(newS[1]);
72
+ this.s2.set(newS[2]);
73
+ this.s3.set(newS[3]);
74
+ this.s4.set(newS[4]);
75
+ this.s5.set(newS[5]);
76
+ }
77
+ /**
78
+ * Absorbs a 16-byte associated data block into the state.
79
+ * @param ai - 16-byte associated data block
80
+ */
81
+ absorb(ai) {
82
+ this.update(ai);
83
+ }
84
+ /**
85
+ * Encrypts a 16-byte plaintext block and writes to output.
86
+ * @param xi - 16-byte plaintext block
87
+ * @param out - 16-byte output buffer
88
+ */
89
+ encTo(xi, out) {
90
+ const z = this.z;
91
+ const tmp = this.tmp;
92
+ xorBlocksTo(this.s1, this.s4, z);
93
+ for (let i = 0; i < 16; i++)
94
+ z[i] ^= this.s5[i];
95
+ andBlocksTo(this.s2, this.s3, tmp);
96
+ for (let i = 0; i < 16; i++)
97
+ z[i] ^= tmp[i];
98
+ this.update(xi);
99
+ for (let i = 0; i < 16; i++)
100
+ out[i] = xi[i] ^ z[i];
101
+ }
102
+ /**
103
+ * Encrypts a 16-byte plaintext block.
104
+ * @param xi - 16-byte plaintext block
105
+ * @returns 16-byte ciphertext block
106
+ */
107
+ enc(xi) {
108
+ const out = new Uint8Array(16);
109
+ this.encTo(xi, out);
110
+ return out;
111
+ }
112
+ /**
113
+ * Decrypts a 16-byte ciphertext block and writes to output.
114
+ * @param ci - 16-byte ciphertext block
115
+ * @param out - 16-byte output buffer
116
+ */
117
+ decTo(ci, out) {
118
+ const z = this.z;
119
+ const tmp = this.tmp;
120
+ xorBlocksTo(this.s1, this.s4, z);
121
+ for (let i = 0; i < 16; i++)
122
+ z[i] ^= this.s5[i];
123
+ andBlocksTo(this.s2, this.s3, tmp);
124
+ for (let i = 0; i < 16; i++)
125
+ z[i] ^= tmp[i];
126
+ for (let i = 0; i < 16; i++)
127
+ out[i] = ci[i] ^ z[i];
128
+ this.update(out);
129
+ }
130
+ /**
131
+ * Decrypts a 16-byte ciphertext block.
132
+ * @param ci - 16-byte ciphertext block
133
+ * @returns 16-byte plaintext block
134
+ */
135
+ dec(ci) {
136
+ const out = new Uint8Array(16);
137
+ this.decTo(ci, out);
138
+ return out;
139
+ }
140
+ /**
141
+ * Decrypts a partial (final) ciphertext block smaller than 16 bytes.
142
+ * @param cn - Partial ciphertext block (1-15 bytes)
143
+ * @returns Decrypted plaintext of the same length
144
+ */
145
+ decPartial(cn) {
146
+ const z = this.z;
147
+ const tmp = this.tmp;
148
+ xorBlocksTo(this.s1, this.s4, z);
149
+ for (let i = 0; i < 16; i++)
150
+ z[i] ^= this.s5[i];
151
+ andBlocksTo(this.s2, this.s3, tmp);
152
+ for (let i = 0; i < 16; i++)
153
+ z[i] ^= tmp[i];
154
+ const t = zeroPad(cn, 16);
155
+ const out = new Uint8Array(16);
156
+ for (let i = 0; i < 16; i++)
157
+ out[i] = t[i] ^ z[i];
158
+ const xn = new Uint8Array(out.subarray(0, cn.length));
159
+ const v = zeroPad(xn, 16);
160
+ this.update(v);
161
+ return xn;
162
+ }
163
+ /**
164
+ * Finalizes encryption/decryption and produces an authentication tag.
165
+ * @param adLenBits - Associated data length in bits
166
+ * @param msgLenBits - Message length in bits
167
+ * @param tagLen - Tag length (16 or 32 bytes)
168
+ * @returns Authentication tag
169
+ */
170
+ finalize(adLenBits, msgLenBits, tagLen = 16) {
171
+ const t = this.tBuf;
172
+ le64To(adLenBits, t, 0);
173
+ le64To(msgLenBits, t, 8);
174
+ for (let i = 0; i < 16; i++)
175
+ t[i] ^= this.s3[i];
176
+ for (let i = 0; i < 7; i++) {
177
+ this.update(t);
178
+ }
179
+ if (tagLen === 16) {
180
+ const tag = new Uint8Array(16);
181
+ for (let i = 0; i < 16; i++) {
182
+ tag[i] =
183
+ this.s0[i] ^
184
+ this.s1[i] ^
185
+ this.s2[i] ^
186
+ this.s3[i] ^
187
+ this.s4[i] ^
188
+ this.s5[i];
189
+ }
190
+ return tag;
191
+ }
192
+ else {
193
+ const tag = new Uint8Array(32);
194
+ for (let i = 0; i < 16; i++) {
195
+ tag[i] = this.s0[i] ^ this.s1[i] ^ this.s2[i];
196
+ }
197
+ for (let i = 0; i < 16; i++) {
198
+ tag[16 + i] = this.s3[i] ^ this.s4[i] ^ this.s5[i];
199
+ }
200
+ return tag;
201
+ }
202
+ }
203
+ }
204
+ /**
205
+ * Encrypts a message using AEGIS-256.
206
+ * @param msg - Plaintext message
207
+ * @param ad - Associated data (authenticated but not encrypted)
208
+ * @param key - 32-byte encryption key
209
+ * @param nonce - 32-byte nonce (must be unique per message with the same key)
210
+ * @param tagLen - Authentication tag length: 16 or 32 bytes (default: 16)
211
+ * @returns Object containing ciphertext and authentication tag
212
+ */
213
+ export function aegis256Encrypt(msg, ad, key, nonce, tagLen = 16) {
214
+ const state = new Aegis256State();
215
+ state.init(key, nonce);
216
+ const adPadded = zeroPad(ad, 16);
217
+ for (let i = 0; i + 16 <= adPadded.length; i += 16) {
218
+ state.absorb(adPadded.subarray(i, i + 16));
219
+ }
220
+ const msgPadded = zeroPad(msg, 16);
221
+ const ct = new Uint8Array(msgPadded.length);
222
+ for (let i = 0; i + 16 <= msgPadded.length; i += 16) {
223
+ state.encTo(msgPadded.subarray(i, i + 16), ct.subarray(i, i + 16));
224
+ }
225
+ const tag = state.finalize(BigInt(ad.length * 8), BigInt(msg.length * 8), tagLen);
226
+ const ciphertext = new Uint8Array(ct.subarray(0, msg.length));
227
+ return { ciphertext, tag };
228
+ }
229
+ /**
230
+ * Decrypts a message using AEGIS-256.
231
+ * @param ct - Ciphertext
232
+ * @param tag - Authentication tag (16 or 32 bytes)
233
+ * @param ad - Associated data (must match what was used during encryption)
234
+ * @param key - 32-byte encryption key
235
+ * @param nonce - 32-byte nonce (must match what was used during encryption)
236
+ * @returns Decrypted plaintext, or null if authentication fails
237
+ */
238
+ export function aegis256Decrypt(ct, tag, ad, key, nonce) {
239
+ const tagLen = tag.length;
240
+ const state = new Aegis256State();
241
+ state.init(key, nonce);
242
+ const adPadded = zeroPad(ad, 16);
243
+ for (let i = 0; i + 16 <= adPadded.length; i += 16) {
244
+ state.absorb(adPadded.subarray(i, i + 16));
245
+ }
246
+ const fullBlocksLen = Math.floor(ct.length / 16) * 16;
247
+ const cn = ct.subarray(fullBlocksLen);
248
+ const msg = new Uint8Array(fullBlocksLen + (cn.length > 0 ? cn.length : 0));
249
+ for (let i = 0; i + 16 <= ct.length; i += 16) {
250
+ state.decTo(ct.subarray(i, i + 16), msg.subarray(i, i + 16));
251
+ }
252
+ if (cn.length > 0) {
253
+ msg.set(state.decPartial(cn), fullBlocksLen);
254
+ }
255
+ const expectedTag = state.finalize(BigInt(ad.length * 8), BigInt(msg.length * 8), tagLen);
256
+ if (!constantTimeEqual(tag, expectedTag)) {
257
+ msg.fill(0);
258
+ return null;
259
+ }
260
+ return msg;
261
+ }
262
+ /**
263
+ * Computes a MAC (Message Authentication Code) using AEGIS-256.
264
+ * @param data - Data to authenticate
265
+ * @param key - 32-byte key
266
+ * @param nonce - 32-byte nonce (optional, uses zero nonce if null)
267
+ * @param tagLen - Tag length: 16 or 32 bytes (default: 16)
268
+ * @returns Authentication tag
269
+ */
270
+ export function aegis256Mac(data, key, nonce = null, tagLen = 16) {
271
+ const state = new Aegis256State();
272
+ state.init(key, nonce ?? new Uint8Array(32));
273
+ const dataPadded = zeroPad(data, 16);
274
+ for (let i = 0; i + 16 <= dataPadded.length; i += 16) {
275
+ state.absorb(dataPadded.subarray(i, i + 16));
276
+ }
277
+ return state.finalize(BigInt(data.length * 8), BigInt(tagLen * 8), tagLen);
278
+ }
279
+ /**
280
+ * Verifies a MAC computed using AEGIS-256.
281
+ * @param data - Data to verify
282
+ * @param tag - Expected authentication tag (16 or 32 bytes)
283
+ * @param key - 32-byte key
284
+ * @param nonce - 32-byte nonce (optional, uses zero nonce if null)
285
+ * @returns True if the tag is valid, false otherwise
286
+ */
287
+ export function aegis256MacVerify(data, tag, key, nonce = null) {
288
+ const tagLen = tag.length;
289
+ const expectedTag = aegis256Mac(data, key, nonce, tagLen);
290
+ return constantTimeEqual(tag, expectedTag);
291
+ }
292
+ //# sourceMappingURL=aegis256.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aegis256.js","sourceRoot":"","sources":["../src/aegis256.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,UAAU,EACV,WAAW,EACX,EAAE,EACF,EAAE,EACF,iBAAiB,EACjB,MAAM,EACN,WAAW,EACX,OAAO,GACP,MAAM,UAAU,CAAC;AAElB;;;GAGG;AACH,MAAM,OAAO,aAAa;IAYzB;QACC,IAAI,CAAC,EAAE,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC;QAC7B,IAAI,CAAC,EAAE,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC;QAC7B,IAAI,CAAC,EAAE,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC;QAC7B,IAAI,CAAC,EAAE,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC;QAC7B,IAAI,CAAC,EAAE,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC;QAC7B,IAAI,CAAC,EAAE,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC;QAC7B,IAAI,CAAC,GAAG,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC;QAC9B,IAAI,CAAC,CAAC,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC;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,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AAC5E,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,iBAAiB,CAChC,IAAgB,EAChB,GAAe,EACf,GAAe,EACf,QAA2B,IAAI;IAE/B,MAAM,MAAM,GAAG,GAAG,CAAC,MAAiB,CAAC;IACrC,MAAM,WAAW,GAAG,WAAW,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;IAC1D,OAAO,iBAAiB,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;AAC5C,CAAC"}
@@ -0,0 +1,149 @@
1
+ /**
2
+ * AEGIS-256X cipher state with configurable parallelism degree.
3
+ * Extends AEGIS-256 with parallel AES rounds for improved performance on wide SIMD architectures.
4
+ */
5
+ export declare class Aegis256XState {
6
+ private v;
7
+ private d;
8
+ private rate;
9
+ private newV;
10
+ private tmp;
11
+ private z;
12
+ private ctxBufs;
13
+ /**
14
+ * Creates a new AEGIS-256X state.
15
+ * @param degree - Parallelism degree (default: 2). Use 2 for AEGIS-256X2, 4 for AEGIS-256X4.
16
+ */
17
+ constructor(degree?: number);
18
+ /**
19
+ * Initializes the state with a key and nonce.
20
+ * @param key - 32-byte encryption key
21
+ * @param nonce - 32-byte nonce (must be unique per message)
22
+ */
23
+ init(key: Uint8Array, nonce: Uint8Array): void;
24
+ /**
25
+ * Updates the state with a message vector.
26
+ * @param m - Message vector (16*degree bytes)
27
+ */
28
+ update(m: Uint8Array): void;
29
+ /**
30
+ * Absorbs an associated data block into the state.
31
+ * @param ai - Associated data block (16*degree bytes)
32
+ */
33
+ absorb(ai: Uint8Array): void;
34
+ private computeZ;
35
+ /**
36
+ * Encrypts a plaintext block and writes to output buffer.
37
+ * @param xi - Plaintext block (16*degree bytes)
38
+ * @param out - Output buffer (16*degree bytes)
39
+ */
40
+ encTo(xi: Uint8Array, out: Uint8Array): void;
41
+ /**
42
+ * Encrypts a plaintext block.
43
+ * @param xi - Plaintext block (16*degree bytes)
44
+ * @returns Ciphertext block of the same size
45
+ */
46
+ enc(xi: Uint8Array): Uint8Array;
47
+ /**
48
+ * Decrypts a ciphertext block and writes to output buffer.
49
+ * @param ci - Ciphertext block (16*degree bytes)
50
+ * @param out - Output buffer (16*degree bytes)
51
+ */
52
+ decTo(ci: Uint8Array, out: Uint8Array): void;
53
+ /**
54
+ * Decrypts a ciphertext block.
55
+ * @param ci - Ciphertext block (16*degree bytes)
56
+ * @returns Plaintext block of the same size
57
+ */
58
+ dec(ci: Uint8Array): Uint8Array;
59
+ /**
60
+ * Decrypts a partial (final) ciphertext block.
61
+ * @param cn - Partial ciphertext block (smaller than 16*degree bytes)
62
+ * @returns Decrypted plaintext of the same length
63
+ */
64
+ decPartial(cn: Uint8Array): Uint8Array;
65
+ /**
66
+ * Finalizes encryption/decryption and produces an authentication tag.
67
+ * @param adLenBits - Associated data length in bits
68
+ * @param msgLenBits - Message length in bits
69
+ * @param tagLen - Tag length (16 or 32 bytes)
70
+ * @returns Authentication tag
71
+ */
72
+ finalize(adLenBits: bigint, msgLenBits: bigint, tagLen?: 16 | 32): Uint8Array;
73
+ /**
74
+ * Finalizes MAC computation and produces an authentication tag.
75
+ * Uses a different finalization procedure than encryption/decryption.
76
+ * @param dataLenBits - Data length in bits
77
+ * @param tagLen - Tag length (16 or 32 bytes)
78
+ * @returns Authentication tag
79
+ */
80
+ finalizeMac(dataLenBits: bigint, tagLen?: 16 | 32): Uint8Array;
81
+ }
82
+ /**
83
+ * Encrypts a message using AEGIS-256X.
84
+ * @param msg - Plaintext message
85
+ * @param ad - Associated data (authenticated but not encrypted)
86
+ * @param key - 32-byte encryption key
87
+ * @param nonce - 32-byte nonce (must be unique per message with the same key)
88
+ * @param tagLen - Authentication tag length: 16 or 32 bytes (default: 16)
89
+ * @param degree - Parallelism degree (default: 2)
90
+ * @returns Object containing ciphertext and authentication tag
91
+ */
92
+ export declare function aegis256XEncrypt(msg: Uint8Array, ad: Uint8Array, key: Uint8Array, nonce: Uint8Array, tagLen?: 16 | 32, degree?: number): {
93
+ ciphertext: Uint8Array;
94
+ tag: Uint8Array;
95
+ };
96
+ /**
97
+ * Decrypts a message using AEGIS-256X.
98
+ * @param ct - Ciphertext
99
+ * @param tag - Authentication tag (16 or 32 bytes)
100
+ * @param ad - Associated data (must match what was used during encryption)
101
+ * @param key - 32-byte encryption key
102
+ * @param nonce - 32-byte nonce (must match what was used during encryption)
103
+ * @param degree - Parallelism degree (default: 2)
104
+ * @returns Decrypted plaintext, or null if authentication fails
105
+ */
106
+ export declare function aegis256XDecrypt(ct: Uint8Array, tag: Uint8Array, ad: Uint8Array, key: Uint8Array, nonce: Uint8Array, degree?: number): Uint8Array | null;
107
+ /** AEGIS-256X2 encryption (degree=2). */
108
+ export declare const aegis256X2Encrypt: (msg: Uint8Array, ad: Uint8Array, key: Uint8Array, nonce: Uint8Array, tagLen?: 16 | 32) => {
109
+ ciphertext: Uint8Array;
110
+ tag: Uint8Array;
111
+ };
112
+ /** AEGIS-256X2 decryption (degree=2). */
113
+ export declare const aegis256X2Decrypt: (ct: Uint8Array, tag: Uint8Array, ad: Uint8Array, key: Uint8Array, nonce: Uint8Array) => Uint8Array<ArrayBufferLike> | null;
114
+ /** AEGIS-256X4 encryption (degree=4). */
115
+ export declare const aegis256X4Encrypt: (msg: Uint8Array, ad: Uint8Array, key: Uint8Array, nonce: Uint8Array, tagLen?: 16 | 32) => {
116
+ ciphertext: Uint8Array;
117
+ tag: Uint8Array;
118
+ };
119
+ /** AEGIS-256X4 decryption (degree=4). */
120
+ export declare const aegis256X4Decrypt: (ct: Uint8Array, tag: Uint8Array, ad: Uint8Array, key: Uint8Array, nonce: Uint8Array) => Uint8Array<ArrayBufferLike> | null;
121
+ /**
122
+ * Computes a MAC (Message Authentication Code) using AEGIS-256X.
123
+ * @param data - Data to authenticate
124
+ * @param key - 32-byte key
125
+ * @param nonce - 32-byte nonce (optional, uses zero nonce if null)
126
+ * @param tagLen - Tag length: 16 or 32 bytes (default: 16)
127
+ * @param degree - Parallelism degree (default: 2)
128
+ * @returns Authentication tag
129
+ */
130
+ export declare function aegis256XMac(data: Uint8Array, key: Uint8Array, nonce?: Uint8Array | null, tagLen?: 16 | 32, degree?: number): Uint8Array;
131
+ /**
132
+ * Verifies a MAC computed using AEGIS-256X.
133
+ * @param data - Data to verify
134
+ * @param tag - Expected authentication tag (16 or 32 bytes)
135
+ * @param key - 32-byte key
136
+ * @param nonce - 32-byte nonce (optional, uses zero nonce if null)
137
+ * @param degree - Parallelism degree (default: 2)
138
+ * @returns True if the tag is valid, false otherwise
139
+ */
140
+ export declare function aegis256XMacVerify(data: Uint8Array, tag: Uint8Array, key: Uint8Array, nonce?: Uint8Array | null, degree?: number): boolean;
141
+ /** AEGIS-256X2 MAC computation (degree=2). */
142
+ export declare const aegis256X2Mac: (data: Uint8Array, key: Uint8Array, nonce?: Uint8Array | null, tagLen?: 16 | 32) => Uint8Array<ArrayBufferLike>;
143
+ /** AEGIS-256X2 MAC verification (degree=2). */
144
+ export declare const aegis256X2MacVerify: (data: Uint8Array, tag: Uint8Array, key: Uint8Array, nonce?: Uint8Array | null) => boolean;
145
+ /** AEGIS-256X4 MAC computation (degree=4). */
146
+ export declare const aegis256X4Mac: (data: Uint8Array, key: Uint8Array, nonce?: Uint8Array | null, tagLen?: 16 | 32) => Uint8Array<ArrayBufferLike>;
147
+ /** AEGIS-256X4 MAC verification (degree=4). */
148
+ export declare const aegis256X4MacVerify: (data: Uint8Array, tag: Uint8Array, key: Uint8Array, nonce?: Uint8Array | null) => boolean;
149
+ //# sourceMappingURL=aegis256x.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aegis256x.d.ts","sourceRoot":"","sources":["../src/aegis256x.ts"],"names":[],"mappings":"AAaA;;;GAGG;AACH,qBAAa,cAAc;IAC1B,OAAO,CAAC,CAAC,CAAiB;IAC1B,OAAO,CAAC,CAAC,CAAS;IAClB,O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