aegis-aead 0.2.1 → 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.
Files changed (55) hide show
  1. package/README.md +29 -22
  2. package/dist/aegis128l.d.ts +33 -33
  3. package/dist/aegis128l.js +225 -235
  4. package/dist/aegis128x.d.ts +35 -35
  5. package/dist/aegis128x.js +348 -282
  6. package/dist/aegis256.d.ts +34 -51
  7. package/dist/aegis256.js +215 -206
  8. package/dist/aegis256x.d.ts +32 -33
  9. package/dist/aegis256x.js +333 -265
  10. package/dist/aes-bs.d.ts +46 -23
  11. package/dist/aes-bs.js +2273 -331
  12. package/dist/index.d.ts +4 -7
  13. package/dist/index.js +4 -7
  14. package/dist/random.d.ts +0 -1
  15. package/dist/random.js +0 -1
  16. package/dist/utils.d.ts +14 -0
  17. package/dist/utils.js +31 -0
  18. package/package.json +6 -6
  19. package/dist/aegis128l-bs.d.ts +0 -194
  20. package/dist/aegis128l-bs.d.ts.map +0 -1
  21. package/dist/aegis128l-bs.js +0 -549
  22. package/dist/aegis128l-bs.js.map +0 -1
  23. package/dist/aegis128l.d.ts.map +0 -1
  24. package/dist/aegis128l.js.map +0 -1
  25. package/dist/aegis128x.d.ts.map +0 -1
  26. package/dist/aegis128x.js.map +0 -1
  27. package/dist/aegis256-bs.d.ts +0 -183
  28. package/dist/aegis256-bs.d.ts.map +0 -1
  29. package/dist/aegis256-bs.js +0 -477
  30. package/dist/aegis256-bs.js.map +0 -1
  31. package/dist/aegis256.d.ts.map +0 -1
  32. package/dist/aegis256.js.map +0 -1
  33. package/dist/aegis256x.d.ts.map +0 -1
  34. package/dist/aegis256x.js.map +0 -1
  35. package/dist/aes-bs.d.ts.map +0 -1
  36. package/dist/aes-bs.js.map +0 -1
  37. package/dist/aes.d.ts +0 -81
  38. package/dist/aes.d.ts.map +0 -1
  39. package/dist/aes.js +0 -232
  40. package/dist/aes.js.map +0 -1
  41. package/dist/index.d.ts.map +0 -1
  42. package/dist/index.js.map +0 -1
  43. package/dist/random.d.ts.map +0 -1
  44. package/dist/random.js.map +0 -1
  45. package/src/aegis128l-bs.ts +0 -709
  46. package/src/aegis128l.ts +0 -653
  47. package/src/aegis128x.ts +0 -932
  48. package/src/aegis256-bs.ts +0 -625
  49. package/src/aegis256.ts +0 -597
  50. package/src/aegis256x.ts +0 -893
  51. package/src/aes-bs.ts +0 -459
  52. package/src/aes.ts +0 -271
  53. package/src/index.ts +0 -126
  54. package/src/random.ts +0 -41
  55. package/src/typed-array.d.ts +0 -18
package/README.md CHANGED
@@ -1,19 +1,22 @@
1
- # aegis-aead
1
+ # AEGIS for JavaScript
2
2
 
