pqc-binary-format 3.0.1

Standardized binary format for post-quantum cryptography encrypted data interchange
Documentation
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
432
433
434
435
436
437
438
439
440
441
442
443
444
445
/* PQC Binary Format v1.0 - C/C++ Bindings */
/* Auto-generated header file - DO NOT EDIT */


#ifndef PQC_BINARY_FORMAT_H
#define PQC_BINARY_FORMAT_H

#pragma once

/* Warning: This file is auto-generated by cbindgen. */


#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

/**
 * Current version of the PQC Binary Format specification
 */
#define PQC_BINARY_VERSION 1

/**
 * C-compatible byte buffer
 */
typedef struct ByteBuffer {
  unsigned char *data;
  uintptr_t len;
  uintptr_t capacity;
} ByteBuffer;

/**
 * Opaque handle to PqcBinaryFormat
 */
typedef struct PqcFormatHandle {
  uint8_t _private[0];
} PqcFormatHandle;

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

/**
 * Algorithm ID for Classical (0x0050): Classical cryptography: X25519 + Ed25519 + AES-256-GCM
 */
extern const uint16_t PQC_ALGORITHM_CLASSICAL;

/**
 * Algorithm ID for Password Classical (0x0051): Password-based classical encryption
 */
extern const uint16_t PQC_ALGORITHM_PASSWORD_CLASSICAL;

/**
 * Algorithm ID for Hybrid (0x0100): Hybrid: ML-KEM-1024 + X25519 + ML-DSA-87 + Ed25519 + AES-256-GCM
 */
extern const uint16_t PQC_ALGORITHM_HYBRID;

/**
 * Algorithm ID for Post-Quantum (0x0200): Post-quantum: ML-KEM-1024 + ML-DSA-87 + AES-256-GCM
 */
extern const uint16_t PQC_ALGORITHM_POST_QUANTUM;

/**
 * Algorithm ID for Multi-Algorithm (0x0201): Multi-algorithm runtime selection
 */
extern const uint16_t PQC_ALGORITHM_MULTI_ALGORITHM;

/**
 * Algorithm ID for ML-KEM-1024 (0x0202): ML-KEM-1024 with AES-256-GCM
 */
extern const uint16_t PQC_ALGORITHM_ML_KEM_1024;

/**
 * Algorithm ID for Multi-KEM Dual Layer (0x0203): Multi-KEM dual layer
 */
extern const uint16_t PQC_ALGORITHM_MULTI_KEM;

/**
 * Algorithm ID for Multi-KEM Triple Layer (0x0204): Multi-KEM triple layer
 */
extern const uint16_t PQC_ALGORITHM_MULTI_KEM_TRIPLE;

/**
 * Algorithm ID for Quad-Layer (0x0205): Quad-layer redundant security
 */
extern const uint16_t PQC_ALGORITHM_QUAD_LAYER;

/**
 * Algorithm ID for Lattice-Code Hybrid (0x0206): Lattice-Code hybrid stack
 */
extern const uint16_t PQC_ALGORITHM_LATTICE_CODE_HYBRID;

/**
 * Algorithm ID for PQ3-Stack (0x0207): PQ3-Stack with forward secrecy
 */
extern const uint16_t PQC_ALGORITHM_PQ3_STACK;

/**
 * Algorithm ID for X25519MLKEM768 (0x0208): X-Wing hybrid KEM: ML-KEM-768 (FIPS 203) combined with X25519, the pair TLS negotiates as X25519MLKEM768
 */
extern const uint16_t PQC_ALGORITHM_X25519_MLKEM768;

/**
 * Algorithm ID for FrodoKEM-1344 (0x0209): FrodoKEM-1344: unstructured-lattice KEM, NIST level 5 (ISO/IEC 18033-2)
 */
extern const uint16_t PQC_ALGORITHM_FRODOKEM_1344;

/**
 * Algorithm ID for Classic-McEliece-6960119 (0x020A): Classic McEliece 6960119: code-based KEM (ISO/IEC 18033-2)
 */
extern const uint16_t PQC_ALGORITHM_CLASSIC_MCELIECE;

/**
 * Algorithm ID for FrodoKEM-976 (0x020B): FrodoKEM-976: unstructured-lattice KEM, NIST level 3
 */
