aegis-aead 0.1.0 → 0.2.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/README.md +239 -64
- package/dist/aegis128l-bs.d.ts +162 -0
- package/dist/aegis128l-bs.d.ts.map +1 -0
- package/dist/aegis128l-bs.js +470 -0
- package/dist/aegis128l-bs.js.map +1 -0
- package/dist/aegis128l.d.ts +42 -5
- package/dist/aegis128l.d.ts.map +1 -1
- package/dist/aegis128l.js +79 -5
- package/dist/aegis128l.js.map +1 -1
- package/dist/aegis128x.d.ts +67 -12
- package/dist/aegis128x.d.ts.map +1 -1
- package/dist/aegis128x.js +102 -9
- package/dist/aegis128x.js.map +1 -1
- package/dist/aegis256-bs.d.ts +151 -0
- package/dist/aegis256-bs.d.ts.map +1 -0
- package/dist/aegis256-bs.js +398 -0
- package/dist/aegis256-bs.js.map +1 -0
- package/dist/aegis256.d.ts +42 -5
- package/dist/aegis256.d.ts.map +1 -1
- package/dist/aegis256.js +79 -5
- package/dist/aegis256.js.map +1 -1
- package/dist/aegis256x.d.ts +67 -12
- package/dist/aegis256x.d.ts.map +1 -1
- package/dist/aegis256x.js +102 -9
- package/dist/aegis256x.js.map +1 -1
- package/dist/aes-bs.d.ts +71 -0
- package/dist/aes-bs.d.ts.map +1 -0
- package/dist/aes-bs.js +399 -0
- package/dist/aes-bs.js.map +1 -0
- package/dist/index.d.ts +6 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -4
- package/dist/index.js.map +1 -1
- package/dist/random.d.ts +22 -0
- package/dist/random.d.ts.map +1 -0
- package/dist/random.js +36 -0
- package/dist/random.js.map +1 -0
- package/package.json +1 -1
- package/src/aegis128l-bs.ts +602 -0
- package/src/aegis128l.ts +112 -5
- package/src/aegis128x.ts +174 -15
- package/src/aegis256-bs.ts +518 -0
- package/src/aegis256.ts +112 -5
- package/src/aegis256x.ts +174 -15
- package/src/aes-bs.ts +459 -0
- package/src/index.ts +66 -0
- package/src/random.ts +41 -0
package/README.md
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/aegis-aead)
|
|
4
4
|
[](https://github.com/jedisct1/js-aegis-aead/actions/workflows/ci.yml)
|
|
5
5
|
|
|
6
|
-
JavaScript
|
|
6
|
+
A compact, zero-dependency JavaScript/TypeScript implementation of [AEGIS](https://datatracker.ietf.org/doc/draft-irtf-cfrg-aegis-aead/), a family of fast, secure authenticated encryption algorithms.
|
|
7
7
|
|
|
8
|
-
AEGIS
|
|
8
|
+
AEGIS provides both encryption with authentication and standalone MAC functionality, with a simple API that makes it hard to misuse.
|
|
9
9
|
|
|
10
10
|
## Installation
|
|
11
11
|
|
|
@@ -20,48 +20,100 @@ npm install aegis-aead
|
|
|
20
20
|
### Encryption and Decryption
|
|
21
21
|
|
|
22
22
|
```typescript
|
|
23
|
-
import {
|
|
23
|
+
import {
|
|
24
|
+
aegis128LCreateKey,
|
|
25
|
+
aegis128LEncrypt,
|
|
26
|
+
aegis128LDecrypt
|
|
27
|
+
} from "aegis-aead";
|
|
24
28
|
|
|
25
|
-
const key =
|
|
26
|
-
const nonce = crypto.getRandomValues(new Uint8Array(16));
|
|
29
|
+
const key = aegis128LCreateKey(); // 16 random bytes
|
|
27
30
|
const message = new TextEncoder().encode("Hello, world!");
|
|
28
31
|
const associatedData = new TextEncoder().encode("metadata");
|
|
29
32
|
|
|
30
|
-
// Encrypt
|
|
31
|
-
|
|
33
|
+
// Encrypt - returns nonce || ciphertext || tag
|
|
34
|
+
// A random nonce is generated automatically
|
|
35
|
+
const sealed = aegis128LEncrypt(message, associatedData, key);
|
|
32
36
|
|
|
33
37
|
// Decrypt (returns null if authentication fails)
|
|
34
|
-
const decrypted = aegis128LDecrypt(
|
|
38
|
+
const decrypted = aegis128LDecrypt(sealed, associatedData, key);
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Detached Mode
|
|
42
|
+
|
|
43
|
+
For applications that need separate access to the ciphertext and tag:
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
import {
|
|
47
|
+
aegis128LCreateKey,
|
|
48
|
+
aegis128LCreateNonce,
|
|
49
|
+
aegis128LEncryptDetached,
|
|
50
|
+
aegis128LDecryptDetached
|
|
51
|
+
} from "aegis-aead";
|
|
52
|
+
|
|
53
|
+
const key = aegis128LCreateKey();
|
|
54
|
+
const nonce = aegis128LCreateNonce();
|
|
55
|
+
const message = new TextEncoder().encode("Hello, world!");
|
|
56
|
+
const associatedData = new TextEncoder().encode("metadata");
|
|
57
|
+
|
|
58
|
+
// Encrypt - returns ciphertext and tag separately
|
|
59
|
+
const { ciphertext, tag } = aegis128LEncryptDetached(message, associatedData, key, nonce);
|
|
60
|
+
|
|
61
|
+
// Decrypt
|
|
62
|
+
const decrypted = aegis128LDecryptDetached(ciphertext, tag, associatedData, key, nonce);
|
|
35
63
|
```
|
|
36
64
|
|
|
37
65
|
### MAC (Message Authentication Code)
|
|
38
66
|
|
|
39
67
|
```typescript
|
|
40
|
-
import {
|
|
68
|
+
import {
|
|
69
|
+
aegis128LCreateKey,
|
|
70
|
+
aegis128LMac,
|
|
71
|
+
aegis128LMacVerify
|
|
72
|
+
} from "aegis-aead";
|
|
41
73
|
|
|
42
|
-
const key =
|
|
43
|
-
const nonce = crypto.getRandomValues(new Uint8Array(16));
|
|
74
|
+
const key = aegis128LCreateKey();
|
|
44
75
|
const data = new TextEncoder().encode("data to authenticate");
|
|
45
76
|
|
|
46
|
-
// Generate MAC
|
|
47
|
-
const tag = aegis128LMac(data, key
|
|
77
|
+
// Generate MAC (nonce defaults to zero if not provided)
|
|
78
|
+
const tag = aegis128LMac(data, key);
|
|
48
79
|
|
|
49
80
|
// Verify MAC
|
|
50
|
-
const valid = aegis128LMacVerify(data, tag, key
|
|
81
|
+
const valid = aegis128LMacVerify(data, tag, key);
|
|
51
82
|
```
|
|
52
83
|
|
|
53
84
|
## Algorithms
|
|
54
85
|
|
|
55
|
-
| Algorithm
|
|
56
|
-
|
|
|
57
|
-
| AEGIS-128L
|
|
58
|
-
| AEGIS-256
|
|
59
|
-
| AEGIS-128X
|
|
60
|
-
| AEGIS-256X
|
|
86
|
+
| Algorithm | Key Size | Nonce Size | Block Size | Use Case |
|
|
87
|
+
| ------------- | -------- | ---------- | ---------- | ---------------------------------- |
|
|
88
|
+
| AEGIS-128L | 16 bytes | 16 bytes | 32 bytes | High throughput on 64-bit CPUs |
|
|
89
|
+
| AEGIS-256 | 32 bytes | 32 bytes | 16 bytes | 256-bit security level |
|
|
90
|
+
| AEGIS-128X | 16 bytes | 16 bytes | 32×D bytes | Multi-lane AEGIS-128L (D = degree) |
|
|
91
|
+
| AEGIS-256X | 32 bytes | 32 bytes | 16×D bytes | Multi-lane AEGIS-256 (D = degree) |
|
|
92
|
+
| AEGIS-128L-BS | 16 bytes | 16 bytes | 32 bytes | Bitsliced |
|
|
93
|
+
| AEGIS-256-BS | 32 bytes | 32 bytes | 16 bytes | Bitsliced |
|
|
94
|
+
|
|
95
|
+
### Bitsliced Variants
|
|
96
|
+
|
|
97
|
+
The `-BS` (bitsliced) variants provide protection against cache-timing side-channel attacks at the cost of ~20% performance overhead. They process AES operations without lookup tables, making execution time independent of the key and data values.
|
|
98
|
+
|
|
99
|
+
Use the bitsliced variants when:
|
|
100
|
+
- Adversaries may be able to observe timing information (shared hosting, cloud VMs)
|
|
101
|
+
- The key holder may encrypt or decrypt attacker-controlled data
|
|
102
|
+
- Maximum side-channel resistance is required
|
|
103
|
+
|
|
104
|
+
For most use cases, the standard implementations are safe since AEGIS's continuous state mixing makes practical timing attacks extremely difficult.
|
|
105
|
+
|
|
106
|
+
### Random Nonces
|
|
107
|
+
|
|
108
|
+
When using random nonces (the default for combined-mode functions):
|
|
109
|
+
|
|
110
|
+
- AEGIS-128L/128X: Safe for up to 2^48 messages per key, regardless of their size
|
|
111
|
+
- AEGIS-256/256X: No practical limits on the number of messages per key
|
|
61
112
|
|
|
62
113
|
### Tag Lengths
|
|
63
114
|
|
|
64
115
|
All algorithms support two tag lengths:
|
|
116
|
+
|
|
65
117
|
- 16 bytes (128-bit) - default
|
|
66
118
|
- 32 bytes (256-bit) - pass `32` as the last parameter to encrypt/MAC functions
|
|
67
119
|
|
|
@@ -70,19 +122,49 @@ All algorithms support two tag lengths:
|
|
|
70
122
|
### AEGIS-128L
|
|
71
123
|
|
|
72
124
|
```typescript
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
125
|
+
// Key/Nonce generation
|
|
126
|
+
aegis128LCreateKey(): Uint8Array // 16 random bytes
|
|
127
|
+
aegis128LCreateNonce(): Uint8Array // 16 random bytes
|
|
128
|
+
|
|
129
|
+
// Combined (nonce || ciphertext || tag)
|
|
130
|
+
aegis128LEncrypt(msg, ad, key, nonce?, tagLen?): Uint8Array
|
|
131
|
+
aegis128LDecrypt(sealed, ad, key, tagLen?): Uint8Array | null
|
|
132
|
+
|
|
133
|
+
// Detached (separate ciphertext and tag)
|
|
134
|
+
aegis128LEncryptDetached(msg, ad, key, nonce, tagLen?): { ciphertext, tag }
|
|
135
|
+
aegis128LDecryptDetached(ciphertext, tag, ad, key, nonce): Uint8Array | null
|
|
136
|
+
|
|
137
|
+
// MAC (nonce is optional, defaults to zero)
|
|
138
|
+
aegis128LMac(data, key, nonce?, tagLen?): Uint8Array
|
|
139
|
+
aegis128LMacVerify(data, tag, key, nonce?): boolean
|
|
140
|
+
|
|
141
|
+
// Constants
|
|
142
|
+
AEGIS_128L_KEY_SIZE // 16
|
|
143
|
+
AEGIS_128L_NONCE_SIZE // 16
|
|
77
144
|
```
|
|
78
145
|
|
|
79
146
|
### AEGIS-256
|
|
80
147
|
|
|
81
148
|
```typescript
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
149
|
+
// Key/Nonce generation
|
|
150
|
+
aegis256CreateKey(): Uint8Array // 32 random bytes
|
|
151
|
+
aegis256CreateNonce(): Uint8Array // 32 random bytes
|
|
152
|
+
|
|
153
|
+
// Combined (nonce || ciphertext || tag)
|
|
154
|
+
aegis256Encrypt(msg, ad, key, nonce?, tagLen?): Uint8Array
|
|
155
|
+
aegis256Decrypt(sealed, ad, key, tagLen?): Uint8Array | null
|
|
156
|
+
|
|
157
|
+
// Detached (separate ciphertext and tag)
|
|
158
|
+
aegis256EncryptDetached(msg, ad, key, nonce, tagLen?): { ciphertext, tag }
|
|
159
|
+
aegis256DecryptDetached(ciphertext, tag, ad, key, nonce): Uint8Array | null
|
|
160
|
+
|
|
161
|
+
// MAC (nonce is optional, defaults to zero)
|
|
162
|
+
aegis256Mac(data, key, nonce?, tagLen?): Uint8Array
|
|
163
|
+
aegis256MacVerify(data, tag, key, nonce?): boolean
|
|
164
|
+
|
|
165
|
+
// Constants
|
|
166
|
+
AEGIS_256_KEY_SIZE // 32
|
|
167
|
+
AEGIS_256_NONCE_SIZE // 32
|
|
86
168
|
```
|
|
87
169
|
|
|
88
170
|
### AEGIS-128X
|
|
@@ -90,23 +172,43 @@ aegis256MacVerify(data, tag, key, nonce): boolean
|
|
|
90
172
|
Pre-configured variants for degree 2 and 4:
|
|
91
173
|
|
|
92
174
|
```typescript
|
|
93
|
-
//
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
175
|
+
// Key/Nonce generation
|
|
176
|
+
aegis128XCreateKey(): Uint8Array // 16 random bytes
|
|
177
|
+
aegis128XCreateNonce(): Uint8Array // 16 random bytes
|
|
178
|
+
aegis128X2CreateKey(): Uint8Array // alias
|
|
179
|
+
aegis128X2CreateNonce(): Uint8Array
|
|
180
|
+
aegis128X4CreateKey(): Uint8Array // alias
|
|
181
|
+
aegis128X4CreateNonce(): Uint8Array
|
|
182
|
+
|
|
183
|
+
// Combined (nonce || ciphertext || tag)
|
|
184
|
+
aegis128X2Encrypt(msg, ad, key, nonce?, tagLen?): Uint8Array
|
|
185
|
+
aegis128X2Decrypt(sealed, ad, key, tagLen?): Uint8Array | null
|
|
186
|
+
aegis128X4Encrypt(msg, ad, key, nonce?, tagLen?): Uint8Array
|
|
187
|
+
aegis128X4Decrypt(sealed, ad, key, tagLen?): Uint8Array | null
|
|
188
|
+
|
|
189
|
+
// Detached (separate ciphertext and tag)
|
|
190
|
+
aegis128X2EncryptDetached(msg, ad, key, nonce, tagLen?): { ciphertext, tag }
|
|
191
|
+
aegis128X2DecryptDetached(ciphertext, tag, ad, key, nonce): Uint8Array | null
|
|
192
|
+
aegis128X4EncryptDetached(msg, ad, key, nonce, tagLen?): { ciphertext, tag }
|
|
193
|
+
aegis128X4DecryptDetached(ciphertext, tag, ad, key, nonce): Uint8Array | null
|
|
194
|
+
|
|
195
|
+
// MAC (nonce is optional, defaults to zero)
|
|
196
|
+
aegis128X2Mac(data, key, nonce?, tagLen?): Uint8Array
|
|
197
|
+
aegis128X2MacVerify(data, tag, key, nonce?): boolean
|
|
198
|
+
aegis128X4Mac(data, key, nonce?, tagLen?): Uint8Array
|
|
199
|
+
aegis128X4MacVerify(data, tag, key, nonce?): boolean
|
|
104
200
|
|
|
105
201
|
// Custom degree
|
|
106
|
-
aegis128XEncrypt(msg, ad, key, nonce
|
|
107
|
-
aegis128XDecrypt(
|
|
108
|
-
|
|
109
|
-
|
|
202
|
+
aegis128XEncrypt(msg, ad, key, nonce?, tagLen?, degree?): Uint8Array
|
|
203
|
+
aegis128XDecrypt(sealed, ad, key, tagLen?, degree?): Uint8Array | null
|
|
204
|
+
aegis128XEncryptDetached(msg, ad, key, nonce, tagLen?, degree?): { ciphertext, tag }
|
|
205
|
+
aegis128XDecryptDetached(ciphertext, tag, ad, key, nonce, degree?): Uint8Array | null
|
|
206
|
+
aegis128XMac(data, key, nonce?, tagLen?, degree?): Uint8Array
|
|
207
|
+
aegis128XMacVerify(data, tag, key, nonce?, degree?): boolean
|
|
208
|
+
|
|
209
|
+
// Constants
|
|
210
|
+
AEGIS_128X_KEY_SIZE // 16
|
|
211
|
+
AEGIS_128X_NONCE_SIZE // 16
|
|
110
212
|
```
|
|
111
213
|
|
|
112
214
|
### AEGIS-256X
|
|
@@ -114,23 +216,91 @@ aegis128XMacVerify(data, tag, key, nonce, degree?): boolean
|
|
|
114
216
|
Pre-configured variants for degree 2 and 4:
|
|
115
217
|
|
|
116
218
|
```typescript
|
|
117
|
-
//
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
219
|
+
// Key/Nonce generation
|
|
220
|
+
aegis256XCreateKey(): Uint8Array // 32 random bytes
|
|
221
|
+
aegis256XCreateNonce(): Uint8Array // 32 random bytes
|
|
222
|
+
aegis256X2CreateKey(): Uint8Array // alias
|
|
223
|
+
aegis256X2CreateNonce(): Uint8Array
|
|
224
|
+
aegis256X4CreateKey(): Uint8Array // alias
|
|
225
|
+
aegis256X4CreateNonce(): Uint8Array
|
|
226
|
+
|
|
227
|
+
// Combined (nonce || ciphertext || tag)
|
|
228
|
+
aegis256X2Encrypt(msg, ad, key, nonce?, tagLen?): Uint8Array
|
|
229
|
+
aegis256X2Decrypt(sealed, ad, key, tagLen?): Uint8Array | null
|
|
230
|
+
aegis256X4Encrypt(msg, ad, key, nonce?, tagLen?): Uint8Array
|
|
231
|
+
aegis256X4Decrypt(sealed, ad, key, tagLen?): Uint8Array | null
|
|
232
|
+
|
|
233
|
+
// Detached (separate ciphertext and tag)
|
|
234
|
+
aegis256X2EncryptDetached(msg, ad, key, nonce, tagLen?): { ciphertext, tag }
|
|
235
|
+
aegis256X2DecryptDetached(ciphertext, tag, ad, key, nonce): Uint8Array | null
|
|
236
|
+
aegis256X4EncryptDetached(msg, ad, key, nonce, tagLen?): { ciphertext, tag }
|
|
237
|
+
aegis256X4DecryptDetached(ciphertext, tag, ad, key, nonce): Uint8Array | null
|
|
238
|
+
|
|
239
|
+
// MAC (nonce is optional, defaults to zero)
|
|
240
|
+
aegis256X2Mac(data, key, nonce?, tagLen?): Uint8Array
|
|
241
|
+
aegis256X2MacVerify(data, tag, key, nonce?): boolean
|
|
242
|
+
aegis256X4Mac(data, key, nonce?, tagLen?): Uint8Array
|
|
243
|
+
aegis256X4MacVerify(data, tag, key, nonce?): boolean
|
|
128
244
|
|
|
129
245
|
// Custom degree
|
|
130
|
-
aegis256XEncrypt(msg, ad, key, nonce
|
|
131
|
-
aegis256XDecrypt(
|
|
132
|
-
|
|
133
|
-
|
|
246
|
+
aegis256XEncrypt(msg, ad, key, nonce?, tagLen?, degree?): Uint8Array
|
|
247
|
+
aegis256XDecrypt(sealed, ad, key, tagLen?, degree?): Uint8Array | null
|
|
248
|
+
aegis256XEncryptDetached(msg, ad, key, nonce, tagLen?, degree?): { ciphertext, tag }
|
|
249
|
+
aegis256XDecryptDetached(ciphertext, tag, ad, key, nonce, degree?): Uint8Array | null
|
|
250
|
+
aegis256XMac(data, key, nonce?, tagLen?, degree?): Uint8Array
|
|
251
|
+
aegis256XMacVerify(data, tag, key, nonce?, degree?): boolean
|
|
252
|
+
|
|
253
|
+
// Constants
|
|
254
|
+
AEGIS_256X_KEY_SIZE // 32
|
|
255
|
+
AEGIS_256X_NONCE_SIZE // 32
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
### AEGIS-128L-BS (Bitsliced)
|
|
259
|
+
|
|
260
|
+
```typescript
|
|
261
|
+
// Key/Nonce generation
|
|
262
|
+
aegis128LBsCreateKey(): Uint8Array // 16 random bytes
|
|
263
|
+
aegis128LBsCreateNonce(): Uint8Array // 16 random bytes
|
|
264
|
+
|
|
265
|
+
// Combined (nonce || ciphertext || tag)
|
|
266
|
+
aegis128LBsEncrypt(msg, ad, key, nonce?, tagLen?): Uint8Array
|
|
267
|
+
aegis128LBsDecrypt(sealed, ad, key, tagLen?): Uint8Array | null
|
|
268
|
+
|
|
269
|
+
// Detached (separate ciphertext and tag)
|
|
270
|
+
aegis128LBsEncryptDetached(msg, ad, key, nonce, tagLen?): { ciphertext, tag }
|
|
271
|
+
aegis128LBsDecryptDetached(ciphertext, tag, ad, key, nonce): Uint8Array | null
|
|
272
|
+
|
|
273
|
+
// MAC (nonce is optional, defaults to zero)
|
|
274
|
+
aegis128LBsMac(data, key, nonce?, tagLen?): Uint8Array
|
|
275
|
+
aegis128LBsMacVerify(data, tag, key, nonce?): boolean
|
|
276
|
+
|
|
277
|
+
// Constants
|
|
278
|
+
AEGIS_128L_BS_KEY_SIZE // 16
|
|
279
|
+
AEGIS_128L_BS_NONCE_SIZE // 16
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
### AEGIS-256-BS (Bitsliced)
|
|
283
|
+
|
|
284
|
+
```typescript
|
|
285
|
+
// Key/Nonce generation
|
|
286
|
+
aegis256BsCreateKey(): Uint8Array // 32 random bytes
|
|
287
|
+
aegis256BsCreateNonce(): Uint8Array // 32 random bytes
|
|
288
|
+
|
|
289
|
+
// Combined (nonce || ciphertext || tag)
|
|
290
|
+
aegis256BsEncrypt(msg, ad, key, nonce?, tagLen?): Uint8Array
|
|
291
|
+
aegis256BsDecrypt(sealed, ad, key, tagLen?): Uint8Array | null
|
|
292
|
+
|
|
293
|
+
// Detached (separate ciphertext and tag)
|
|
294
|
+
aegis256BsEncryptDetached(msg, ad, key, nonce, tagLen?): { ciphertext, tag }
|
|
295
|
+
aegis256BsDecryptDetached(ciphertext, tag, ad, key, nonce): Uint8Array | null
|
|
296
|
+
|
|
297
|
+
// MAC (nonce is optional, defaults to zero)
|
|
298
|
+
aegis256BsMac(data, key, nonce?, tagLen?): Uint8Array
|
|
299
|
+
aegis256BsMacVerify(data, tag, key, nonce?): boolean
|
|
300
|
+
|
|
301
|
+
// Constants
|
|
302
|
+
AEGIS_256_BS_KEY_SIZE // 32
|
|
303
|
+
AEGIS_256_BS_NONCE_SIZE // 32
|
|
134
304
|
```
|
|
135
305
|
|
|
136
306
|
## Browser Example
|
|
@@ -144,12 +314,17 @@ open examples/index.html
|
|
|
144
314
|
|
|
145
315
|
The example demonstrates encryption/decryption with a simple UI where you can enter a message, encrypt it, and decrypt it back.
|
|
146
316
|
|
|
147
|
-
##
|
|
317
|
+
## Compatibility
|
|
318
|
+
|
|
319
|
+
The key/nonce generation functions use the Web Crypto API (`globalThis.crypto.getRandomValues`) which is available in:
|
|
320
|
+
|
|
321
|
+
- All modern browsers
|
|
322
|
+
- Node.js 18+
|
|
323
|
+
- Deno
|
|
324
|
+
- Bun
|
|
148
325
|
|
|
149
|
-
|
|
150
|
-
- Decryption returns `null` on authentication failure; do not use any partial output
|
|
151
|
-
- Tag verification uses constant-time comparison
|
|
326
|
+
## Interoperability
|
|
152
327
|
|
|
153
|
-
|
|
328
|
+
This library follows the [AEGIS IETF draft specification](https://datatracker.ietf.org/doc/draft-irtf-cfrg-aegis-aead/) and can exchange encrypted messages with any compliant implementation, including native libraries in C, Rust, Go, Zig, and more.
|
|
154
329
|
|
|
155
|
-
|
|
330
|
+
See the [full list of AEGIS implementations](https://github.com/cfrg/draft-irtf-cfrg-aegis-aead?tab=readme-ov-file#known-implementations).
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bitsliced AEGIS-128L implementation.
|
|
3
|
+
* Provides constant-time operation by processing all 8 state blocks simultaneously.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Bitsliced AEGIS-128L cipher state.
|
|
7
|
+
* Uses 8 AES blocks (128 bytes) stored in bitsliced form (32 uint32 words).
|
|
8
|
+
*/
|
|
9
|
+
export declare class Aegis128LBsState {
|
|
10
|
+
private st;
|
|
11
|
+
private st1;
|
|
12
|
+
private tmp0;
|
|
13
|
+
private tmp1;
|
|
14
|
+
private z0;
|
|
15
|
+
private z1;
|
|
16
|
+
constructor();
|
|
17
|
+
/**
|
|
18
|
+
* AEGIS round function: applies AES round to all blocks and rotates.
|
|
19
|
+
* st[i] = AES(st[i]) ^ st[(i-1) mod 8]
|
|
20
|
+
*/
|
|
21
|
+
private aegisRound;
|
|
22
|
+
/**
|
|
23
|
+
* AEGIS round function with constant input (used in packed mode).
|
|
24
|
+
*/
|
|
25
|
+
private aegisRoundPacked;
|
|
26
|
+
/**
|
|
27
|
+
* Pack constant input for blocks 0 and 4.
|
|
28
|
+
*/
|
|
29
|
+
private packConstantInput;
|
|
30
|
+
/**
|
|
31
|
+
* Absorb rate: XOR message blocks into state positions 0 and 4.
|
|
32
|
+
*/
|
|
33
|
+
private absorbRate;
|
|
34
|
+
/**
|
|
35
|
+
* Update state with two message blocks.
|
|
36
|
+
*/
|
|
37
|
+
private update;
|
|
38
|
+
/**
|
|
39
|
+
* Initializes the state with a key and nonce.
|
|
40
|
+
* @param key - 16-byte encryption key
|
|
41
|
+
* @param nonce - 16-byte nonce (must be unique per message)
|
|
42
|
+
*/
|
|
43
|
+
init(key: Uint8Array, nonce: Uint8Array): void;
|
|
44
|
+
/**
|
|
45
|
+
* Absorbs a 32-byte associated data block into the state.
|
|
46
|
+
* @param ai - 32-byte associated data block
|
|
47
|
+
*/
|
|
48
|
+
absorb(ai: Uint8Array): void;
|
|
49
|
+
/**
|
|
50
|
+
* Encrypts a 32-byte plaintext block and writes to output buffer.
|
|
51
|
+
* @param xi - 32-byte plaintext block
|
|
52
|
+
* @param out - 32-byte output buffer
|
|
53
|
+
*/
|
|
54
|
+
encTo(xi: Uint8Array, out: Uint8Array): void;
|
|
55
|
+
/**
|
|
56
|
+
* Encrypts a 32-byte plaintext block.
|
|
57
|
+
* @param xi - 32-byte plaintext block
|
|
58
|
+
* @returns 32-byte ciphertext block
|
|
59
|
+
*/
|
|
60
|
+
enc(xi: Uint8Array): Uint8Array;
|
|
61
|
+
/**
|
|
62
|
+
* Decrypts a 32-byte ciphertext block and writes to output buffer.
|
|
63
|
+
* @param ci - 32-byte ciphertext block
|
|
64
|
+
* @param out - 32-byte output buffer
|
|
65
|
+
*/
|
|
66
|
+
decTo(ci: Uint8Array, out: Uint8Array): void;
|
|
67
|
+
/**
|
|
68
|
+
* Decrypts a 32-byte ciphertext block.
|
|
69
|
+
* @param ci - 32-byte ciphertext block
|
|
70
|
+
* @returns 32-byte plaintext block
|
|
71
|
+
*/
|
|
72
|
+
dec(ci: Uint8Array): Uint8Array;
|
|
73
|
+
/**
|
|
74
|
+
* Decrypts a partial (final) ciphertext block smaller than 32 bytes.
|
|
75
|
+
* @param cn - Partial ciphertext block (1-31 bytes)
|
|
76
|
+
* @returns Decrypted plaintext of the same length
|
|
77
|
+
*/
|
|
78
|
+
decPartial(cn: Uint8Array): Uint8Array;
|
|
79
|
+
/**
|
|
80
|
+
* Finalizes encryption/decryption and produces an authentication tag.
|
|
81
|
+
* @param adLen - Associated data length in bytes
|
|
82
|
+
* @param msgLen - Message length in bytes
|
|
83
|
+
* @param tagLen - Tag length (16 or 32 bytes)
|
|
84
|
+
* @returns Authentication tag
|
|
85
|
+
*/
|
|
86
|
+
finalize(adLen: number, msgLen: number, tagLen?: 16 | 32): Uint8Array;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Encrypts a message using bitsliced AEGIS-128L (detached mode).
|
|
90
|
+
* @param msg - Plaintext message
|
|
91
|
+
* @param ad - Associated data (authenticated but not encrypted)
|
|
92
|
+
* @param key - 16-byte encryption key
|
|
93
|
+
* @param nonce - 16-byte nonce (must be unique per message with the same key)
|
|
94
|
+
* @param tagLen - Authentication tag length: 16 or 32 bytes (default: 16)
|
|
95
|
+
* @returns Object containing ciphertext and authentication tag separately
|
|
96
|
+
*/
|
|
97
|
+
export declare function aegis128LBsEncryptDetached(msg: Uint8Array, ad: Uint8Array, key: Uint8Array, nonce: Uint8Array, tagLen?: 16 | 32): {
|
|
98
|
+
ciphertext: Uint8Array;
|
|
99
|
+
tag: Uint8Array;
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Decrypts a message using bitsliced AEGIS-128L (detached mode).
|
|
103
|
+
* @param ct - Ciphertext
|
|
104
|
+
* @param tag - Authentication tag (16 or 32 bytes)
|
|
105
|
+
* @param ad - Associated data (must match what was used during encryption)
|
|
106
|
+
* @param key - 16-byte encryption key
|
|
107
|
+
* @param nonce - 16-byte nonce (must match what was used during encryption)
|
|
108
|
+
* @returns Decrypted plaintext, or null if authentication fails
|
|
109
|
+
*/
|
|
110
|
+
export declare function aegis128LBsDecryptDetached(ct: Uint8Array, tag: Uint8Array, ad: Uint8Array, key: Uint8Array, nonce: Uint8Array): Uint8Array | null;
|
|
111
|
+
export declare const AEGIS_128L_BS_NONCE_SIZE = 16;
|
|
112
|
+
export declare const AEGIS_128L_BS_KEY_SIZE = 16;
|
|
113
|
+
/**
|
|
114
|
+
* Encrypts a message using bitsliced AEGIS-128L.
|
|
115
|
+
* Returns a single buffer containing nonce || ciphertext || tag.
|
|
116
|
+
* @param msg - Plaintext message
|
|
117
|
+
* @param ad - Associated data (authenticated but not encrypted)
|
|
118
|
+
* @param key - 16-byte encryption key
|
|
119
|
+
* @param nonce - 16-byte nonce (optional, generates random nonce if not provided)
|
|
120
|
+
* @param tagLen - Authentication tag length: 16 or 32 bytes (default: 16)
|
|
121
|
+
* @returns Concatenated nonce || ciphertext || tag
|
|
122
|
+
*/
|
|
123
|
+
export declare function aegis128LBsEncrypt(msg: Uint8Array, ad: Uint8Array, key: Uint8Array, nonce?: Uint8Array | null, tagLen?: 16 | 32): Uint8Array;
|
|
124
|
+
/**
|
|
125
|
+
* Decrypts a message using bitsliced AEGIS-128L.
|
|
126
|
+
* Expects input as nonce || ciphertext || tag.
|
|
127
|
+
* @param sealed - Concatenated nonce || ciphertext || tag
|
|
128
|
+
* @param ad - Associated data (must match what was used during encryption)
|
|
129
|
+
* @param key - 16-byte encryption key
|
|
130
|
+
* @param tagLen - Authentication tag length: 16 or 32 bytes (default: 16)
|
|
131
|
+
* @returns Decrypted plaintext, or null if authentication fails
|
|
132
|
+
*/
|
|
133
|
+
export declare function aegis128LBsDecrypt(sealed: Uint8Array, ad: Uint8Array, key: Uint8Array, tagLen?: 16 | 32): Uint8Array | null;
|
|
134
|
+
/**
|
|
135
|
+
* Computes a MAC (Message Authentication Code) using bitsliced AEGIS-128L.
|
|
136
|
+
* @param data - Data to authenticate
|
|
137
|
+
* @param key - 16-byte key
|
|
138
|
+
* @param nonce - 16-byte nonce (optional, uses zero nonce if null)
|
|
139
|
+
* @param tagLen - Tag length: 16 or 32 bytes (default: 16)
|
|
140
|
+
* @returns Authentication tag
|
|
141
|
+
*/
|
|
142
|
+
export declare function aegis128LBsMac(data: Uint8Array, key: Uint8Array, nonce?: Uint8Array | null, tagLen?: 16 | 32): Uint8Array;
|
|
143
|
+
/**
|
|
144
|
+
* Verifies a MAC computed using bitsliced AEGIS-128L.
|
|
145
|
+
* @param data - Data to verify
|
|
146
|
+
* @param tag - Expected authentication tag (16 or 32 bytes)
|
|
147
|
+
* @param key - 16-byte key
|
|
148
|
+
* @param nonce - 16-byte nonce (optional, uses zero nonce if null)
|
|
149
|
+
* @returns True if the tag is valid, false otherwise
|
|
150
|
+
*/
|
|
151
|
+
export declare function aegis128LBsMacVerify(data: Uint8Array, tag: Uint8Array, key: Uint8Array, nonce?: Uint8Array | null): boolean;
|
|
152
|
+
/**
|
|
153
|
+
* Generates a random 16-byte key for bitsliced AEGIS-128L.
|
|
154
|
+
* @returns 16-byte encryption key
|
|
155
|
+
*/
|
|
156
|
+
export declare function aegis128LBsCreateKey(): Uint8Array;
|
|
157
|
+
/**
|
|
158
|
+
* Generates a random 16-byte nonce for bitsliced AEGIS-128L.
|
|
159
|
+
* @returns 16-byte nonce
|
|
160
|
+
*/
|
|
161
|
+
export declare function aegis128LBsCreateNonce(): Uint8Array;
|
|
162
|
+
//# sourceMappingURL=aegis128l-bs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aegis128l-bs.d.ts","sourceRoot":"","sources":["../src/aegis128l-bs.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA+BH;;;GAGG;AACH,qBAAa,gBAAgB;IAC5B,OAA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