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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Frank Denis
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,155 @@
1
+ # aegis-aead
2
+
3
+ [![npm](https://img.shields.io/npm/v/aegis-aead)](https://www.npmjs.com/package/aegis-aead)
4
+ [![CI](https://github.com/jedisct1/js-aegis-aead/actions/workflows/ci.yml/badge.svg)](https://github.com/jedisct1/js-aegis-aead/actions/workflows/ci.yml)
5
+
6
+ JavaScript / TypeScript implementation of the [AEGIS authenticated encryption algorithms](https://datatracker.ietf.org/doc/draft-irtf-cfrg-aegis-aead/).
7
+
8
+ AEGIS is a family of fast authenticated encryption algorithms built on AES round functions. It provides both encryption with authentication and standalone MAC functionality.
9
+
10
+ ## Installation
11
+
12
+ ```bash
13
+ bun add aegis-aead
14
+ # or
15
+ npm install aegis-aead
16
+ ```
17
+
18
+ ## Usage
19
+
20
+ ### Encryption and Decryption
21
+
22
+ ```typescript
23
+ import { aegis128LEncrypt, aegis128LDecrypt } from "aegis-aead";
24
+
25
+ const key = crypto.getRandomValues(new Uint8Array(16));
26
+ const nonce = crypto.getRandomValues(new Uint8Array(16));
27
+ const message = new TextEncoder().encode("Hello, world!");
28
+ const associatedData = new TextEncoder().encode("metadata");
29
+
30
+ // Encrypt
31
+ const { ciphertext, tag } = aegis128LEncrypt(message, associatedData, key, nonce);
32
+
33
+ // Decrypt (returns null if authentication fails)
34
+ const decrypted = aegis128LDecrypt(ciphertext, tag, associatedData, key, nonce);
35
+ ```
36
+
37
+ ### MAC (Message Authentication Code)
38
+
39
+ ```typescript
40
+ import { aegis128LMac, aegis128LMacVerify } from "aegis-aead";
41
+
42
+ const key = crypto.getRandomValues(new Uint8Array(16));
43
+ const nonce = crypto.getRandomValues(new Uint8Array(16));
44
+ const data = new TextEncoder().encode("data to authenticate");
45
+
46
+ // Generate MAC
47
+ const tag = aegis128LMac(data, key, nonce);
48
+
49
+ // Verify MAC
50
+ const valid = aegis128LMacVerify(data, tag, key, nonce);
51
+ ```
52
+
53
+ ## Algorithms
54
+
55
+ | Algorithm | Key Size | Nonce Size | Block Size | Use Case |
56
+ | ---------- | -------- | ---------- | ---------- | ---------------------------------- |
57
+ | AEGIS-128L | 16 bytes | 16 bytes | 32 bytes | High throughput on 64-bit CPUs |
58
+ | AEGIS-256 | 32 bytes | 32 bytes | 16 bytes | 256-bit security level |
59
+ | AEGIS-128X | 16 bytes | 16 bytes | 32×D bytes | Multi-lane AEGIS-128L (D = degree) |
60
+ | AEGIS-256X | 32 bytes | 32 bytes | 16×D bytes | Multi-lane AEGIS-256 (D = degree) |
61
+
62
+ ### Tag Lengths
63
+
64
+ All algorithms support two tag lengths:
65
+ - 16 bytes (128-bit) - default
66
+ - 32 bytes (256-bit) - pass `32` as the last parameter to encrypt/MAC functions
67
+
68
+ ## API Reference
69
+
70
+ ### AEGIS-128L
71
+
72
+ ```typescript
73
+ aegis128LEncrypt(msg, ad, key, nonce, tagLen?): { ciphertext, tag }
74
+ aegis128LDecrypt(ciphertext, tag, ad, key, nonce): Uint8Array | null
75
+ aegis128LMac(data, key, nonce, tagLen?): Uint8Array
76
+ aegis128LMacVerify(data, tag, key, nonce): boolean
77
+ ```
78
+
79
+ ### AEGIS-256
80
+
81
+ ```typescript
82
+ aegis256Encrypt(msg, ad, key, nonce, tagLen?): { ciphertext, tag }
83
+ aegis256Decrypt(ciphertext, tag, ad, key, nonce): Uint8Array | null
84
+ aegis256Mac(data, key, nonce, tagLen?): Uint8Array
85
+ aegis256MacVerify(data, tag, key, nonce): boolean
86
+ ```
87
+
88
+ ### AEGIS-128X
89
+
90
+ Pre-configured variants for degree 2 and 4:
91
+
92
+ ```typescript
93
+ // Degree 2
94
+ aegis128X2Encrypt(msg, ad, key, nonce, tagLen?): { ciphertext, tag }
95
+ aegis128X2Decrypt(ciphertext, tag, ad, key, nonce): Uint8Array | null
96
+ aegis128X2Mac(data, key, nonce, tagLen?): Uint8Array
97
+ aegis128X2MacVerify(data, tag, key, nonce): boolean
98
+
99
+ // Degree 4
100
+ aegis128X4Encrypt(msg, ad, key, nonce, tagLen?): { ciphertext, tag }
101
+ aegis128X4Decrypt(ciphertext, tag, ad, key, nonce): Uint8Array | null
102
+ aegis128X4Mac(data, key, nonce, tagLen?): Uint8Array
103
+ aegis128X4MacVerify(data, tag, key, nonce): boolean
104
+
105
+ // Custom degree
106
+ aegis128XEncrypt(msg, ad, key, nonce, tagLen?, degree?): { ciphertext, tag }
107
+ aegis128XDecrypt(ciphertext, tag, ad, key, nonce, degree?): Uint8Array | null
108
+ aegis128XMac(data, key, nonce, tagLen?, degree?): Uint8Array
109
+ aegis128XMacVerify(data, tag, key, nonce, degree?): boolean
110
+ ```
111
+
112
+ ### AEGIS-256X
113
+
114
+ Pre-configured variants for degree 2 and 4:
115
+
116
+ ```typescript
117
+ // Degree 2
118
+ aegis256X2Encrypt(msg, ad, key, nonce, tagLen?): { ciphertext, tag }
119
+ aegis256X2Decrypt(ciphertext, tag, ad, key, nonce): Uint8Array | null
120
+ aegis256X2Mac(data, key, nonce, tagLen?): Uint8Array
121
+ aegis256X2MacVerify(data, tag, key, nonce): boolean
122
+
123
+ // Degree 4
124
+ aegis256X4Encrypt(msg, ad, key, nonce, tagLen?): { ciphertext, tag }
125
+ aegis256X4Decrypt(ciphertext, tag, ad, key, nonce): Uint8Array | null
126
+ aegis256X4Mac(data, key, nonce, tagLen?): Uint8Array
127
+ aegis256X4MacVerify(data, tag, key, nonce): boolean
128
+
129
+ // Custom degree
130
+ aegis256XEncrypt(msg, ad, key, nonce, tagLen?, degree?): { ciphertext, tag }
131
+ aegis256XDecrypt(ciphertext, tag, ad, key, nonce, degree?): Uint8Array | null
132
+ aegis256XMac(data, key, nonce, tagLen?, degree?): Uint8Array
133
+ aegis256XMacVerify(data, tag, key, nonce, degree?): boolean
134
+ ```
135
+
136
+ ## Browser Example
137
+
138
+ A browser example is included in `examples/`. To build and run it:
139
+
140
+ ```bash
141
+ bun run build:example
142
+ open examples/index.html
143
+ ```
144
+
145
+ The example demonstrates encryption/decryption with a simple UI where you can enter a message, encrypt it, and decrypt it back.
146
+
147
+ ## Security Notes
148
+
149
+ - Never reuse a nonce with the same key
150
+ - Decryption returns `null` on authentication failure; do not use any partial output
151
+ - Tag verification uses constant-time comparison
152
+
153
+ ## License
154
+
155
+ MIT
@@ -0,0 +1,120 @@
1
+ /**
2
+ * AEGIS-128L cipher state.
3
+ * Uses 8 AES blocks (128 bytes) of internal state and processes 32-byte blocks.
4
+ */
5
+ export declare class Aegis128LState {
6
+ private s0;
7
+ private s1;
8
+ private s2;
9
+ private s3;
10
+ private s4;
11
+ private s5;
12
+ private s6;
13
+ private s7;
14
+ private tmp0;
15
+ private tmp1;
16
+ private z0;
17
+ private z1;
18
+ private newS;
19
+ private tBuf;
20
+ constructor();
21
+ get s(): Uint8Array[];
22
+ set s(states: Uint8Array[]);
23
+ /**
24
+ * Initializes the state with a key and nonce.
25
+ * @param key - 16-byte encryption key
26
+ * @param nonce - 16-byte nonce (must be unique per message)
27
+ */
28
+ init(key: Uint8Array, nonce: Uint8Array): void;
29
+ /**
30
+ * Updates the state with two 16-byte message blocks.
31
+ * @param m0 - First 16-byte message block
32
+ * @param m1 - Second 16-byte message block
33
+ */
34
+ update(m0: ArrayLike<number>, m1: ArrayLike<number>): void;
35
+ /**
36
+ * Absorbs a 32-byte associated data block into the state.
37
+ * @param ai - 32-byte associated data block
38
+ */
39
+ absorb(ai: Uint8Array): void;
40
+ /**
41
+ * Encrypts a 32-byte plaintext block and writes to output buffer.
42
+ * @param xi - 32-byte plaintext block
43
+ * @param out - 32-byte output buffer
44
+ */
45
+ encTo(xi: Uint8Array, out: Uint8Array): void;
46
+ /**
47
+ * Encrypts a 32-byte plaintext block.
48
+ * @param xi - 32-byte plaintext block
49
+ * @returns 32-byte ciphertext block
50
+ */
51
+ enc(xi: Uint8Array): Uint8Array;
52
+ /**
53
+ * Decrypts a 32-byte ciphertext block and writes to output buffer.
54
+ * @param ci - 32-byte ciphertext block
55
+ * @param out - 32-byte output buffer
56
+ */
57
+ decTo(ci: Uint8Array, out: Uint8Array): void;
58
+ /**
59
+ * Decrypts a 32-byte ciphertext block.
60
+ * @param ci - 32-byte ciphertext block
61
+ * @returns 32-byte plaintext block
62
+ */
63
+ dec(ci: Uint8Array): Uint8Array;
64
+ /**
65
+ * Decrypts a partial (final) ciphertext block smaller than 32 bytes.
66
+ * @param cn - Partial ciphertext block (1-31 bytes)
67
+ * @returns Decrypted plaintext of the same length
68
+ */
69
+ decPartial(cn: Uint8Array): Uint8Array;
70
+ /**
71
+ * Finalizes encryption/decryption and produces an authentication tag.
72
+ * @param adLenBits - Associated data length in bits
73
+ * @param msgLenBits - Message length in bits
74
+ * @param tagLen - Tag length (16 or 32 bytes)
75
+ * @returns Authentication tag
76
+ */
77
+ finalize(adLenBits: bigint, msgLenBits: bigint, tagLen?: 16 | 32): Uint8Array;
78
+ }
79
+ /**
80
+ * Encrypts a message using AEGIS-128L.
81
+ * @param msg - Plaintext message
82
+ * @param ad - Associated data (authenticated but not encrypted)
83
+ * @param key - 16-byte encryption key
84
+ * @param nonce - 16-byte nonce (must be unique per message with the same key)
85
+ * @param tagLen - Authentication tag length: 16 or 32 bytes (default: 16)
86
+ * @returns Object containing ciphertext and authentication tag
87
+ */
88
+ export declare function aegis128LEncrypt(msg: Uint8Array, ad: Uint8Array, key: Uint8Array, nonce: Uint8Array, tagLen?: 16 | 32): {
89
+ ciphertext: Uint8Array;
90
+ tag: Uint8Array;
91
+ };
92
+ /**
93
+ * Decrypts a message using AEGIS-128L.
94
+ * @param ct - Ciphertext
95
+ * @param tag - Authentication tag (16 or 32 bytes)
96
+ * @param ad - Associated data (must match what was used during encryption)
97
+ * @param key - 16-byte encryption key
98
+ * @param nonce - 16-byte nonce (must match what was used during encryption)
99
+ * @returns Decrypted plaintext, or null if authentication fails
100
+ */
101
+ export declare function aegis128LDecrypt(ct: Uint8Array, tag: Uint8Array, ad: Uint8Array, key: Uint8Array, nonce: Uint8Array): Uint8Array | null;
102
+ /**
103
+ * Computes a MAC (Message Authentication Code) using AEGIS-128L.
104
+ * @param data - Data to authenticate
105
+ * @param key - 16-byte key
106
+ * @param nonce - 16-byte nonce (optional, uses zero nonce if null)
107
+ * @param tagLen - Tag length: 16 or 32 bytes (default: 16)
108
+ * @returns Authentication tag
109
+ */
110
+ export declare function aegis128LMac(data: Uint8Array, key: Uint8Array, nonce?: Uint8Array | null, tagLen?: 16 | 32): Uint8Array;
111
+ /**
112
+ * Verifies a MAC computed using AEGIS-128L.
113
+ * @param data - Data to verify
114
+ * @param tag - Expected authentication tag (16 or 32 bytes)
115
+ * @param key - 16-byte key
116
+ * @param nonce - 16-byte nonce (optional, uses zero nonce if null)
117
+ * @returns True if the tag is valid, false otherwise
118
+ */
119
+ export declare function aegis128LMacVerify(data: Uint8Array, tag: Uint8Array, key: Uint8Array, nonce?: Uint8Array | null): boolean;
120
+ //# sourceMappingURL=aegis128l.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aegis128l.d.ts","sourceRoot":"","sources":["../src/aegis128l.ts"],"names":[],"mappings":"AAWA;;;GAGG;AACH,qBAAa,cAAc;IAC1B,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,EAAE,CAAa;IACvB,OAAO,CAAC,EAAE,CAAa;IACvB,OAAO,CAAC,IAAI,CAAa;IACzB,OAAO,CAAC,IAAI,CAAa;IACzB,OAAO,CAAC,EAAE,CAAa;IACvB,OAAO,CAAC,EAAE,CAAa;IACvB,OAAO,CAAC,IAAI,CAAe;IAC3B,OAAO,CAAC,IAAI,CAAa;;IAmBzB,IAAI,CAAC,IAAI,UAAU,EAAE,CAWpB;IAED,IAAI,CAAC,CAAC,MAAM,EAAE,UAAU,EAAE,EASzB;IAED;;;;OAIG;IACH,IAAI,CAAC,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,GAAG,IAAI;IAe9C;;;;OAIG;IACH,MAAM,CAAC,EAAE,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG,IAAI;IAwB1D;;;OAGG;IACH,MAAM,CAAC,EAAE,EAAE,UAAU,GAAG,IAAI;IAI5B;;;;OAIG;IACH,KAAK,CAAC,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,UAAU,GAAG,IAAI;IAsB5C;;;;OAIG;IACH,GAAG,CAAC,EAAE,EAAE,UAAU,GAAG,UAAU;IAM/B;;;;OAIG;IACH,KA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-128L cipher state.
4
+ * Uses 8 AES blocks (128 bytes) of internal state and processes 32-byte blocks.
5
+ */
6
+ export class Aegis128LState {
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.s6 = new Uint8Array(16);
15
+ this.s7 = new Uint8Array(16);
16
+ this.tmp0 = new Uint8Array(16);
17
+ this.tmp1 = new Uint8Array(16);
18
+ this.z0 = new Uint8Array(16);
19
+ this.z1 = new Uint8Array(16);
20
+ this.newS = Array.from({ length: 8 }, () => new Uint8Array(16));
21
+ this.tBuf = new Uint8Array(16);
22
+ }
23
+ get s() {
24
+ return [
25
+ this.s0,
26
+ this.s1,
27
+ this.s2,
28
+ this.s3,
29
+ this.s4,
30
+ this.s5,
31
+ this.s6,
32
+ this.s7,
33
+ ];
34
+ }
35
+ set s(states) {
36
+ this.s0.set(states[0]);
37
+ this.s1.set(states[1]);
38
+ this.s2.set(states[2]);
39
+ this.s3.set(states[3]);
40
+ this.s4.set(states[4]);
41
+ this.s5.set(states[5]);
42
+ this.s6.set(states[6]);
43
+ this.s7.set(states[7]);
44
+ }
45
+ /**
46
+ * Initializes the state with a key and nonce.
47
+ * @param key - 16-byte encryption key
48
+ * @param nonce - 16-byte nonce (must be unique per message)
49
+ */
50
+ init(key, nonce) {
51
+ xorBlocksTo(key, nonce, this.s0);
52
+ this.s1.set(C1);
53
+ this.s2.set(C0);
54
+ this.s3.set(C1);
55
+ xorBlocksTo(key, nonce, this.s4);
56
+ xorBlocksTo(key, C0, this.s5);
57
+ xorBlocksTo(key, C1, this.s6);
58
+ xorBlocksTo(key, C0, this.s7);
59
+ for (let i = 0; i < 10; i++) {
60
+ this.update(nonce, key);
61
+ }
62
+ }
63
+ /**
64
+ * Updates the state with two 16-byte message blocks.
65
+ * @param m0 - First 16-byte message block
66
+ * @param m1 - Second 16-byte message block
67
+ */
68
+ update(m0, m1) {
69
+ const newS = this.newS;
70
+ xorBlocksTo(this.s0, m0, this.tmp0);
71
+ aesRoundTo(this.s7, this.tmp0, newS[0]);
72
+ aesRoundTo(this.s0, this.s1, newS[1]);
73
+ aesRoundTo(this.s1, this.s2, newS[2]);
74
+ aesRoundTo(this.s2, this.s3, newS[3]);
75
+ xorBlocksTo(this.s4, m1, this.tmp1);
76
+ aesRoundTo(this.s3, this.tmp1, newS[4]);
77
+ aesRoundTo(this.s4, this.s5, newS[5]);
78
+ aesRoundTo(this.s5, this.s6, newS[6]);
79
+ aesRoundTo(this.s6, this.s7, newS[7]);
80
+ this.s0.set(newS[0]);
81
+ this.s1.set(newS[1]);
82
+ this.s2.set(newS[2]);
83
+ this.s3.set(newS[3]);
84
+ this.s4.set(newS[4]);
85
+ this.s5.set(newS[5]);
86
+ this.s6.set(newS[6]);
87
+ this.s7.set(newS[7]);
88
+ }
89
+ /**
90
+ * Absorbs a 32-byte associated data block into the state.
91
+ * @param ai - 32-byte associated data block
92
+ */
93
+ absorb(ai) {
94
+ this.update(ai.subarray(0, 16), ai.subarray(16, 32));
95
+ }
96
+ /**
97
+ * Encrypts a 32-byte plaintext block and writes to output buffer.
98
+ * @param xi - 32-byte plaintext block
99
+ * @param out - 32-byte output buffer
100
+ */
101
+ encTo(xi, out) {
102
+ const z0 = this.z0;
103
+ const z1 = this.z1;
104
+ const tmp = this.tmp0;
105
+ xorBlocksTo(this.s1, this.s6, z0);
106
+ andBlocksTo(this.s2, this.s3, tmp);
107
+ for (let i = 0; i < 16; i++)
108
+ z0[i] ^= tmp[i];
109
+ xorBlocksTo(this.s2, this.s5, z1);
110
+ andBlocksTo(this.s6, this.s7, tmp);
111
+ for (let i = 0; i < 16; i++)
112
+ z1[i] ^= tmp[i];
113
+ const t0 = xi.subarray(0, 16);
114
+ const t1 = xi.subarray(16, 32);
115
+ for (let i = 0; i < 16; i++)
116
+ out[i] = t0[i] ^ z0[i];
117
+ for (let i = 0; i < 16; i++)
118
+ out[16 + i] = t1[i] ^ z1[i];
119
+ this.update(t0, t1);
120
+ }
121
+ /**
122
+ * Encrypts a 32-byte plaintext block.
123
+ * @param xi - 32-byte plaintext block
124
+ * @returns 32-byte ciphertext block
125
+ */
126
+ enc(xi) {
127
+ const out = new Uint8Array(32);
128
+ this.encTo(xi, out);
129
+ return out;
130
+ }
131
+ /**
132
+ * Decrypts a 32-byte ciphertext block and writes to output buffer.
133
+ * @param ci - 32-byte ciphertext block
134
+ * @param out - 32-byte output buffer
135
+ */
136
+ decTo(ci, out) {
137
+ const z0 = this.z0;
138
+ const z1 = this.z1;
139
+ const tmp = this.tmp0;
140
+ xorBlocksTo(this.s1, this.s6, z0);
141
+ andBlocksTo(this.s2, this.s3, tmp);
142
+ for (let i = 0; i < 16; i++)
143
+ z0[i] ^= tmp[i];
144
+ xorBlocksTo(this.s2, this.s5, z1);
145
+ andBlocksTo(this.s6, this.s7, tmp);
146
+ for (let i = 0; i < 16; i++)
147
+ z1[i] ^= tmp[i];
148
+ const t0 = ci.subarray(0, 16);
149
+ const t1 = ci.subarray(16, 32);
150
+ for (let i = 0; i < 16; i++)
151
+ out[i] = t0[i] ^ z0[i];
152
+ for (let i = 0; i < 16; i++)
153
+ out[16 + i] = t1[i] ^ z1[i];
154
+ this.update(out.subarray(0, 16), out.subarray(16, 32));
155
+ }
156
+ /**
157
+ * Decrypts a 32-byte ciphertext block.
158
+ * @param ci - 32-byte ciphertext block
159
+ * @returns 32-byte plaintext block
160
+ */
161
+ dec(ci) {
162
+ const out = new Uint8Array(32);
163
+ this.decTo(ci, out);
164
+ return out;
165
+ }
166
+ /**
167
+ * Decrypts a partial (final) ciphertext block smaller than 32 bytes.
168
+ * @param cn - Partial ciphertext block (1-31 bytes)
169
+ * @returns Decrypted plaintext of the same length
170
+ */
171
+ decPartial(cn) {
172
+ const z0 = this.z0;
173
+ const z1 = this.z1;
174
+ const tmp = this.tmp0;
175
+ xorBlocksTo(this.s1, this.s6, z0);
176
+ andBlocksTo(this.s2, this.s3, tmp);
177
+ for (let i = 0; i < 16; i++)
178
+ z0[i] ^= tmp[i];
179
+ xorBlocksTo(this.s2, this.s5, z1);
180
+ andBlocksTo(this.s6, this.s7, tmp);
181
+ for (let i = 0; i < 16; i++)
182
+ z1[i] ^= tmp[i];
183
+ const padded = zeroPad(cn, 32);
184
+ const t0 = padded.subarray(0, 16);
185
+ const t1 = padded.subarray(16, 32);
186
+ const out = new Uint8Array(32);
187
+ for (let i = 0; i < 16; i++)
188
+ out[i] = t0[i] ^ z0[i];
189
+ for (let i = 0; i < 16; i++)
190
+ out[16 + i] = t1[i] ^ z1[i];
191
+ const xn = new Uint8Array(out.subarray(0, cn.length));
192
+ const v = zeroPad(xn, 32);
193
+ this.update(v.subarray(0, 16), v.subarray(16, 32));
194
+ return xn;
195
+ }
196
+ /**
197
+ * Finalizes encryption/decryption and produces an authentication tag.
198
+ * @param adLenBits - Associated data length in bits
199
+ * @param msgLenBits - Message length in bits
200
+ * @param tagLen - Tag length (16 or 32 bytes)
201
+ * @returns Authentication tag
202
+ */
203
+ finalize(adLenBits, msgLenBits, tagLen = 16) {
204
+ const t = this.tBuf;
205
+ le64To(adLenBits, t, 0);
206
+ le64To(msgLenBits, t, 8);
207
+ for (let i = 0; i < 16; i++)
208
+ t[i] ^= this.s2[i];
209
+ for (let i = 0; i < 7; i++) {
210
+ this.update(t, t);
211
+ }
212
+ if (tagLen === 16) {
213
+ const tag = new Uint8Array(16);
214
+ for (let i = 0; i < 16; i++) {
215
+ tag[i] =
216
+ this.s0[i] ^
217
+ this.s1[i] ^
218
+ this.s2[i] ^
219
+ this.s3[i] ^
220
+ this.s4[i] ^
221
+ this.s5[i] ^
222
+ this.s6[i];
223
+ }
224
+ return tag;
225
+ }
226
+ else {
227
+ const tag = new Uint8Array(32);
228
+ for (let i = 0; i < 16; i++) {
229
+ tag[i] = this.s0[i] ^ this.s1[i] ^ this.s2[i] ^ this.s3[i];
230
+ }
231
+ for (let i = 0; i < 16; i++) {
232
+ tag[16 + i] = this.s4[i] ^ this.s5[i] ^ this.s6[i] ^ this.s7[i];
233
+ }
234
+ return tag;
235
+ }
236
+ }
237
+ }
238
+ /**
239
+ * Encrypts a message using AEGIS-128L.
240
+ * @param msg - Plaintext message
241
+ * @param ad - Associated data (authenticated but not encrypted)
242
+ * @param key - 16-byte encryption key
243
+ * @param nonce - 16-byte nonce (must be unique per message with the same key)
244
+ * @param tagLen - Authentication tag length: 16 or 32 bytes (default: 16)
245
+ * @returns Object containing ciphertext and authentication tag
246
+ */
247
+ export function aegis128LEncrypt(msg, ad, key, nonce, tagLen = 16) {
248
+ const state = new Aegis128LState();
249
+ state.init(key, nonce);
250
+ const adPadded = zeroPad(ad, 32);
251
+ for (let i = 0; i + 32 <= adPadded.length; i += 32) {
252
+ state.absorb(adPadded.subarray(i, i + 32));
253
+ }
254
+ const msgPadded = zeroPad(msg, 32);
255
+ const ct = new Uint8Array(msgPadded.length);
256
+ for (let i = 0; i + 32 <= msgPadded.length; i += 32) {
257
+ state.encTo(msgPadded.subarray(i, i + 32), ct.subarray(i, i + 32));
258
+ }
259
+ const tag = state.finalize(BigInt(ad.length * 8), BigInt(msg.length * 8), tagLen);
260
+ const ciphertext = new Uint8Array(ct.subarray(0, msg.length));
261
+ return { ciphertext, tag };
262
+ }
263
+ /**
264
+ * Decrypts a message using AEGIS-128L.
265
+ * @param ct - Ciphertext
266
+ * @param tag - Authentication tag (16 or 32 bytes)
267
+ * @param ad - Associated data (must match what was used during encryption)
268
+ * @param key - 16-byte encryption key
269
+ * @param nonce - 16-byte nonce (must match what was used during encryption)
270
+ * @returns Decrypted plaintext, or null if authentication fails
271
+ */
272
+ export function aegis128LDecrypt(ct, tag, ad, key, nonce) {
273
+ const tagLen = tag.length;
274
+ const state = new Aegis128LState();
275
+ state.init(key, nonce);
276
+ const adPadded = zeroPad(ad, 32);
277
+ for (let i = 0; i + 32 <= adPadded.length; i += 32) {
278
+ state.absorb(adPadded.subarray(i, i + 32));
279
+ }
280
+ const fullBlocksLen = Math.floor(ct.length / 32) * 32;
281
+ const cn = ct.subarray(fullBlocksLen);
282
+ const msg = new Uint8Array(fullBlocksLen + (cn.length > 0 ? cn.length : 0));
283
+ for (let i = 0; i + 32 <= ct.length; i += 32) {
284
+ state.decTo(ct.subarray(i, i + 32), msg.subarray(i, i + 32));
285
+ }
286
+ if (cn.length > 0) {
287
+ msg.set(state.decPartial(cn), fullBlocksLen);
288
+ }
289
+ const expectedTag = state.finalize(BigInt(ad.length * 8), BigInt(msg.length * 8), tagLen);
290
+ if (!constantTimeEqual(tag, expectedTag)) {
291
+ msg.fill(0);
292
+ return null;
293
+ }
294
+ return msg;
295
+ }
296
+ /**
297
+ * Computes a MAC (Message Authentication Code) using AEGIS-128L.
298
+ * @param data - Data to authenticate
299
+ * @param key - 16-byte key
300
+ * @param nonce - 16-byte nonce (optional, uses zero nonce if null)
301
+ * @param tagLen - Tag length: 16 or 32 bytes (default: 16)
302
+ * @returns Authentication tag
303
+ */
304
+ export function aegis128LMac(data, key, nonce = null, tagLen = 16) {
305
+ const state = new Aegis128LState();
306
+ state.init(key, nonce ?? new Uint8Array(16));
307
+ const dataPadded = zeroPad(data, 32);
308
+ for (let i = 0; i + 32 <= dataPadded.length; i += 32) {
309
+ state.absorb(dataPadded.subarray(i, i + 32));
310
+ }
311
+ return state.finalize(BigInt(data.length * 8), BigInt(tagLen * 8), tagLen);
312
+ }
313
+ /**
314
+ * Verifies a MAC computed using AEGIS-128L.
315
+ * @param data - Data to verify
316
+ * @param tag - Expected authentication tag (16 or 32 bytes)
317
+ * @param key - 16-byte key
318
+ * @param nonce - 16-byte nonce (optional, uses zero nonce if null)
319
+ * @returns True if the tag is valid, false otherwise
320
+ */
321
+ export function aegis128LMacVerify(data, tag, key, nonce = null) {
322
+ const tagLen = tag.length;
323
+ const expectedTag = aegis128LMac(data, key, nonce, tagLen);
324
+ return constantTimeEqual(tag, expectedTag);
325
+ }
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