extern const uint16_t PQC_ALGORITHM_FRODOKEM_976;

/**
 * Algorithm ID for Max Secure: PQ Lightweight (0x0300): Max Secure: PQ Lightweight
 */
extern const uint16_t PQC_ALGORITHM_MAX_SECURE_LIGHTWEIGHT;

/**
 * Algorithm ID for Max Secure: Pure PQ (0x0301): Max Secure: Pure PQ
 */
extern const uint16_t PQC_ALGORITHM_MAX_SECURE_PURE_PQ;

/**
 * Algorithm ID for Max Secure: Hybrid (0x0302): Max Secure: Hybrid Transition
 */
extern const uint16_t PQC_ALGORITHM_MAX_SECURE_HYBRID;

/**
 * Algorithm ID for Max Secure: Stateless (0x0303): Max Secure: Stateless
 */
extern const uint16_t PQC_ALGORITHM_MAX_SECURE_STATELESS;

/**
 * Algorithm ID for Max Secure: Crypto-Agile (0x0304): Max Secure: Crypto-Agile
 */
extern const uint16_t PQC_ALGORITHM_MAX_SECURE_CRYPTO_AGILE;

/**
 * Algorithm ID for Max Secure: PQC + ZK (0x0305): Max Secure: PQC + Zero-Knowledge
 */
extern const uint16_t PQC_ALGORITHM_MAX_SECURE_PQC_ZK;

/**
 * Algorithm ID for Max Secure: Hybrid Transition (0x0306): Max Secure: Hybrid Transition
 */
extern const uint16_t PQC_ALGORITHM_MAX_SECURE_HYBRID_TRANSITION;

/**
 * Algorithm ID for FN-DSA 512: Compact (0x0400): FN-DSA 512: Compact
 */
extern const uint16_t PQC_ALGORITHM_FN_DSA_512_COMPACT;

/**
 * Algorithm ID for FN-DSA 1024: High-Security (0x0401): FN-DSA 1024: High-Security
 */
extern const uint16_t PQC_ALGORITHM_FN_DSA_1024_SECURITY;

/**
 * Algorithm ID for FN-DSA: Floating-Point Hardened (0x0402): FN-DSA: Floating-Point Hardened
 */
extern const uint16_t PQC_ALGORITHM_FN_DSA_FP_HARDENED;

/**
 * Algorithm ID for FN-DSA: Dual Signature (0x0403): FN-DSA: Dual Signature
 */
extern const uint16_t PQC_ALGORITHM_FN_DSA_DUAL_SIGNATURE;

/**
 * Algorithm ID for FN-DSA: Transition Stack (0x0404): FN-DSA: Transition Stack
 */
extern const uint16_t PQC_ALGORITHM_FN_DSA_TRANSITION;

/**
 * Algorithm ID for FN-DSA + ZK Stack (0x0405): FN-DSA + Zero-Knowledge Stack
 */
extern const uint16_t PQC_ALGORITHM_FN_DSA_ZK;

/**
 * Algorithm ID for FN-DSA + ZK Stack Enhanced (0x0406): FN-DSA + ZK Stack Enhanced
 */
extern const uint16_t PQC_ALGORITHM_FN_DSA_ZK_STACK;

/**
 * Algorithm ID for FN-DSA: Transition Stack Enhanced (0x0407): FN-DSA: Transition Stack Enhanced
 */
extern const uint16_t PQC_ALGORITHM_FN_DSA_TRANSITION_STACK;

/**
 * Algorithm ID for Quantum-Inspired Lattice Fusion (0x0500): Quantum-Inspired Lattice Fusion
 */
extern const uint16_t PQC_ALGORITHM_QUANTUM_LATTICE_FUSION;

/**
 * Algorithm ID for Post-ZK Homomorphic (0x0501): Post-ZK Homomorphic with LFHE 2023
 */
extern const uint16_t PQC_ALGORITHM_POST_ZK_HOMOMORPHIC;

/**
 * Algorithm ID for Quantum-Resistant Consensus (0x0502): Quantum-Resistant Consensus
 */
extern const uint16_t PQC_ALGORITHM_QUANTUM_RESISTANT_CONSENSUS;

