1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
//! Cryptographic algorithm identifiers for VSF hash, signature, and key types
//!
//! Each type (h, g, k) uses a single lowercase ASCII letter (a-z) to identify
//! the algorithm. This gives 26 slots per type, with most reserved for future use.
//!
//! ## Important: Algorithm vs Output Size
//!
//! Each letter represents a **distinct algorithm**, NOT just a different output size:
//! - SHA-256 (`s`) and SHA-512 (`t`) are **different algorithms** (32-bit vs 64-bit internal words, different round counts)
//! - They are not "the same algorithm with different output lengths"
//!
//! ## Variable-Length Output
//!
//! Some algorithms support variable output lengths while maintaining the same algorithm ID:
//! - **BLAKE3**: Can output any length (default 32 bytes, but can produce 1 byte to 2^64 bytes)
//! - **BLAKE2b**: Can output 1-64 bytes
//! - **SHA-3**: Supports "XOF" (extendable output) variants
//!
//! When storing a hash, the actual output length is encoded in the VSF `h` type's length field.
//! The algorithm ID just tells you which hash function was used.
// ==================== MAC ALGORITHMS (a type) ====================
/// HMAC-SHA256 - RECOMMENDED DEFAULT
///
/// **Algorithm:** Hash-based Message Authentication Code using SHA-256
/// **Fixed output:** 32 bytes (256 bits)
/// **Performance:** Fast, widely supported
/// **Security:** 128-bit security level
/// **Use case:** General-purpose authenticated encryption
pub const MAC_HMAC_SHA256: u8 = b'h';
/// HMAC-SHA512
///
/// **Algorithm:** Hash-based Message Authentication Code using SHA-512
/// **Fixed output:** 64 bytes (512 bits)
/// **Performance:** Fast on 64-bit systems
/// **Security:** 256-bit security level
pub const MAC_HMAC_SHA512: u8 = b't'; // 't' for "twelve-eight" (512 bits)
/// Poly1305
///
/// **Algorithm:** One-time authenticator (Poly1305-AES or standalone)
/// **Fixed output:** 16 bytes (128 bits)
/// **Performance:** Extremely fast
/// **Security:** 128-bit security level
/// **Use case:** Commonly paired with ChaCha20 for authenticated encryption
/// **Note:** Requires unique nonce per message with same key
pub const MAC_POLY1305: u8 = b'p';
/// BLAKE3 keyed mode
///
/// **Algorithm:** BLAKE3 with keying material (MAC mode)
/// **Default output:** 32 bytes (variable length supported)
/// **Performance:** Extremely fast, modern design
/// **Security:** 128-bit security level at 256-bit output
/// **Note:** BLAKE3's keyed mode is a true MAC, not just HMAC-BLAKE3
pub const MAC_BLAKE3: u8 = b'b';
/// CMAC (AES-based)
///
/// **Algorithm:** Cipher-based Message Authentication Code using AES
/// **Fixed output:** 16 bytes (128 bits)
/// **Security:** 128-bit security level
/// **Use case:** AES-based systems, hardware acceleration available
/// **Note:** Slower than HMAC/Poly1305 but useful when AES is already in use
pub const MAC_CMAC: u8 = b'c';
// Reserved MAC slots: a, d, e, f, g, i, j, k, l, m, n, o, q, r, t, u, v, w, x, y, z
/// Get MAC algorithm name from ID
/// Get expected MAC tag length in bytes (None = variable length)
// ==================== HASH ALGORITHMS (h type) ====================
/// BLAKE3 hash - RECOMMENDED DEFAULT
///
/// **Default output:** 32 bytes
/// **Variable output:** Supports any length from 1 byte to 2^64 bytes
/// **Performance:** Extremely fast, modern design
/// **Security:** Full 128-bit collision resistance at 256-bit output
pub const HASH_BLAKE3: u8 = b'b';
/// SHA-256 hash
///
/// **Algorithm:** SHA-2 family with 32-bit words, 64 rounds
/// **Fixed output:** 32 bytes (256 bits)
/// **Security:** 128-bit collision resistance
/// **Note:** This is NOT just SHA-512 with shorter output - it's a different algorithm
pub const HASH_SHA256: u8 = b's';
/// SHA-512 hash
///
/// **Algorithm:** SHA-2 family with 64-bit words, 80 rounds
/// **Fixed output:** 64 bytes (512 bits)
/// **Security:** 256-bit collision resistance
/// **Note:** On 64-bit processors, can be faster than SHA-256 despite longer output
pub const HASH_SHA512: u8 = b't';
// Reserved hash slots: a, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, u, v, w, x, y, z
/// Get hash algorithm name from ID
/// Get expected hash length in bytes
// ==================== SIGNATURE ALGORITHMS (g type) ====================
/// Ed25519 signature - RECOMMENDED DEFAULT
///
/// **Algorithm:** Edwards-curve Digital Signature Algorithm using Curve25519
/// **Fixed output:** 64 bytes (512 bits)
/// **Performance:** Very fast signing and verification
/// **Security:** ~128-bit security level
/// **Note:** This is a completely different algorithm from ECDSA, not just a different curve
pub const SIG_ED25519: u8 = b'e';
/// ECDSA P-256 signature
///
/// **Algorithm:** Elliptic Curve Digital Signature Algorithm on NIST P-256 curve
/// **Fixed output:** 64 bytes (two 32-byte integers: r and s)
/// **Security:** ~128-bit security level
/// **Use case:** Required for compliance with certain standards
/// **Note:** Different algorithm family than Ed25519 (ECDSA vs EdDSA)
pub const SIG_ECDSA_P256: u8 = b'p';
/// RSA-2048 signature
///
/// **Algorithm:** RSA with 2048-bit modulus
/// **Fixed output:** 256 bytes (2048 bits)
/// **Security:** ~112-bit security level (2048-bit RSA ≈ 112-bit symmetric)
/// **Performance:** Slower than elliptic curve algorithms
/// **Note:** RSA-2048 and RSA-4096 are the same algorithm with different key sizes,
/// but we give them different IDs because the signature size differs
pub const SIG_RSA_2048: u8 = b'r';
// Reserved signature slots: a, b, c, d, f, g, h, i, j, k, l, m, n, o, q, s, t, u, v, w, x, y, z
/// Get signature algorithm name from ID
/// Get expected signature length in bytes
// ==================== KEY TYPES (k type) ====================
/// Ed25519 public key - RECOMMENDED DEFAULT
///
/// **Algorithm:** Edwards-curve public key for signature verification
/// **Fixed size:** 32 bytes
/// **Use with:** Ed25519 signatures (SIG_ED25519)
/// **Performance:** Very fast signature verification
/// **Note:** Ed25519 keys are NOT compatible with X25519 (different curve operations)
pub const KEY_ED25519: u8 = b'e';
/// X25519 public key
///
/// **Algorithm:** Montgomery curve (Curve25519) public key for Diffie-Hellman key exchange
/// **Fixed size:** 32 bytes
/// **Use case:** ECDH key agreement (deriving shared secrets)
/// **Performance:** Very fast key exchange
/// **Note:** X25519 is NOT for signatures - it's for key agreement only
/// (Even though it uses the same underlying curve as Ed25519)
pub const KEY_X25519: u8 = b'x';
/// P-curve ECDSA/ECDH public key (P-256, P-384)
///
/// **Algorithm:** NIST P-curve elliptic curve public key
/// **Variable size:** 33/65 bytes (P-256), 49/97 bytes (P-384) - size disambiguates
/// **Use with:** ECDSA signatures or ECDH key agreement
/// **Security:** ~128-bit (P-256) or ~192-bit (P-384) security level
pub const KEY_P_CURVE: u8 = b'p';
/// secp256k1 public key (Bitcoin curve)
///
/// **Algorithm:** Koblitz curve used in Bitcoin/Ethereum
/// **Fixed size:** 33 bytes (compressed)
/// **Use case:** ECDH key agreement
/// **Origin:** Certicom (2000)
pub const KEY_SECP256K1: u8 = b'k';
/// ChaCha20-Poly1305 symmetric key
pub const KEY_CHACHA20_POLY1305: u8 = b'c';
/// AES-256-GCM symmetric key
pub const KEY_AES256_GCM: u8 = b'a';
/// ML-KEM public key (FIPS 203 - formerly Kyber)
///
/// **Algorithm:** Module-Learning with Errors Key Encapsulation Mechanism
/// **Variable size:** 800B (ML-KEM-512), 1184B (ML-KEM-768), 1568B (ML-KEM-1024)
/// **Security:** Post-quantum lattice-based
/// **Origin:** IBM/European consortium (2017), NIST standardized 2024
pub const KEY_ML_KEM: u8 = b'm';
/// FrodoKEM public key
///
/// **Algorithm:** Unstructured LWE-based key encapsulation
/// **Variable size:** 9616B (640), 15632B (976), 21520B (1344) - size disambiguates
/// **Security:** Post-quantum, conservative (no ring structure to exploit)
/// **Origin:** Microsoft Research (2016)
pub const KEY_FRODO: u8 = b'f';
/// Classic McEliece public key
///
/// **Algorithm:** Code-based key encapsulation (Goppa codes)
/// **Variable size:** 261KB to 1MB depending on variant
/// **Security:** Post-quantum, 47+ years of cryptanalysis
/// **Origin:** McEliece (1978), modern variants by Bernstein/Lange
/// **Note:** Extremely large public keys, small ciphertexts
pub const KEY_MCELIECE: u8 = b'l';
/// Shared secret / derived key material
///
/// **Usage:** Output of key agreement (ECDH, KEM decapsulation)
/// **Typical size:** 32 bytes
/// **Note:** Algorithm-agnostic - just raw key material
pub const KEY_SHARED_SECRET: u8 = b's';
/// Get key algorithm name from ID
///
/// Note: This handles both asymmetric keys (Ed25519, X25519, etc.) and
/// symmetric encryption keys (ChaCha20-Poly1305, AES-256-GCM, etc.)
/// Get expected public key length in bytes (None = variable length)
// ==================== WRAPPING/ENCRYPTION ALGORITHMS (v type) ====================
/// ChaCha20-Poly1305 AEAD encryption - RECOMMENDED DEFAULT
///
/// **Algorithm:** ChaCha20 stream cipher + Poly1305 MAC
/// **Key size:** 32 bytes
/// **Nonce size:** 12 bytes
/// **Tag size:** 16 bytes (Poly1305 authentication tag)
/// **Performance:** Extremely fast, constant-time
/// **Security:** 256-bit key strength
/// **Use case:** General-purpose authenticated encryption
pub const WRAP_CHACHA20POLY1305: u8 = b'c';
/// AES-256-GCM encryption
///
/// **Algorithm:** AES-256 in Galois/Counter Mode
/// **Key size:** 32 bytes
/// **Nonce size:** 12 bytes
/// **Tag size:** 16 bytes (GCM authentication tag)
/// **Security:** 256-bit key strength
/// **Use case:** Hardware-accelerated encryption (AES-NI)
pub const WRAP_AES256_GCM: u8 = b'a';
// Reserved wrapping slots: b, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z
/// Get wrapping algorithm name from ID
/// Get expected key length for wrapping algorithm in bytes
// ==================== VALIDATION HELPERS ====================
/// Validate MAC algorithm ID is known
/// Validate hash algorithm ID is known
/// Validate signature algorithm ID is known
/// Validate key algorithm ID is known