aegis-aead 0.2.2 → 0.2.3
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 +25 -20
- package/dist/aegis128l.d.ts +33 -33
- package/dist/aegis128l.js +225 -235
- package/dist/aegis128x.d.ts +35 -35
- package/dist/aegis128x.js +348 -282
- package/dist/aegis256.d.ts +34 -51
- package/dist/aegis256.js +215 -206
- package/dist/aegis256x.d.ts +32 -33
- package/dist/aegis256x.js +333 -265
- package/dist/aes-bs.d.ts +42 -35
- package/dist/aes-bs.js +2269 -401
- package/dist/index.d.ts +4 -7
- package/dist/index.js +4 -7
- package/dist/random.d.ts +0 -1
- package/dist/random.js +0 -1
- package/dist/utils.d.ts +14 -0
- package/dist/utils.js +31 -0
- package/package.json +5 -6
- package/dist/aegis128l-bs.d.ts +0 -137
- package/dist/aegis128l-bs.d.ts.map +0 -1
- package/dist/aegis128l-bs.js +0 -442
- package/dist/aegis128l-bs.js.map +0 -1
- package/dist/aegis128l.d.ts.map +0 -1
- package/dist/aegis128l.js.map +0 -1
- package/dist/aegis128x.d.ts.map +0 -1
- package/dist/aegis128x.js.map +0 -1
- package/dist/aegis256-bs.d.ts +0 -79
- package/dist/aegis256-bs.d.ts.map +0 -1
- package/dist/aegis256-bs.js +0 -366
- package/dist/aegis256-bs.js.map +0 -1
- package/dist/aegis256.d.ts.map +0 -1
- package/dist/aegis256.js.map +0 -1
- package/dist/aegis256x.d.ts.map +0 -1
- package/dist/aegis256x.js.map +0 -1
- package/dist/aes-bs.d.ts.map +0 -1
- package/dist/aes-bs.js.map +0 -1
- package/dist/aes.d.ts +0 -81
- package/dist/aes.d.ts.map +0 -1
- package/dist/aes.js +0 -232
- package/dist/aes.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/random.d.ts.map +0 -1
- package/dist/random.js.map +0 -1
- package/src/aegis128l-bs.ts +0 -600
- package/src/aegis128l.ts +0 -653
- package/src/aegis128x.ts +0 -932
- package/src/aegis256-bs.ts +0 -519
- package/src/aegis256.ts +0 -597
- package/src/aegis256x.ts +0 -893
- package/src/aes-bs.ts +0 -540
- package/src/aes.ts +0 -271
- package/src/index.ts +0 -126
- package/src/random.ts +0 -41
- package/src/typed-array.d.ts +0 -18
package/README.md
CHANGED
|
@@ -16,6 +16,7 @@ AEGIS provides both encryption with authentication and standalone MAC functional
|
|
|
16
16
|
- [Installation](#installation)
|
|
17
17
|
- [Quick Start](#quick-start)
|
|
18
18
|
- [Choosing an Algorithm](#choosing-an-algorithm)
|
|
19
|
+
- [Performance](#performance)
|
|
19
20
|
- [Usage Examples](#usage-examples)
|
|
20
21
|
- [Combined Mode](#combined-mode)
|
|
21
22
|
- [Detached Mode](#detached-mode)
|
|
@@ -29,7 +30,7 @@ AEGIS provides both encryption with authentication and standalone MAC functional
|
|
|
29
30
|
- [Security Considerations](#security-considerations)
|
|
30
31
|
- [Nonce Safety](#nonce-safety)
|
|
31
32
|
- [Tag Lengths](#tag-lengths)
|
|
32
|
-
- [
|
|
33
|
+
- [Constant-Time Implementation](#constant-time-implementation)
|
|
33
34
|
- [Compatibility](#compatibility)
|
|
34
35
|
- [Browser Example](#browser-example)
|
|
35
36
|
|
|
@@ -59,24 +60,35 @@ const decrypted = aegis128LDecrypt(sealed, associatedData, key);
|
|
|
59
60
|
|
|
60
61
|
## Choosing an Algorithm
|
|
61
62
|
|
|
62
|
-
| Algorithm
|
|
63
|
-
|
|
|
64
|
-
| AEGIS-128L
|
|
65
|
-
| AEGIS-256
|
|
66
|
-
| AEGIS-128X
|
|
67
|
-
| AEGIS-256X
|
|
68
|
-
| AEGIS-128L-BS | 16 bytes | 16 bytes | Side-channel protection |
|
|
69
|
-
| AEGIS-256-BS | 32 bytes | 32 bytes | Side-channel + large nonce |
|
|
63
|
+
| Algorithm | Key | Nonce | Best For |
|
|
64
|
+
| ---------- | -------- | -------- | ---------------------------------------- |
|
|
65
|
+
| AEGIS-128L | 16 bytes | 16 bytes | General use, high throughput |
|
|
66
|
+
| AEGIS-256 | 32 bytes | 32 bytes | Large nonce, unlimited messages |
|
|
67
|
+
| AEGIS-128X | 16 bytes | 16 bytes | Interop with native SIMD implementations |
|
|
68
|
+
| AEGIS-256X | 32 bytes | 32 bytes | Interop + large nonce |
|
|
70
69
|
|
|
71
70
|
Recommendations:
|
|
72
71
|
|
|
73
72
|
- Default choice: AEGIS-128L offers excellent performance with safe random nonces up to 2^48 messages
|
|
74
73
|
- Unlimited messages: AEGIS-256 when you need unlimited random nonces (32-byte nonce eliminates collision risk)
|
|
75
74
|
- Interoperability: AEGIS-128X/256X when exchanging data with native implementations using these variants
|
|
76
|
-
- Hostile environments: Bitsliced variants (-BS) when attackers may observe timing
|
|
77
75
|
|
|
78
76
|
Note: The X variants are designed for SIMD parallelism in native code. In JavaScript they offer no speed benefit but are provided for interoperability.
|
|
79
77
|
|
|
78
|
+
## Performance
|
|
79
|
+
|
|
80
|
+
The numbers below come from `bun run bench` on an Apple M5 Max, with AES-GCM and ChaCha20-Poly1305 supplied by @noble/ciphers for comparison. Throughput is for combined-mode encryption with empty associated data; your mileage will vary with hardware and runtime.
|
|
81
|
+
|
|
82
|
+
| Algorithm | 64 B | 1 KB | 16 KB | 1 MB |
|
|
83
|
+
| ----------------- | ------: | -------: | -------: | -------: |
|
|
84
|
+
| AEGIS-128L | 50 MB/s | 224 MB/s | 310 MB/s | 324 MB/s |
|
|
85
|
+
| ChaCha20-Poly1305 | 36 MB/s | 175 MB/s | 248 MB/s | 256 MB/s |
|
|
86
|
+
| AEGIS-256 | 36 MB/s | 146 MB/s | 198 MB/s | 204 MB/s |
|
|
87
|
+
| AES-128-GCM | 13 MB/s | 74 MB/s | 150 MB/s | 182 MB/s |
|
|
88
|
+
| AES-256-GCM | 12 MB/s | 66 MB/s | 122 MB/s | 143 MB/s |
|
|
89
|
+
|
|
90
|
+
AEGIS-128L is the fastest option at every message size, reaching about 324 MB/s on large buffers — roughly 1.3x ChaCha20-Poly1305 and 1.8x AES-128-GCM.
|
|
91
|
+
|
|
80
92
|
## Usage Examples
|
|
81
93
|
|
|
82
94
|
### Combined Mode
|
|
@@ -155,7 +167,7 @@ const valid = aegis128LMacVerify(data, tag, key);
|
|
|
155
167
|
|
|
156
168
|
## API Overview
|
|
157
169
|
|
|
158
|
-
All AEGIS variants follow the same API pattern. Replace `aegis128L` with your chosen algorithm (`aegis256`, `aegis128X2`, `aegis128X4`, `aegis256X2`, `aegis256X4
|
|
170
|
+
All AEGIS variants follow the same API pattern. Replace `aegis128L` with your chosen algorithm (`aegis256`, `aegis128X2`, `aegis128X4`, `aegis256X2`, `aegis256X4`).
|
|
159
171
|
|
|
160
172
|
### Functions
|
|
161
173
|
|
|
@@ -221,16 +233,9 @@ All algorithms support 16-byte (128-bit) and 32-byte (256-bit) tags:
|
|
|
221
233
|
const sealed = aegis128LEncrypt(msg, ad, key, undefined, 32);
|
|
222
234
|
```
|
|
223
235
|
|
|
224
|
-
###
|
|
225
|
-
|
|
226
|
-
The `-BS` variants use a constant-time bitsliced AES implementation that doesn't use lookup tables. This prevents cache-timing attacks at the cost of ~20% performance.
|
|
227
|
-
|
|
228
|
-
Use bitsliced variants when:
|
|
229
|
-
- Running on shared infrastructure (cloud VMs, containers)
|
|
230
|
-
- Attackers may observe timing information
|
|
231
|
-
- Processing attacker-controlled data with secret keys
|
|
236
|
+
### Constant-Time Implementation
|
|
232
237
|
|
|
233
|
-
|
|
238
|
+
All variants are built on a constant-time bitsliced AES implementation that doesn't use lookup tables, which prevents cache-timing attacks. The bitsliced code processes all state blocks in a single fused round, and it is also the fastest scalar implementation we know of, so the protection comes at no cost. There is no faster table-based fallback to choose, and no reason to want one.
|
|
234
239
|
|
|
235
240
|
## Compatibility
|
|
236
241
|
|
package/dist/aegis128l.d.ts
CHANGED
|
@@ -1,25 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AEGIS-128L implementation.
|
|
3
|
+
* Built on the constant-time bitsliced AES core, which processes all 8 state
|
|
4
|
+
* blocks simultaneously without lookup tables.
|
|
5
|
+
*/
|
|
1
6
|
/**
|
|
2
7
|
* AEGIS-128L cipher state.
|
|
3
|
-
*
|
|
8
|
+
* The state is kept in packed bitsliced form between operations so that
|
|
9
|
+
* pack/unpack does not need to be applied at every round.
|
|
4
10
|
*/
|
|
5
11
|
export declare class Aegis128LState {
|
|
6
|
-
private
|
|
7
|
-
private
|
|
8
|
-
private s2;
|
|
9
|
-
private s3;
|
|
10
|
-
private s4;
|
|
11
|
-
private s5;
|
|
12
|
-
private s6;
|
|
13
|
-
private s7;
|
|
12
|
+
private st;
|
|
13
|
+
private constantInput;
|
|
14
14
|
private tmp0;
|
|
15
15
|
private tmp1;
|
|
16
16
|
private z0;
|
|
17
17
|
private z1;
|
|
18
|
-
private newS;
|
|
19
|
-
private tBuf;
|
|
20
18
|
constructor();
|
|
19
|
+
/**
|
|
20
|
+
* Returns the 8 state blocks as byte arrays (for testing).
|
|
21
|
+
*/
|
|
21
22
|
get s(): Uint8Array[];
|
|
22
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Sets the 8 state blocks from byte arrays (for testing).
|
|
25
|
+
*/
|
|
26
|
+
set s(blocks: Uint8Array[]);
|
|
23
27
|
/**
|
|
24
28
|
* Initializes the state with a key and nonce.
|
|
25
29
|
* @param key - 16-byte encryption key
|
|
@@ -31,18 +35,21 @@ export declare class Aegis128LState {
|
|
|
31
35
|
* @param m0 - First 16-byte message block
|
|
32
36
|
* @param m1 - Second 16-byte message block
|
|
33
37
|
*/
|
|
34
|
-
update(m0:
|
|
38
|
+
update(m0: Uint8Array, m1: Uint8Array): void;
|
|
35
39
|
/**
|
|
36
40
|
* Absorbs a 32-byte associated data block into the state.
|
|
37
|
-
* @param ai - 32-byte associated data block
|
|
41
|
+
* @param ai - Buffer holding the 32-byte associated data block
|
|
42
|
+
* @param off - Offset of the block within the buffer
|
|
38
43
|
*/
|
|
39
|
-
absorb(ai: Uint8Array): void;
|
|
44
|
+
absorb(ai: Uint8Array, off?: number): void;
|
|
40
45
|
/**
|
|
41
46
|
* Encrypts a 32-byte plaintext block and writes to output buffer.
|
|
42
|
-
* @param xi - 32-byte plaintext block
|
|
43
|
-
* @param out - 32-byte
|
|
47
|
+
* @param xi - Buffer holding the 32-byte plaintext block
|
|
48
|
+
* @param out - Output buffer receiving the 32-byte ciphertext block
|
|
49
|
+
* @param inOff - Offset of the plaintext block within xi
|
|
50
|
+
* @param outOff - Offset of the ciphertext block within out
|
|
44
51
|
*/
|
|
45
|
-
encTo(xi: Uint8Array, out: Uint8Array): void;
|
|
52
|
+
encTo(xi: Uint8Array, out: Uint8Array, inOff?: number, outOff?: number): void;
|
|
46
53
|
/**
|
|
47
54
|
* Encrypts a 32-byte plaintext block.
|
|
48
55
|
* @param xi - 32-byte plaintext block
|
|
@@ -51,25 +58,19 @@ export declare class Aegis128LState {
|
|
|
51
58
|
enc(xi: Uint8Array): Uint8Array;
|
|
52
59
|
/**
|
|
53
60
|
* Decrypts a 32-byte ciphertext block and writes to output buffer.
|
|
54
|
-
* @param ci - 32-byte ciphertext block
|
|
55
|
-
* @param out - 32-byte
|
|
61
|
+
* @param ci - Buffer holding the 32-byte ciphertext block
|
|
62
|
+
* @param out - Output buffer receiving the 32-byte plaintext block
|
|
63
|
+
* @param inOff - Offset of the ciphertext block within ci
|
|
64
|
+
* @param outOff - Offset of the plaintext block within out
|
|
56
65
|
*/
|
|
57
|
-
decTo(ci: Uint8Array, out: Uint8Array): void;
|
|
66
|
+
decTo(ci: Uint8Array, out: Uint8Array, inOff?: number, outOff?: number): void;
|
|
58
67
|
/**
|
|
59
68
|
* Decrypts a 32-byte ciphertext block.
|
|
60
69
|
* @param ci - 32-byte ciphertext block
|
|
61
70
|
* @returns 32-byte plaintext block
|
|
62
71
|
*/
|
|
63
72
|
dec(ci: Uint8Array): Uint8Array;
|
|
64
|
-
/**
|
|
65
|
-
* Encrypts a 32-byte plaintext block in-place.
|
|
66
|
-
* @param block - 32-byte buffer (plaintext in, ciphertext out)
|
|
67
|
-
*/
|
|
68
73
|
encInPlace(block: Uint8Array): void;
|
|
69
|
-
/**
|
|
70
|
-
* Decrypts a 32-byte ciphertext block in-place.
|
|
71
|
-
* @param block - 32-byte buffer (ciphertext in, plaintext out)
|
|
72
|
-
*/
|
|
73
74
|
decInPlace(block: Uint8Array): void;
|
|
74
75
|
/**
|
|
75
76
|
* Decrypts a partial (final) ciphertext block smaller than 32 bytes.
|
|
@@ -79,12 +80,12 @@ export declare class Aegis128LState {
|
|
|
79
80
|
decPartial(cn: Uint8Array): Uint8Array;
|
|
80
81
|
/**
|
|
81
82
|
* Finalizes encryption/decryption and produces an authentication tag.
|
|
82
|
-
* @param
|
|
83
|
-
* @param
|
|
83
|
+
* @param adLen - Associated data length in bytes
|
|
84
|
+
* @param msgLen - Message length in bytes
|
|
84
85
|
* @param tagLen - Tag length (16 or 32 bytes)
|
|
85
86
|
* @returns Authentication tag
|
|
86
87
|
*/
|
|
87
|
-
finalize(
|
|
88
|
+
finalize(adLen: number, msgLen: number, tagLen?: 16 | 32): Uint8Array;
|
|
88
89
|
}
|
|
89
90
|
/**
|
|
90
91
|
* Encrypts a message using AEGIS-128L (detached mode).
|
|
@@ -186,4 +187,3 @@ export declare function aegis128LCreateKey(): Uint8Array;
|
|
|
186
187
|
* @throws Error if no cryptographic random source is available
|
|
187
188
|
*/
|
|
188
189
|
export declare function aegis128LCreateNonce(): Uint8Array;
|
|
189
|
-
//# sourceMappingURL=aegis128l.d.ts.map
|