/**
 * Algorithm ID for Entropy-Orchestrated (0x0503): Entropy-Orchestrated PQ Stack
 */
extern const uint16_t PQC_ALGORITHM_ENTROPY_ORCHESTRATED;

/**
 * Algorithm ID for Lattice-Code Hybrid FN (0x0504): Lattice-Code Hybrid FN
 */
extern const uint16_t PQC_ALGORITHM_LATTICE_CODE_HYBRID_FN;

/**
 * Algorithm ID for AI-Synthesized Crypto-Agile (0x0505): AI-Synthesized Crypto-Agile
 */
extern const uint16_t PQC_ALGORITHM_AI_SYNTHESIZED_CRYPTO_AGILE;

/**
 * Algorithm ID for Experimental Engine (0x0506): Experimental Engine (generic)
 */
extern const uint16_t PQC_ALGORITHM_EXPERIMENTAL;

/**
 * Algorithm ID for HQC-128 (0x0600): HQC-128 (NIST Level 1, 128-bit security)
 */
extern const uint16_t PQC_ALGORITHM_HQC_128;

/**
 * Algorithm ID for HQC-192 (0x0601): HQC-192 (NIST Level 3, 192-bit security)
 */
extern const uint16_t PQC_ALGORITHM_HQC_192;

/**
 * Algorithm ID for HQC-256 (0x0602): HQC-256 (NIST Level 5, 256-bit security)
 */
extern const uint16_t PQC_ALGORITHM_HQC_256;

/**
 * Algorithm ID for ML-KEM-512 (0x0700): ML-KEM-512 (NIST Level 1, 128-bit security)
 */
extern const uint16_t PQC_ALGORITHM_ML_KEM_512;

/**
 * Algorithm ID for ML-KEM-768 (0x0701): ML-KEM-768 (NIST Level 3, 192-bit security)
 */
extern const uint16_t PQC_ALGORITHM_ML_KEM_768;

/**
 * Algorithm ID for ML-DSA-44 (0x0800): ML-DSA-44 (NIST Level 2, 128-bit security)
 */
extern const uint16_t PQC_ALGORITHM_ML_DSA_44;

/**
 * Algorithm ID for ML-DSA-65 (0x0801): ML-DSA-65 (NIST Level 3, 192-bit security)
 */
extern const uint16_t PQC_ALGORITHM_ML_DSA_65;

/**
 * Algorithm ID for ML-DSA-87 (0x0802): ML-DSA-87 (NIST Level 5, 256-bit security)
 */
extern const uint16_t PQC_ALGORITHM_ML_DSA_87;

/**
 * Algorithm ID for SLH-DSA-SHA2-128s (0x0900): SLH-DSA-SHA2-128s (NIST Level 1, small signatures)
 */
extern const uint16_t PQC_ALGORITHM_SLH_DSA_SHA2_128S;

/**
 * Algorithm ID for SLH-DSA-SHA2-128f (0x0901): SLH-DSA-SHA2-128f (NIST Level 1, fast signatures)
 */
extern const uint16_t PQC_ALGORITHM_SLH_DSA_SHA2_128F;

/**
 * Algorithm ID for SLH-DSA-SHA2-192s (0x0902): SLH-DSA-SHA2-192s (NIST Level 3, small signatures)
 */
extern const uint16_t PQC_ALGORITHM_SLH_DSA_SHA2_192S;

/**
 * Algorithm ID for SLH-DSA-SHA2-192f (0x0903): SLH-DSA-SHA2-192f (NIST Level 3, fast signatures)
 */
extern const uint16_t PQC_ALGORITHM_SLH_DSA_SHA2_192F;

/**
 * Algorithm ID for SLH-DSA-SHA2-256s (0x0904): SLH-DSA-SHA2-256s (NIST Level 5, small signatures)
 */
extern const uint16_t PQC_ALGORITHM_SLH_DSA_SHA2_256S;

/**
 * Algorithm ID for SLH-DSA-SHA2-256f (0x0905): SLH-DSA-SHA2-256f (NIST Level 5, fast signatures)
 */
extern const uint16_t PQC_ALGORITHM_SLH_DSA_SHA2_256F;

/**
 * Free a byte buffer allocated by this library
 *
 * # Safety
 * The buffer must have been allocated by this library
 */
