aegis-aead 0.1.1 → 0.2.1
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 +195 -89
- package/dist/aegis128l-bs.d.ts +194 -0
- package/dist/aegis128l-bs.d.ts.map +1 -0
- package/dist/aegis128l-bs.js +549 -0
- package/dist/aegis128l-bs.js.map +1 -0
- package/dist/aegis128l.d.ts +74 -5
- package/dist/aegis128l.d.ts.map +1 -1
- package/dist/aegis128l.js +173 -5
- package/dist/aegis128l.js.map +1 -1
- package/dist/aegis128x.d.ts +109 -12
- package/dist/aegis128x.d.ts.map +1 -1
- package/dist/aegis128x.js +202 -9
- package/dist/aegis128x.js.map +1 -1
- package/dist/aegis256-bs.d.ts +183 -0
- package/dist/aegis256-bs.d.ts.map +1 -0
- package/dist/aegis256-bs.js +477 -0
- package/dist/aegis256-bs.js.map +1 -0
- package/dist/aegis256.d.ts +74 -5
- package/dist/aegis256.d.ts.map +1 -1
- package/dist/aegis256.js +158 -5
- package/dist/aegis256.js.map +1 -1
- package/dist/aegis256x.d.ts +109 -12
- package/dist/aegis256x.d.ts.map +1 -1
- package/dist/aegis256x.js +193 -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 +709 -0
- package/src/aegis128l.ts +238 -5
- package/src/aegis128x.ts +342 -15
- package/src/aegis256-bs.ts +625 -0
- package/src/aegis256.ts +223 -5
- package/src/aegis256x.ts +329 -15
- package/src/aes-bs.ts +459 -0
- package/src/index.ts +86 -0
- package/src/random.ts +41 -0
- package/README.md~ +0 -154
package/README.md
CHANGED
|
@@ -3,9 +3,33 @@
|
|
|
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
|
|
7
|
-
|
|
8
|
-
AEGIS
|
|
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
|
+
|
|
8
|
+
AEGIS provides both encryption with authentication and standalone MAC functionality, with a simple API that makes it hard to misuse.
|
|
9
|
+
|
|
10
|
+
## Table of Contents
|
|
11
|
+
|
|
12
|
+
- [aegis-aead](#aegis-aead)
|
|
13
|
+
- [Table of Contents](#table-of-contents)
|
|
14
|
+
- [Installation](#installation)
|
|
15
|
+
- [Quick Start](#quick-start)
|
|
16
|
+
- [Choosing an Algorithm](#choosing-an-algorithm)
|
|
17
|
+
- [Usage Examples](#usage-examples)
|
|
18
|
+
- [Combined Mode](#combined-mode)
|
|
19
|
+
- [Detached Mode](#detached-mode)
|
|
20
|
+
- [In-Place Mode](#in-place-mode)
|
|
21
|
+
- [MAC (Message Authentication Code)](#mac-message-authentication-code)
|
|
22
|
+
- [API Overview](#api-overview)
|
|
23
|
+
- [Functions](#functions)
|
|
24
|
+
- [Parameters](#parameters)
|
|
25
|
+
- [Constants](#constants)
|
|
26
|
+
- [Parallel Variants (AEGIS-128X / AEGIS-256X)](#parallel-variants-aegis-128x--aegis-256x)
|
|
27
|
+
- [Security Considerations](#security-considerations)
|
|
28
|
+
- [Nonce Safety](#nonce-safety)
|
|
29
|
+
- [Tag Lengths](#tag-lengths)
|
|
30
|
+
- [Bitsliced Variants](#bitsliced-variants)
|
|
31
|
+
- [Compatibility](#compatibility)
|
|
32
|
+
- [Browser Example](#browser-example)
|
|
9
33
|
|
|
10
34
|
## Installation
|
|
11
35
|
|
|
@@ -15,135 +39,217 @@ bun add aegis-aead
|
|
|
15
39
|
npm install aegis-aead
|
|
16
40
|
```
|
|
17
41
|
|
|
18
|
-
##
|
|
19
|
-
|
|
20
|
-
### Encryption and Decryption
|
|
42
|
+
## Quick Start
|
|
21
43
|
|
|
22
44
|
```typescript
|
|
23
|
-
import { aegis128LEncrypt, aegis128LDecrypt } from "aegis-aead";
|
|
45
|
+
import { aegis128LCreateKey, aegis128LEncrypt, aegis128LDecrypt } from "aegis-aead";
|
|
24
46
|
|
|
25
|
-
const key =
|
|
26
|
-
const nonce = crypto.getRandomValues(new Uint8Array(16));
|
|
47
|
+
const key = aegis128LCreateKey();
|
|
27
48
|
const message = new TextEncoder().encode("Hello, world!");
|
|
28
49
|
const associatedData = new TextEncoder().encode("metadata");
|
|
29
50
|
|
|
30
|
-
// Encrypt
|
|
31
|
-
const
|
|
51
|
+
// Encrypt (nonce is generated automatically)
|
|
52
|
+
const sealed = aegis128LEncrypt(message, associatedData, key);
|
|
32
53
|
|
|
33
54
|
// Decrypt (returns null if authentication fails)
|
|
34
|
-
const decrypted = aegis128LDecrypt(
|
|
55
|
+
const decrypted = aegis128LDecrypt(sealed, associatedData, key);
|
|
35
56
|
```
|
|
36
57
|
|
|
37
|
-
|
|
58
|
+
## Choosing an Algorithm
|
|
38
59
|
|
|
39
|
-
|
|
40
|
-
|
|
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 |
|
|
41
68
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
69
|
+
Recommendations:
|
|
70
|
+
|
|
71
|
+
- Default choice: AEGIS-128L offers excellent performance with safe random nonces up to 2^48 messages
|
|
72
|
+
- Unlimited messages: AEGIS-256 when you need unlimited random nonces (32-byte nonce eliminates collision risk)
|
|
73
|
+
- 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
|
+
|
|
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.
|
|
45
77
|
|
|
46
|
-
|
|
47
|
-
|
|
78
|
+
## Usage Examples
|
|
79
|
+
|
|
80
|
+
### Combined Mode
|
|
81
|
+
|
|
82
|
+
The simplest API: returns `nonce || ciphertext || tag` in one buffer.
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
import { aegis128LCreateKey, aegis128LEncrypt, aegis128LDecrypt } from "aegis-aead";
|
|
86
|
+
|
|
87
|
+
const key = aegis128LCreateKey();
|
|
88
|
+
const message = new TextEncoder().encode("Hello, world!");
|
|
89
|
+
const ad = new TextEncoder().encode("metadata");
|
|
48
90
|
|
|
49
|
-
|
|
50
|
-
const
|
|
91
|
+
const sealed = aegis128LEncrypt(message, ad, key);
|
|
92
|
+
const decrypted = aegis128LDecrypt(sealed, ad, key);
|
|
51
93
|
```
|
|
52
94
|
|
|
53
|
-
|
|
95
|
+
### Detached Mode
|
|
54
96
|
|
|
55
|
-
|
|
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) |
|
|
97
|
+
When you need separate access to ciphertext and tag:
|
|
61
98
|
|
|
62
|
-
|
|
99
|
+
```typescript
|
|
100
|
+
import {
|
|
101
|
+
aegis128LCreateKey,
|
|
102
|
+
aegis128LCreateNonce,
|
|
103
|
+
aegis128LEncryptDetached,
|
|
104
|
+
aegis128LDecryptDetached
|
|
105
|
+
} from "aegis-aead";
|
|
106
|
+
|
|
107
|
+
const key = aegis128LCreateKey();
|
|
108
|
+
const nonce = aegis128LCreateNonce();
|
|
109
|
+
const message = new TextEncoder().encode("Hello, world!");
|
|
110
|
+
const ad = new TextEncoder().encode("metadata");
|
|
63
111
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
112
|
+
const { ciphertext, tag } = aegis128LEncryptDetached(message, ad, key, nonce);
|
|
113
|
+
const decrypted = aegis128LDecryptDetached(ciphertext, tag, ad, key, nonce);
|
|
114
|
+
```
|
|
67
115
|
|
|
68
|
-
|
|
116
|
+
### In-Place Mode
|
|
69
117
|
|
|
70
|
-
|
|
118
|
+
Zero-copy encryption that modifies the buffer directly:
|
|
71
119
|
|
|
72
120
|
```typescript
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
121
|
+
import {
|
|
122
|
+
aegis128LCreateKey,
|
|
123
|
+
aegis128LCreateNonce,
|
|
124
|
+
aegis128LEncryptDetachedInPlace,
|
|
125
|
+
aegis128LDecryptDetachedInPlace
|
|
126
|
+
} from "aegis-aead";
|
|
127
|
+
|
|
128
|
+
const key = aegis128LCreateKey();
|
|
129
|
+
const nonce = aegis128LCreateNonce();
|
|
130
|
+
const data = new TextEncoder().encode("Hello, world!");
|
|
131
|
+
const ad = new TextEncoder().encode("metadata");
|
|
132
|
+
|
|
133
|
+
// Encrypt: data is modified, tag is returned
|
|
134
|
+
const tag = aegis128LEncryptDetachedInPlace(data, ad, key, nonce);
|
|
135
|
+
|
|
136
|
+
// Decrypt: returns true if authentication succeeds
|
|
137
|
+
const success = aegis128LDecryptDetachedInPlace(data, tag, ad, key, nonce);
|
|
77
138
|
```
|
|
78
139
|
|
|
79
|
-
###
|
|
140
|
+
### MAC (Message Authentication Code)
|
|
141
|
+
|
|
142
|
+
Authenticate data without encrypting:
|
|
80
143
|
|
|
81
144
|
```typescript
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
145
|
+
import { aegis128LCreateKey, aegis128LMac, aegis128LMacVerify } from "aegis-aead";
|
|
146
|
+
|
|
147
|
+
const key = aegis128LCreateKey();
|
|
148
|
+
const data = new TextEncoder().encode("data to authenticate");
|
|
149
|
+
|
|
150
|
+
const tag = aegis128LMac(data, key);
|
|
151
|
+
const valid = aegis128LMacVerify(data, tag, key);
|
|
86
152
|
```
|
|
87
153
|
|
|
88
|
-
|
|
154
|
+
## API Overview
|
|
155
|
+
|
|
156
|
+
All AEGIS variants follow the same API pattern. Replace `aegis128L` with your chosen algorithm (`aegis256`, `aegis128X2`, `aegis128X4`, `aegis256X2`, `aegis256X4`, `aegis128LBs`, `aegis256Bs`).
|
|
157
|
+
|
|
158
|
+
### Functions
|
|
159
|
+
|
|
160
|
+
| Function | Description |
|
|
161
|
+
| ------------------------------------------------------- | -------------------------------------------------- |
|
|
162
|
+
| `createKey()` | Generate a random key |
|
|
163
|
+
| `createNonce()` | Generate a random nonce |
|
|
164
|
+
| `encrypt(msg, ad, key, nonce?, tagLen?)` | Encrypt, returns `nonce \|\| ciphertext \|\| tag` |
|
|
165
|
+
| `decrypt(sealed, ad, key, tagLen?)` | Decrypt combined output, returns `null` on failure |
|
|
166
|
+
| `encryptDetached(msg, ad, key, nonce, tagLen?)` | Encrypt, returns `{ ciphertext, tag }` |
|
|
167
|
+
| `decryptDetached(ct, tag, ad, key, nonce)` | Decrypt detached, returns `null` on failure |
|
|
168
|
+
| `encryptDetachedInPlace(data, ad, key, nonce, tagLen?)` | Encrypt in-place, returns tag |
|
|
169
|
+
| `decryptDetachedInPlace(data, tag, ad, key, nonce)` | Decrypt in-place, returns `boolean` |
|
|
170
|
+
| `mac(data, key, nonce?, tagLen?)` | Generate MAC tag |
|
|
171
|
+
| `macVerify(data, tag, key, nonce?)` | Verify MAC tag |
|
|
172
|
+
|
|
173
|
+
### Parameters
|
|
89
174
|
|
|
90
|
-
|
|
175
|
+
- msg/data: `Uint8Array` - Data to encrypt/authenticate
|
|
176
|
+
- ad: `Uint8Array` - Associated data (authenticated but not encrypted)
|
|
177
|
+
- key: `Uint8Array` - Encryption key (16 or 32 bytes depending on algorithm)
|
|
178
|
+
- nonce: `Uint8Array` - Number used once (auto-generated if omitted in combined mode)
|
|
179
|
+
- tagLen: `number` - Authentication tag length: `16` (default) or `32`
|
|
180
|
+
|
|
181
|
+
### Constants
|
|
182
|
+
|
|
183
|
+
Each algorithm exports size constants:
|
|
91
184
|
|
|
92
185
|
```typescript
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
|
186
|
+
import { AEGIS_128L_KEY_SIZE, AEGIS_128L_NONCE_SIZE } from "aegis-aead";
|
|
187
|
+
// AEGIS_128L_KEY_SIZE = 16
|
|
188
|
+
// AEGIS_128L_NONCE_SIZE = 16
|
|
110
189
|
```
|
|
111
190
|
|
|
112
|
-
### AEGIS-256X
|
|
191
|
+
### Parallel Variants (AEGIS-128X / AEGIS-256X)
|
|
113
192
|
|
|
114
|
-
|
|
193
|
+
The X variants support a configurable degree of parallelism:
|
|
115
194
|
|
|
116
195
|
```typescript
|
|
117
|
-
//
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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
|
|
196
|
+
// Pre-configured for degree 2 and 4
|
|
197
|
+
import { aegis128X2Encrypt, aegis128X4Encrypt } from "aegis-aead";
|
|
198
|
+
|
|
199
|
+
// Or use custom degree (typically 2 or 4)
|
|
200
|
+
import { aegis128XEncrypt } from "aegis-aead";
|
|
201
|
+
const sealed = aegis128XEncrypt(msg, ad, key, nonce, 16, 4); // degree=4
|
|
134
202
|
```
|
|
135
203
|
|
|
204
|
+
## Security Considerations
|
|
205
|
+
|
|
206
|
+
### Nonce Safety
|
|
207
|
+
|
|
208
|
+
- Combined mode generates random nonces automatically
|
|
209
|
+
- Detached mode requires you to provide nonces - never reuse a nonce with the same key
|
|
210
|
+
- AEGIS-128L/128X: Safe for up to 2^48 messages per key with random nonces
|
|
211
|
+
- AEGIS-256/256X: No practical limits on message count
|
|
212
|
+
|
|
213
|
+
### Tag Lengths
|
|
214
|
+
|
|
215
|
+
All algorithms support 16-byte (128-bit) and 32-byte (256-bit) tags:
|
|
216
|
+
|
|
217
|
+
```typescript
|
|
218
|
+
// 32-byte tag
|
|
219
|
+
const sealed = aegis128LEncrypt(msg, ad, key, undefined, 32);
|
|
220
|
+
```
|
|
221
|
+
|
|
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
|
|
230
|
+
|
|
231
|
+
For most applications, standard variants are safe since AEGIS's continuous state mixing makes timing attacks impractical.
|
|
232
|
+
|
|
233
|
+
## Compatibility
|
|
234
|
+
|
|
235
|
+
Runtime Requirements:
|
|
236
|
+
|
|
237
|
+
The library uses the Web Crypto API (`crypto.getRandomValues`) for key/nonce generation:
|
|
238
|
+
|
|
239
|
+
- All modern browsers
|
|
240
|
+
- Node.js 18+
|
|
241
|
+
- Deno
|
|
242
|
+
- Bun
|
|
243
|
+
|
|
244
|
+
Interoperability:
|
|
245
|
+
|
|
246
|
+
This library implements the [AEGIS IETF draft specification](https://datatracker.ietf.org/doc/draft-irtf-cfrg-aegis-aead/) and interoperates with any compliant implementation. See the [full list of AEGIS implementations](https://github.com/cfrg/draft-irtf-cfrg-aegis-aead?tab=readme-ov-file#known-implementations).
|
|
247
|
+
|
|
136
248
|
## Browser Example
|
|
137
249
|
|
|
138
|
-
A browser
|
|
250
|
+
A browser demo is included:
|
|
139
251
|
|
|
140
252
|
```bash
|
|
141
253
|
bun run build:example
|
|
142
254
|
open examples/index.html
|
|
143
255
|
```
|
|
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
|
-
## License
|
|
148
|
-
|
|
149
|
-
MIT
|
|
@@ -0,0 +1,194 @@
|
|
|
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
|
+
* Encrypts a 32-byte plaintext block in-place.
|
|
75
|
+
* @param block - 32-byte buffer (plaintext in, ciphertext out)
|
|
76
|
+
*/
|
|
77
|
+
encInPlace(block: Uint8Array): void;
|
|
78
|
+
/**
|
|
79
|
+
* Decrypts a 32-byte ciphertext block in-place.
|
|
80
|
+
* @param block - 32-byte buffer (ciphertext in, plaintext out)
|
|
81
|
+
*/
|
|
82
|
+
decInPlace(block: Uint8Array): void;
|
|
83
|
+
/**
|
|
84
|
+
* Decrypts a partial (final) ciphertext block smaller than 32 bytes.
|
|
85
|
+
* @param cn - Partial ciphertext block (1-31 bytes)
|
|
86
|
+
* @returns Decrypted plaintext of the same length
|
|
87
|
+
*/
|
|
88
|
+
decPartial(cn: Uint8Array): Uint8Array;
|
|
89
|
+
/**
|
|
90
|
+
* Finalizes encryption/decryption and produces an authentication tag.
|
|
91
|
+
* @param adLen - Associated data length in bytes
|
|
92
|
+
* @param msgLen - Message length in bytes
|
|
93
|
+
* @param tagLen - Tag length (16 or 32 bytes)
|
|
94
|
+
* @returns Authentication tag
|
|
95
|
+
*/
|
|
96
|
+
finalize(adLen: number, msgLen: number, tagLen?: 16 | 32): Uint8Array;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Encrypts a message using bitsliced AEGIS-128L (detached mode).
|
|
100
|
+
* @param msg - Plaintext message
|
|
101
|
+
* @param ad - Associated data (authenticated but not encrypted)
|
|
102
|
+
* @param key - 16-byte encryption key
|
|
103
|
+
* @param nonce - 16-byte nonce (must be unique per message with the same key)
|
|
104
|
+
* @param tagLen - Authentication tag length: 16 or 32 bytes (default: 16)
|
|
105
|
+
* @returns Object containing ciphertext and authentication tag separately
|
|
106
|
+
*/
|
|
107
|
+
export declare function aegis128LBsEncryptDetached(msg: Uint8Array, ad: Uint8Array, key: Uint8Array, nonce: Uint8Array, tagLen?: 16 | 32): {
|
|
108
|
+
ciphertext: Uint8Array;
|
|
109
|
+
tag: Uint8Array;
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* Decrypts a message using bitsliced AEGIS-128L (detached mode).
|
|
113
|
+
* @param ct - Ciphertext
|
|
114
|
+
* @param tag - Authentication tag (16 or 32 bytes)
|
|
115
|
+
* @param ad - Associated data (must match what was used during encryption)
|
|
116
|
+
* @param key - 16-byte encryption key
|
|
117
|
+
* @param nonce - 16-byte nonce (must match what was used during encryption)
|
|
118
|
+
* @returns Decrypted plaintext, or null if authentication fails
|
|
119
|
+
*/
|
|
120
|
+
export declare function aegis128LBsDecryptDetached(ct: Uint8Array, tag: Uint8Array, ad: Uint8Array, key: Uint8Array, nonce: Uint8Array): Uint8Array | null;
|
|
121
|
+
/**
|
|
122
|
+
* Encrypts a message in-place using bitsliced AEGIS-128L (detached mode).
|
|
123
|
+
* The input buffer is modified to contain the ciphertext.
|
|
124
|
+
* @param data - Buffer containing plaintext (will be overwritten with ciphertext)
|
|
125
|
+
* @param ad - Associated data (authenticated but not encrypted)
|
|
126
|
+
* @param key - 16-byte encryption key
|
|
127
|
+
* @param nonce - 16-byte nonce (must be unique per message with the same key)
|
|
128
|
+
* @param tagLen - Authentication tag length: 16 or 32 bytes (default: 16)
|
|
129
|
+
* @returns Authentication tag
|
|
130
|
+
*/
|
|
131
|
+
export declare function aegis128LBsEncryptDetachedInPlace(data: Uint8Array, ad: Uint8Array, key: Uint8Array, nonce: Uint8Array, tagLen?: 16 | 32): Uint8Array;
|
|
132
|
+
/**
|
|
133
|
+
* Decrypts a message in-place using bitsliced AEGIS-128L (detached mode).
|
|
134
|
+
* The input buffer is modified to contain the plaintext (or zeroed on failure).
|
|
135
|
+
* @param data - Buffer containing ciphertext (will be overwritten with plaintext)
|
|
136
|
+
* @param tag - Authentication tag (16 or 32 bytes)
|
|
137
|
+
* @param ad - Associated data (must match what was used during encryption)
|
|
138
|
+
* @param key - 16-byte encryption key
|
|
139
|
+
* @param nonce - 16-byte nonce (must match what was used during encryption)
|
|
140
|
+
* @returns True if authentication succeeds, false otherwise
|
|
141
|
+
*/
|
|
142
|
+
export declare function aegis128LBsDecryptDetachedInPlace(data: Uint8Array, tag: Uint8Array, ad: Uint8Array, key: Uint8Array, nonce: Uint8Array): boolean;
|
|
143
|
+
export declare const AEGIS_128L_BS_NONCE_SIZE = 16;
|
|
144
|
+
export declare const AEGIS_128L_BS_KEY_SIZE = 16;
|
|
145
|
+
/**
|
|
146
|
+
* Encrypts a message using bitsliced AEGIS-128L.
|
|
147
|
+
* Returns a single buffer containing nonce || ciphertext || tag.
|
|
148
|
+
* @param msg - Plaintext message
|
|
149
|
+
* @param ad - Associated data (authenticated but not encrypted)
|
|
150
|
+
* @param key - 16-byte encryption key
|
|
151
|
+
* @param nonce - 16-byte nonce (optional, generates random nonce if not provided)
|
|
152
|
+
* @param tagLen - Authentication tag length: 16 or 32 bytes (default: 16)
|
|
153
|
+
* @returns Concatenated nonce || ciphertext || tag
|
|
154
|
+
*/
|
|
155
|
+
export declare function aegis128LBsEncrypt(msg: Uint8Array, ad: Uint8Array, key: Uint8Array, nonce?: Uint8Array | null, tagLen?: 16 | 32): Uint8Array;
|
|
156
|
+
/**
|
|
157
|
+
* Decrypts a message using bitsliced AEGIS-128L.
|
|
158
|
+
* Expects input as nonce || ciphertext || tag.
|
|
159
|
+
* @param sealed - Concatenated nonce || ciphertext || tag
|
|
160
|
+
* @param ad - Associated data (must match what was used during encryption)
|
|
161
|
+
* @param key - 16-byte encryption key
|
|
162
|
+
* @param tagLen - Authentication tag length: 16 or 32 bytes (default: 16)
|
|
163
|
+
* @returns Decrypted plaintext, or null if authentication fails
|
|
164
|
+
*/
|
|
165
|
+
export declare function aegis128LBsDecrypt(sealed: Uint8Array, ad: Uint8Array, key: Uint8Array, tagLen?: 16 | 32): Uint8Array | null;
|
|
166
|
+
/**
|
|
167
|
+
* Computes a MAC (Message Authentication Code) using bitsliced AEGIS-128L.
|
|
168
|
+
* @param data - Data to authenticate
|
|
169
|
+
* @param key - 16-byte key
|
|
170
|
+
* @param nonce - 16-byte nonce (optional, uses zero nonce if null)
|
|
171
|
+
* @param tagLen - Tag length: 16 or 32 bytes (default: 16)
|
|
172
|
+
* @returns Authentication tag
|
|
173
|
+
*/
|
|
174
|
+
export declare function aegis128LBsMac(data: Uint8Array, key: Uint8Array, nonce?: Uint8Array | null, tagLen?: 16 | 32): Uint8Array;
|
|
175
|
+
/**
|
|
176
|
+
* Verifies a MAC computed using bitsliced AEGIS-128L.
|
|
177
|
+
* @param data - Data to verify
|
|
178
|
+
* @param tag - Expected authentication tag (16 or 32 bytes)
|
|
179
|
+
* @param key - 16-byte key
|
|
180
|
+
* @param nonce - 16-byte nonce (optional, uses zero nonce if null)
|
|
181
|
+
* @returns True if the tag is valid, false otherwise
|
|
182
|
+
*/
|
|
183
|
+
export declare function aegis128LBsMacVerify(data: Uint8Array, tag: Uint8Array, key: Uint8Array, nonce?: Uint8Array | null): boolean;
|
|
184
|
+
/**
|
|
185
|
+
* Generates a random 16-byte key for bitsliced AEGIS-128L.
|
|
186
|
+
* @returns 16-byte encryption key
|
|
187
|
+
*/
|
|
188
|
+
export declare function aegis128LBsCreateKey(): Uint8Array;
|
|
189
|
+
/**
|
|
190
|
+
* Generates a random 16-byte nonce for bitsliced AEGIS-128L.
|
|
191
|
+
* @returns 16-byte nonce
|
|
192
|
+
*/
|
|
193
|
+
export declare function aegis128LBsCreateNonce(): Uint8Array;
|
|
194
|
+
//# 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,OAAO,CAAC,EAAE,CAAY;IACtB,OAAO,CAAC,GAAG,CAAY;IACvB,OAAO,CAAC,IAAI,CAAW;IACvB,OAAO,CAAC,IAAI,CAAW;IACvB,OAAO,CAAC,EAAE,CAAW;IACrB,OAAO,CAAC,EAAE,CAAW;;IAWrB;;;OAGG;IACH,OAAO,CAAC,UAAU;IAkBlB;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAWxB;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAOzB;;OAEG;IACH,OAAO,CAAC,UAAU;IAalB;;OAEG;IACH,OAAO,CAAC,MAAM;IAKd;;;;OAIG;IACH,IAAI,CAAC,GAAG,EAAE,UAAU,EAAE,KAAK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