3
3
  [![npm](https://img.shields.io/npm/v/aegis-aead)](https://www.npmjs.com/package/aegis-aead)
4
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
5
 
6
+ [View on npm](https://www.npmjs.com/package/aegis-aead)
7
+
6
8
  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
9
 
8
10
  AEGIS provides both encryption with authentication and standalone MAC functionality, with a simple API that makes it hard to misuse.
9
11
 
10
12
  ## Table of Contents
11
13
 
12
- - [aegis-aead](#aegis-aead)
14
+ - [AEGIS for JavaScript](#aegis-for-javascript)
13
15
  - [Table of Contents](#table-of-contents)
14
16
  - [Installation](#installation)
15
17
  - [Quick Start](#quick-start)
16
18
  - [Choosing an Algorithm](#choosing-an-algorithm)
19
+ - [Performance](#performance)
17
20
  - [Usage Examples](#usage-examples)
18
21
  - [Combined Mode](#combined-mode)
19
22
  - [Detached Mode](#detached-mode)
@@ -27,7 +30,7 @@ AEGIS provides both encryption with authentication and standalone MAC functional
27
30
  - [Security Considerations](#security-considerations)
28
31
  - [Nonce Safety](#nonce-safety)
29
32
  - [Tag Lengths](#tag-lengths)
30
- - [Bitsliced Variants](#bitsliced-variants)
33
+ - [Constant-Time Implementation](#constant-time-implementation)
31
34
  - [Compatibility](#compatibility)
32
35
  - [Browser Example](#browser-example)
33
36
 
@@ -57,24 +60,35 @@ const decrypted = aegis128LDecrypt(sealed, associatedData, key);
57
60
 
58
61
  ## Choosing an Algorithm
59
62
 
60
- | Algorithm | Key | Nonce | Best For |
61
- | ------------- | -------- | -------- | ---------------------------------------- |
62
- | AEGIS-128L | 16 bytes | 16 bytes | General use, high throughput |
63
- | AEGIS-256 | 32 bytes | 32 bytes | Large nonce, unlimited messages |
64
- | AEGIS-128X | 16 bytes | 16 bytes | Interop with native SIMD implementations |
65
- | AEGIS-256X | 32 bytes | 32 bytes | Interop + large nonce |
66
- | AEGIS-128L-BS | 16 bytes | 16 bytes | Side-channel protection |
67
- | 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 |
68
69
 
69
70
  Recommendations:
70
71
 
71
72
  - Default choice: AEGIS-128L offers excellent performance with safe random nonces up to 2^48 messages
72
73
  - Unlimited messages: AEGIS-256 when you need unlimited random nonces (32-byte nonce eliminates collision risk)
73
74
  - Interoperability: AEGIS-128X/256X when exchanging data with native implementations using these variants
74
- - Hostile environments: Bitsliced variants (-BS) when attackers may observe timing
75
75
 
76
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.
77
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
+
78
92
  ## Usage Examples
79
93
 
80
94
  ### Combined Mode
@@ -153,7 +167,7 @@ const valid = aegis128LMacVerify(data, tag, key);
153
167
 
154
168
  ## API Overview
155
169
 
156
- All AEGIS variants follow the same API pattern. Replace `aegis128L` with your chosen algorithm (`aegis256`, `aegis128X2`, `aegis128X4`, `aegis256X2`, `aegis256X4`, `aegis128LBs`, `aegis256Bs`).
170
+ All AEGIS variants follow the same API pattern. Replace `aegis128L` with your chosen algorithm (`aegis256`, `aegis128X2`, `aegis128X4`, `aegis256X2`, `aegis256X4`).
157
171
 
158
172
  ### Functions
159
173
 
@@ -219,16 +233,9 @@ All algorithms support 16-byte (128-bit) and 32-byte (256-bit) tags:
219
233
  const sealed = aegis128LEncrypt(msg, ad, key, undefined, 32);
220
234
  ```
221
235
 
222
- ### Bitsliced Variants
223
-
224
- 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.
225
-
226
- Use bitsliced variants when:
227
- - Running on shared infrastructure (cloud VMs, containers)
228
- - Attackers may observe timing information
229
- - Processing attacker-controlled data with secret keys
236
+ ### Constant-Time Implementation
230
237
 
231
- For most applications, standard variants are safe since AEGIS's continuous state mixing makes timing attacks impractical.
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.
232
239
 
233
240
  ## Compatibility
234
241
 
@@ -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
- * Uses 8 AES blocks (128 bytes) of internal state and processes 32-byte blocks.
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 s0;
7
- private s1;
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
- set s(states: Uint8Array[]);
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: ArrayLike<number>, m1: ArrayLike<number>): void;
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 output buffer
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 output buffer
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 adLenBits - Associated data length in bits
83
- * @param msgLenBits - Message length in bits
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(adLenBits: bigint, msgLenBits: bigint, tagLen?: 16 | 32): Uint8Array;
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