void pqc_free_buffer(struct ByteBuffer buffer);

/**
 * Free a string allocated by this library
 *
 * # Safety
 * The string must have been allocated by this library
 */
void pqc_free_string(char *s);

/**
 * Create a new PQC Binary Format structure
 *
 * # Parameters
 * - `algorithm_id`: Algorithm identifier (see Algorithm enum)
 * - `iv`: IV/nonce bytes
 * - `iv_len`: Length of IV
 * - `tag`: Authentication tag bytes
 * - `tag_len`: Length of tag
 * - `data`: Encrypted data bytes
 * - `data_len`: Length of encrypted data
 *
 * # Returns
 * Opaque handle to PqcBinaryFormat, or NULL on error
 *
 * # Safety
 * All pointers must be valid. The returned handle must be freed with `pqc_format_free`.
 */
struct PqcFormatHandle *pqc_format_new(uint16_t algorithm_id, const unsigned char *iv, uintptr_t iv_len, const unsigned char *tag, uintptr_t tag_len, const unsigned char *data, uintptr_t data_len);

/**
 * Create PQC Binary Format with KEM parameters
 *
 * # Safety
 * All pointers must be valid
 */
struct PqcFormatHandle *pqc_format_new_with_kem(uint16_t algorithm_id, const unsigned char *iv, uintptr_t iv_len, const unsigned char *tag, uintptr_t tag_len, const unsigned char *kem_public_key, uintptr_t kem_public_key_len, const unsigned char *kem_ciphertext, uintptr_t kem_ciphertext_len, const unsigned char *data, uintptr_t data_len);

/**
 * Serialize PQC Binary Format to bytes
 *
 * # Parameters
 * - `handle`: Handle to PqcBinaryFormat
 *
 * # Returns
 * ByteBuffer containing serialized data, or NULL buffer on error
 *
 * # Safety
 * Handle must be valid. Returned buffer must be freed with `pqc_free_buffer`.
 */
struct ByteBuffer pqc_format_to_bytes(const struct PqcFormatHandle *handle);

/**
 * Deserialize PQC Binary Format from bytes
 *
 * # Parameters
 * - `data`: Bytes to deserialize
 * - `len`: Length of data
 *
 * # Returns
 * Handle to PqcBinaryFormat, or NULL on error
 *
 * # Safety
 * Data pointer must be valid. Returned handle must be freed with `pqc_format_free`.
 */
struct PqcFormatHandle *pqc_format_from_bytes(const unsigned char *data, uintptr_t len);

/**
 * Get algorithm ID from format
 *
 * # Safety
 * Handle must be valid
 */
uint16_t pqc_format_get_algorithm_id(const struct PqcFormatHandle *handle);

/**
 * Get algorithm name from format
 *
 * # Returns
 * Null-terminated string. Must be freed with `pqc_free_string`.
 *
 * # Safety
 * Handle must be valid
 */
char *pqc_format_get_algorithm_name(const struct PqcFormatHandle *handle);

/**
 * Get encrypted data from format
 *
 * # Returns
 * ByteBuffer containing data. Must be freed with `pqc_free_buffer`.
 *
 * # Safety
 * Handle must be valid
 */
struct ByteBuffer pqc_format_get_data(const struct PqcFormatHandle *handle);

/**
 * Validate format structure
 *
 * # Returns
 * 0 on success, -1 on error
 *
 * # Safety
 * Handle must be valid
 */
int pqc_format_validate(const struct PqcFormatHandle *handle);

/**
 * Get total size of serialized format
 *
 * # Safety
 * Handle must be valid
 */
uintptr_t pqc_format_get_total_size(const struct PqcFormatHandle *handle);

/**
 * Free a PqcBinaryFormat handle
 *
 * # Safety
 * Handle must have been allocated by this library and not previously freed
 */
void pqc_format_free(struct PqcFormatHandle *handle);

/**
 * Get library version string
 *
 * # Returns
 * Null-terminated version string. Must be freed with `pqc_free_string`.
 */
char *pqc_get_version(void);

/**
 * Get binary format version
 */
uint8_t pqc_get_binary_version(void);

#ifdef __cplusplus
}  // extern "C"
#endif  // __cplusplus

#endif  /* PQC_BINARY_FORMAT_H */