pqc-binary-format 1.0.7
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 +661 -0
- package/package.json +34 -0
- package/pqc_binary_format.d.ts +236 -0
- package/pqc_binary_format.js +5 -0
- package/pqc_binary_format_bg.js +827 -0
- package/pqc_binary_format_bg.wasm +0 -0
package/README.md
ADDED
|
@@ -0,0 +1,661 @@
|
|
|
1
|
+
# PQC Binary Format v1.0.7
|
|
2
|
+
|
|
3
|
+
[](https://crates.io/crates/pqc-binary-format)
|
|
4
|
+
[](https://docs.rs/pqc-binary-format)
|
|
5
|
+
[](LICENSE-MIT)
|
|
6
|
+
[](https://github.com/PQCrypta/pqcrypta-community/actions)
|
|
7
|
+
|
|
8
|
+
**A standardized, self-describing binary format for post-quantum cryptography encrypted data interchange.**
|
|
9
|
+
|
|
10
|
+
## ๐ The Problem
|
|
11
|
+
|
|
12
|
+
Post-quantum cryptography (PQC) implementations suffer from the "Babel Tower problem": different implementations cannot interoperate because there is no standardized format for encrypted data. Each library uses its own proprietary format, making cross-platform and cross-language encryption impossible.
|
|
13
|
+
|
|
14
|
+
## ๐ก The Solution
|
|
15
|
+
|
|
16
|
+
PQC Binary Format provides a universal, algorithm-agnostic format that:
|
|
17
|
+
|
|
18
|
+
- โ
Works across **28+ cryptographic algorithms**
|
|
19
|
+
- โ
**Self-describing metadata** enables seamless decryption
|
|
20
|
+
- โ
**Integrity verification** with SHA-256 checksums
|
|
21
|
+
- โ
**Cross-platform compatible** (Rust, Python, JavaScript, Go, etc.)
|
|
22
|
+
- โ
**Future-proof** design allows algorithm migration
|
|
23
|
+
- โ
**Zero dependencies** except serde and sha2
|
|
24
|
+
|
|
25
|
+
## ๐ Quick Start
|
|
26
|
+
|
|
27
|
+
### Rust
|
|
28
|
+
|
|
29
|
+
Add to your `Cargo.toml`:
|
|
30
|
+
|
|
31
|
+
```toml
|
|
32
|
+
[dependencies]
|
|
33
|
+
pqc-binary-format = "1.0"
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Basic Usage (Rust)
|
|
37
|
+
|
|
38
|
+
```rust
|
|
39
|
+
use pqc_binary_format::{PqcBinaryFormat, Algorithm, PqcMetadata, EncParameters};
|
|
40
|
+
use std::collections::HashMap;
|
|
41
|
+
|
|
42
|
+
// Create metadata with encryption parameters
|
|
43
|
+
let metadata = PqcMetadata {
|
|
44
|
+
enc_params: EncParameters {
|
|
45
|
+
iv: vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], // 12-byte nonce
|
|
46
|
+
tag: vec![0; 16], // 16-byte auth tag
|
|
47
|
+
params: HashMap::new(),
|
|
48
|
+
},
|
|
49
|
+
..Default::default()
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// Create encrypted data container
|
|
53
|
+
let encrypted_data = vec![1, 2, 3, 4, 5]; // Your encrypted bytes
|
|
54
|
+
let format = PqcBinaryFormat::new(Algorithm::Hybrid, metadata, encrypted_data);
|
|
55
|
+
|
|
56
|
+
// Serialize to bytes (for transmission or storage)
|
|
57
|
+
let bytes = format.to_bytes().unwrap();
|
|
58
|
+
|
|
59
|
+
// Deserialize from bytes (includes automatic checksum verification)
|
|
60
|
+
let recovered = PqcBinaryFormat::from_bytes(&bytes).unwrap();
|
|
61
|
+
|
|
62
|
+
assert_eq!(format, recovered);
|
|
63
|
+
println!("Algorithm: {}", recovered.algorithm().name());
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Python
|
|
67
|
+
|
|
68
|
+
Install the Python bindings:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
cd bindings/python
|
|
72
|
+
pip install maturin
|
|
73
|
+
maturin develop --release
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
from pqc_binary_format import Algorithm, EncParameters, PqcMetadata, PqcBinaryFormat
|
|
78
|
+
|
|
79
|
+
# Create algorithm and metadata
|
|
80
|
+
algorithm = Algorithm("hybrid")
|
|
81
|
+
enc_params = EncParameters(
|
|
82
|
+
iv=bytes([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]),
|
|
83
|
+
tag=bytes([0] * 16)
|
|
84
|
+
)
|
|
85
|
+
metadata = PqcMetadata(enc_params=enc_params, kem_params=None, sig_params=None, compression_params=None)
|
|
86
|
+
|
|
87
|
+
# Create and serialize format
|
|
88
|
+
pqc_format = PqcBinaryFormat(algorithm, metadata, bytes([1, 2, 3, 4, 5]))
|
|
89
|
+
serialized = pqc_format.to_bytes()
|
|
90
|
+
|
|
91
|
+
# Deserialize and verify
|
|
92
|
+
deserialized = PqcBinaryFormat.from_bytes(serialized)
|
|
93
|
+
deserialized.validate() # Verify checksum integrity
|
|
94
|
+
print(f"Algorithm: {deserialized.algorithm.name}")
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### JavaScript/TypeScript
|
|
98
|
+
|
|
99
|
+
Build the WebAssembly bindings:
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
cd bindings/javascript
|
|
103
|
+
npm install
|
|
104
|
+
npm run build
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
```javascript
|
|
108
|
+
import init, { WasmAlgorithm, WasmEncParameters, WasmPqcMetadata, WasmPqcBinaryFormat } from './pqc_binary_format.js';
|
|
109
|
+
|
|
110
|
+
await init();
|
|
111
|
+
|
|
112
|
+
const algorithm = new WasmAlgorithm('hybrid');
|
|
113
|
+
const encParams = new WasmEncParameters(
|
|
114
|
+
new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]),
|
|
115
|
+
new Uint8Array(16)
|
|
116
|
+
);
|
|
117
|
+
const metadata = new WasmPqcMetadata(encParams);
|
|
118
|
+
const pqcFormat = new WasmPqcBinaryFormat(algorithm, metadata, new Uint8Array([1, 2, 3, 4, 5]));
|
|
119
|
+
|
|
120
|
+
const serialized = pqcFormat.toBytes();
|
|
121
|
+
const deserialized = WasmPqcBinaryFormat.fromBytes(serialized);
|
|
122
|
+
console.log(`Algorithm: ${deserialized.algorithm.name}`);
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Go
|
|
126
|
+
|
|
127
|
+
Build the Rust library first, then use the Go bindings:
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
cargo build --release
|
|
131
|
+
cd bindings/go
|
|
132
|
+
go build example.go
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
```go
|
|
136
|
+
package main
|
|
137
|
+
|
|
138
|
+
import (
|
|
139
|
+
"fmt"
|
|
140
|
+
"log"
|
|
141
|
+
pqc "github.com/PQCrypta/pqcrypta-community/bindings/go"
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
func main() {
|
|
145
|
+
iv := []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}
|
|
146
|
+
tag := make([]byte, 16)
|
|
147
|
+
data := []byte{1, 2, 3, 4, 5}
|
|
148
|
+
|
|
149
|
+
format, err := pqc.NewPqcBinaryFormat(pqc.AlgorithmHybrid, iv, tag, data)
|
|
150
|
+
if err != nil {
|
|
151
|
+
log.Fatal(err)
|
|
152
|
+
}
|
|
153
|
+
defer format.Free()
|
|
154
|
+
|
|
155
|
+
serialized, _ := format.ToBytes()
|
|
156
|
+
deserialized, _ := pqc.FromBytes(serialized)
|
|
157
|
+
defer deserialized.Free()
|
|
158
|
+
|
|
159
|
+
fmt.Printf("Algorithm: %s\n", deserialized.GetAlgorithmName())
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### C/C++
|
|
164
|
+
|
|
165
|
+
Build the Rust library and generate the C header:
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
cargo build --release
|
|
169
|
+
cbindgen --config cbindgen.toml --output include/pqc_binary_format.h
|
|
170
|
+
cd bindings/c-cpp
|
|
171
|
+
make
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
```cpp
|
|
175
|
+
#include "pqc_binary_format.h"
|
|
176
|
+
#include <iostream>
|
|
177
|
+
#include <vector>
|
|
178
|
+
|
|
179
|
+
int main() {
|
|
180
|
+
std::vector<uint8_t> iv = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
|
|
181
|
+
std::vector<uint8_t> tag(16, 0);
|
|
182
|
+
std::vector<uint8_t> data = {1, 2, 3, 4, 5};
|
|
183
|
+
|
|
184
|
+
PqcFormatHandle* format = pqc_format_new(
|
|
185
|
+
PQC_ALGORITHM_HYBRID,
|
|
186
|
+
iv.data(), iv.size(),
|
|
187
|
+
tag.data(), tag.size(),
|
|
188
|
+
data.data(), data.size()
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
ByteBuffer serialized = pqc_format_to_bytes(format);
|
|
192
|
+
PqcFormatHandle* deserialized = pqc_format_from_bytes(serialized.data, serialized.len);
|
|
193
|
+
|
|
194
|
+
char* alg_name = pqc_format_get_algorithm_name(deserialized);
|
|
195
|
+
std::cout << "Algorithm: " << alg_name << std::endl;
|
|
196
|
+
|
|
197
|
+
pqc_free_string(alg_name);
|
|
198
|
+
pqc_free_buffer(serialized);
|
|
199
|
+
pqc_format_free(deserialized);
|
|
200
|
+
pqc_format_free(format);
|
|
201
|
+
|
|
202
|
+
return 0;
|
|
203
|
+
}
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## ๐ Language Bindings
|
|
207
|
+
|
|
208
|
+
PQC Binary Format provides **production-ready, fully tested bindings** for multiple programming languages. All bindings support the complete API and produce cross-compatible binary formats.
|
|
209
|
+
|
|
210
|
+
### Available Bindings (v1.0.7)
|
|
211
|
+
|
|
212
|
+
| Language | Status | Package | Documentation | Examples |
|
|
213
|
+
|----------|--------|---------|---------------|----------|
|
|
214
|
+
| **Rust** | โ
Native | `pqc-binary-format` | [docs.rs](https://docs.rs/pqc-binary-format) | [3 examples](examples/) |
|
|
215
|
+
| **Python** | โ
Tested | `pqc_binary_format` | [Python README](bindings/python/README.md) | [2 examples](examples/python/) |
|
|
216
|
+
| **JavaScript/WASM** | โ
Tested | `pqc_binary_format` (npm) | [JS README](bindings/javascript/README.md) | [1 example](examples/javascript/) |
|
|
217
|
+
| **Go** | โ
Tested | `github.com/PQCrypta/pqcrypta-community/bindings/go` | [Go README](bindings/go/README.md) | [1 example](examples/go/) |
|
|
218
|
+
| **C** | โ
Tested | FFI via Rust | [C/C++ README](bindings/c-cpp/README.md) | [1 example](examples/c/) |
|
|
219
|
+
| **C++** | โ
Tested | FFI via Rust | [C/C++ README](bindings/c-cpp/README.md) | [1 example](examples/cpp/) |
|
|
220
|
+
|
|
221
|
+
### Installation Quick Reference
|
|
222
|
+
|
|
223
|
+
```bash
|
|
224
|
+
# Rust
|
|
225
|
+
cargo add pqc-binary-format
|
|
226
|
+
|
|
227
|
+
# Python (via maturin)
|
|
228
|
+
python3 -m venv .venv && source .venv/bin/activate
|
|
229
|
+
pip install maturin
|
|
230
|
+
maturin develop --release
|
|
231
|
+
|
|
232
|
+
# JavaScript/WASM (via wasm-pack)
|
|
233
|
+
wasm-pack build --target web --features wasm
|
|
234
|
+
|
|
235
|
+
# Go
|
|
236
|
+
go get github.com/PQCrypta/pqcrypta-community/bindings/go
|
|
237
|
+
|
|
238
|
+
# C/C++ (build from source)
|
|
239
|
+
cargo build --release --no-default-features
|
|
240
|
+
# Link against target/release/libpqc_binary_format.so
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
### Cross-Language Compatibility
|
|
244
|
+
|
|
245
|
+
**All language bindings are fully interoperable!** You can:
|
|
246
|
+
- โ
Encrypt data in Python, decrypt in Rust
|
|
247
|
+
- โ
Serialize in Go, deserialize in JavaScript
|
|
248
|
+
- โ
Create format in C++, validate in Python
|
|
249
|
+
- โ
Mix any combination across platforms
|
|
250
|
+
|
|
251
|
+
Example workflow:
|
|
252
|
+
```bash
|
|
253
|
+
# Create encrypted data with Python
|
|
254
|
+
python3 examples/python/basic_usage.py > data.bin
|
|
255
|
+
|
|
256
|
+
# Verify with C++
|
|
257
|
+
LD_LIBRARY_PATH=target/release ./examples/cpp/basic_usage < data.bin
|
|
258
|
+
|
|
259
|
+
# Process with Go
|
|
260
|
+
cd examples/go && go run basic_usage.go < ../../data.bin
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
### Binding Features
|
|
264
|
+
|
|
265
|
+
All bindings support:
|
|
266
|
+
- โ
Full algorithm suite (28 algorithms)
|
|
267
|
+
- โ
Metadata serialization/deserialization
|
|
268
|
+
- โ
SHA-256 integrity verification
|
|
269
|
+
- โ
Feature flags (compression, streaming, etc.)
|
|
270
|
+
- โ
Error handling with detailed messages
|
|
271
|
+
- โ
Memory safety (Rust-backed)
|
|
272
|
+
|
|
273
|
+
### Package Distribution Status
|
|
274
|
+
|
|
275
|
+
| Platform | Status | Notes |
|
|
276
|
+
|----------|--------|-------|
|
|
277
|
+
| crates.io (Rust) | โ
**Published** | **[v1.0.7 live!](https://crates.io/crates/pqc-binary-format)** |
|
|
278
|
+
| PyPI (Python) | โณ Ready | Maturin build tested, ready for `maturin publish` |
|
|
279
|
+
| npm (JavaScript) | โณ Ready | WASM package built with wasm-pack |
|
|
280
|
+
| pkg.go.dev (Go) | โณ Ready | Will auto-index on tag push |
|
|
281
|
+
|
|
282
|
+
## ๐ฆ Binary Format Specification
|
|
283
|
+
|
|
284
|
+
```text
|
|
285
|
+
+-------------------+
|
|
286
|
+
| Magic (4 bytes) | "PQC\x01" - Format identifier
|
|
287
|
+
+-------------------+
|
|
288
|
+
| Version (1 byte) | 0x01 - Format version
|
|
289
|
+
+-------------------+
|
|
290
|
+
| Algorithm (2 bytes)| Algorithm identifier (0x0050 - 0x0506)
|
|
291
|
+
+-------------------+
|
|
292
|
+
| Flags (1 byte) | Feature flags (compression, streaming, etc.)
|
|
293
|
+
+-------------------+
|
|
294
|
+
| Metadata Len (4) | Length of metadata section
|
|
295
|
+
+-------------------+
|
|
296
|
+
| Data Len (8) | Length of encrypted payload
|
|
297
|
+
+-------------------+
|
|
298
|
+
| Metadata (var) | Algorithm-specific parameters
|
|
299
|
+
+-------------------+
|
|
300
|
+
| Data (var) | Encrypted data
|
|
301
|
+
+-------------------+
|
|
302
|
+
| Checksum (32) | SHA-256 integrity checksum
|
|
303
|
+
+-------------------+
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
## ๐ Supported Algorithms
|
|
307
|
+
|
|
308
|
+
The format supports 28 cryptographic algorithm identifiers:
|
|
309
|
+
|
|
310
|
+
### Classical Algorithms
|
|
311
|
+
- **Classical** (0x0050): X25519 + Ed25519 + AES-256-GCM
|
|
312
|
+
- **Password Classical** (0x0051): Password-based encryption
|
|
313
|
+
|
|
314
|
+
### Hybrid Algorithms
|
|
315
|
+
- **Hybrid** (0x0100): ML-KEM-1024 + X25519 + ML-DSA-87 + Ed25519
|
|
316
|
+
|
|
317
|
+
### Post-Quantum Algorithms
|
|
318
|
+
- **Post-Quantum** (0x0200): ML-KEM-1024 + ML-DSA-87
|
|
319
|
+
- **ML-KEM-1024** (0x0202): Pure ML-KEM with AES-256-GCM
|
|
320
|
+
- **Multi-KEM** (0x0203): Dual-layer KEM
|
|
321
|
+
- **Multi-KEM Triple** (0x0204): Triple-layer KEM
|
|
322
|
+
- **Quad-Layer** (0x0205): Four independent layers
|
|
323
|
+
- **PQ3-Stack** (0x0207): Forward secrecy stack
|
|
324
|
+
|
|
325
|
+
### Max Secure Series (0x0300-0x0306)
|
|
326
|
+
High-security configurations for enterprise use
|
|
327
|
+
|
|
328
|
+
### FN-DSA Series (0x0400-0x0407)
|
|
329
|
+
Falcon-based signature algorithms
|
|
330
|
+
|
|
331
|
+
### Experimental (0x0500-0x0506)
|
|
332
|
+
Research and next-generation algorithms
|
|
333
|
+
|
|
334
|
+
[View full algorithm list](docs/algorithms.md)
|
|
335
|
+
|
|
336
|
+
## ๐ฏ Features
|
|
337
|
+
|
|
338
|
+
### Feature Flags
|
|
339
|
+
|
|
340
|
+
Control optional behavior with feature flags:
|
|
341
|
+
|
|
342
|
+
```rust
|
|
343
|
+
use pqc_binary_format::{PqcBinaryFormat, Algorithm, FormatFlags, PqcMetadata, EncParameters};
|
|
344
|
+
use std::collections::HashMap;
|
|
345
|
+
|
|
346
|
+
let flags = FormatFlags::new()
|
|
347
|
+
.with_compression() // Data was compressed before encryption
|
|
348
|
+
.with_streaming() // Streaming encryption mode
|
|
349
|
+
.with_additional_auth(); // Additional authentication layer
|
|
350
|
+
|
|
351
|
+
let metadata = PqcMetadata {
|
|
352
|
+
enc_params: EncParameters {
|
|
353
|
+
iv: vec![1; 12],
|
|
354
|
+
tag: vec![1; 16],
|
|
355
|
+
params: HashMap::new(),
|
|
356
|
+
},
|
|
357
|
+
..Default::default()
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
let format = PqcBinaryFormat::with_flags(
|
|
361
|
+
Algorithm::QuadLayer,
|
|
362
|
+
flags,
|
|
363
|
+
metadata,
|
|
364
|
+
vec![1, 2, 3],
|
|
365
|
+
);
|
|
366
|
+
|
|
367
|
+
assert!(format.flags().has_compression());
|
|
368
|
+
assert!(format.flags().has_streaming());
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
### Metadata Structure
|
|
372
|
+
|
|
373
|
+
The format includes rich metadata for decryption:
|
|
374
|
+
|
|
375
|
+
```rust
|
|
376
|
+
use pqc_binary_format::{PqcMetadata, KemParameters, SigParameters, EncParameters, CompressionParameters};
|
|
377
|
+
use std::collections::HashMap;
|
|
378
|
+
|
|
379
|
+
let metadata = PqcMetadata {
|
|
380
|
+
// Key Encapsulation (optional)
|
|
381
|
+
kem_params: Some(KemParameters {
|
|
382
|
+
public_key: vec![/* ML-KEM public key */],
|
|
383
|
+
ciphertext: vec![/* encapsulated key */],
|
|
384
|
+
params: HashMap::new(),
|
|
385
|
+
}),
|
|
386
|
+
|
|
387
|
+
// Digital Signature (optional)
|
|
388
|
+
sig_params: Some(SigParameters {
|
|
389
|
+
public_key: vec![/* ML-DSA public key */],
|
|
390
|
+
signature: vec![/* signature bytes */],
|
|
391
|
+
params: HashMap::new(),
|
|
392
|
+
}),
|
|
393
|
+
|
|
394
|
+
// Symmetric Encryption (required)
|
|
395
|
+
enc_params: EncParameters {
|
|
396
|
+
iv: vec![1; 12], // Nonce/IV
|
|
397
|
+
tag: vec![1; 16], // AEAD auth tag
|
|
398
|
+
params: HashMap::new(),
|
|
399
|
+
},
|
|
400
|
+
|
|
401
|
+
// Compression (optional)
|
|
402
|
+
compression_params: Some(CompressionParameters {
|
|
403
|
+
algorithm: "zstd".to_string(),
|
|
404
|
+
level: 3,
|
|
405
|
+
original_size: 1024,
|
|
406
|
+
params: HashMap::new(),
|
|
407
|
+
}),
|
|
408
|
+
|
|
409
|
+
// Custom parameters (extensible)
|
|
410
|
+
custom: HashMap::new(),
|
|
411
|
+
};
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
### Custom Parameters
|
|
415
|
+
|
|
416
|
+
Add your own metadata:
|
|
417
|
+
|
|
418
|
+
```rust
|
|
419
|
+
use pqc_binary_format::PqcMetadata;
|
|
420
|
+
|
|
421
|
+
let mut metadata = PqcMetadata::new();
|
|
422
|
+
metadata.add_custom("my_param".to_string(), vec![1, 2, 3]);
|
|
423
|
+
|
|
424
|
+
// Later...
|
|
425
|
+
if let Some(value) = metadata.get_custom("my_param") {
|
|
426
|
+
println!("Custom param: {:?}", value);
|
|
427
|
+
}
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
## ๐ Integrity Verification
|
|
431
|
+
|
|
432
|
+
Every format includes a SHA-256 checksum calculated over all fields:
|
|
433
|
+
|
|
434
|
+
```rust
|
|
435
|
+
use pqc_binary_format::PqcBinaryFormat;
|
|
436
|
+
|
|
437
|
+
let bytes = format.to_bytes().unwrap();
|
|
438
|
+
|
|
439
|
+
// Tamper with the data
|
|
440
|
+
// let mut corrupted = bytes.clone();
|
|
441
|
+
// corrupted[50] ^= 0xFF;
|
|
442
|
+
|
|
443
|
+
// Deserialization automatically verifies checksum
|
|
444
|
+
match PqcBinaryFormat::from_bytes(&bytes) {
|
|
445
|
+
Ok(format) => println!("โ Checksum valid"),
|
|
446
|
+
Err(e) => println!("โ Checksum failed: {}", e),
|
|
447
|
+
}
|
|
448
|
+
```
|
|
449
|
+
|
|
450
|
+
## ๐ Examples
|
|
451
|
+
|
|
452
|
+
### Example 1: Basic Encryption Format
|
|
453
|
+
|
|
454
|
+
```rust
|
|
455
|
+
use pqc_binary_format::{PqcBinaryFormat, Algorithm, PqcMetadata, EncParameters};
|
|
456
|
+
use std::collections::HashMap;
|
|
457
|
+
|
|
458
|
+
fn main() {
|
|
459
|
+
let metadata = PqcMetadata {
|
|
460
|
+
enc_params: EncParameters {
|
|
461
|
+
iv: vec![1; 12],
|
|
462
|
+
tag: vec![1; 16],
|
|
463
|
+
params: HashMap::new(),
|
|
464
|
+
},
|
|
465
|
+
..Default::default()
|
|
466
|
+
};
|
|
467
|
+
|
|
468
|
+
let format = PqcBinaryFormat::new(
|
|
469
|
+
Algorithm::Hybrid,
|
|
470
|
+
metadata,
|
|
471
|
+
vec![/* your encrypted data */],
|
|
472
|
+
);
|
|
473
|
+
|
|
474
|
+
// Save to file
|
|
475
|
+
let bytes = format.to_bytes().unwrap();
|
|
476
|
+
std::fs::write("encrypted.pqc", &bytes).unwrap();
|
|
477
|
+
|
|
478
|
+
// Load from file
|
|
479
|
+
let loaded_bytes = std::fs::read("encrypted.pqc").unwrap();
|
|
480
|
+
let loaded = PqcBinaryFormat::from_bytes(&loaded_bytes).unwrap();
|
|
481
|
+
|
|
482
|
+
println!("Algorithm: {}", loaded.algorithm().name());
|
|
483
|
+
}
|
|
484
|
+
```
|
|
485
|
+
|
|
486
|
+
### Example 2: Cross-Language Interoperability
|
|
487
|
+
|
|
488
|
+
**Rust (Encryption)**
|
|
489
|
+
```rust
|
|
490
|
+
let format = PqcBinaryFormat::new(Algorithm::PostQuantum, metadata, data);
|
|
491
|
+
let bytes = format.to_bytes().unwrap();
|
|
492
|
+
// Send bytes to Python/JavaScript/Go/C++
|
|
493
|
+
```
|
|
494
|
+
|
|
495
|
+
**Python (Decryption)**
|
|
496
|
+
```python
|
|
497
|
+
from pqc_binary_format import PqcBinaryFormat
|
|
498
|
+
|
|
499
|
+
format = PqcBinaryFormat.from_bytes(bytes)
|
|
500
|
+
print(f"Algorithm: {format.algorithm().name()}")
|
|
501
|
+
print(f"Data: {len(format.data())} bytes")
|
|
502
|
+
```
|
|
503
|
+
|
|
504
|
+
**JavaScript (Decryption)**
|
|
505
|
+
```javascript
|
|
506
|
+
const format = WasmPqcBinaryFormat.fromBytes(bytes);
|
|
507
|
+
console.log(`Algorithm: ${format.algorithm.name}`);
|
|
508
|
+
console.log(`Data: ${format.data.length} bytes`);
|
|
509
|
+
```
|
|
510
|
+
|
|
511
|
+
**Go (Decryption)**
|
|
512
|
+
```go
|
|
513
|
+
format, _ := pqc.FromBytes(bytes)
|
|
514
|
+
defer format.Free()
|
|
515
|
+
fmt.Printf("Algorithm: %s\n", format.GetAlgorithmName())
|
|
516
|
+
fmt.Printf("Data: %d bytes\n", len(format.GetData()))
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
### Example 3: Algorithm Migration
|
|
520
|
+
|
|
521
|
+
```rust
|
|
522
|
+
// Old data encrypted with Classical algorithm
|
|
523
|
+
let old_format = PqcBinaryFormat::from_bytes(&old_encrypted_data)?;
|
|
524
|
+
assert_eq!(old_format.algorithm(), Algorithm::Classical);
|
|
525
|
+
|
|
526
|
+
// Re-encrypt with Post-Quantum algorithm
|
|
527
|
+
let plaintext = decrypt_with_classical(&old_format)?;
|
|
528
|
+
let new_metadata = create_pq_metadata()?;
|
|
529
|
+
let new_format = PqcBinaryFormat::new(
|
|
530
|
+
Algorithm::PostQuantum,
|
|
531
|
+
new_metadata,
|
|
532
|
+
encrypt_with_pq(&plaintext)?,
|
|
533
|
+
);
|
|
534
|
+
|
|
535
|
+
// Same format, different algorithm!
|
|
536
|
+
```
|
|
537
|
+
|
|
538
|
+
## ๐ Use Cases
|
|
539
|
+
|
|
540
|
+
### 1. **Cross-Platform Encryption**
|
|
541
|
+
Encrypt in Rust, decrypt in Python, JavaScript, or Go using the same format.
|
|
542
|
+
|
|
543
|
+
### 2. **Long-Term Archival**
|
|
544
|
+
Self-describing format ensures data can be decrypted decades later even as algorithms evolve.
|
|
545
|
+
|
|
546
|
+
### 3. **Algorithm Agility**
|
|
547
|
+
Switch between algorithms without changing application code.
|
|
548
|
+
|
|
549
|
+
### 4. **Compliance & Audit**
|
|
550
|
+
Embedded metadata provides audit trail for regulatory compliance (GDPR, HIPAA, etc.).
|
|
551
|
+
|
|
552
|
+
### 5. **Research & Benchmarking**
|
|
553
|
+
Standardized format enables fair comparison of PQC algorithm performance.
|
|
554
|
+
|
|
555
|
+
## ๐งช Testing
|
|
556
|
+
|
|
557
|
+
```bash
|
|
558
|
+
# Run tests
|
|
559
|
+
cargo test
|
|
560
|
+
|
|
561
|
+
# Run tests with output
|
|
562
|
+
cargo test -- --nocapture
|
|
563
|
+
|
|
564
|
+
# Run specific test
|
|
565
|
+
cargo test test_binary_format_roundtrip
|
|
566
|
+
```
|
|
567
|
+
|
|
568
|
+
## ๐ Benchmarks
|
|
569
|
+
|
|
570
|
+
```bash
|
|
571
|
+
# Run benchmarks
|
|
572
|
+
cargo bench
|
|
573
|
+
|
|
574
|
+
# View benchmark results
|
|
575
|
+
open target/criterion/report/index.html
|
|
576
|
+
```
|
|
577
|
+
|
|
578
|
+
Performance characteristics:
|
|
579
|
+
- **Serialization**: ~50 MB/s for typical payloads
|
|
580
|
+
- **Deserialization**: ~45 MB/s (includes checksum verification)
|
|
581
|
+
- **Overhead**: ~100 bytes + metadata size
|
|
582
|
+
|
|
583
|
+
## ๐ง Development
|
|
584
|
+
|
|
585
|
+
### Building from Source
|
|
586
|
+
|
|
587
|
+
```bash
|
|
588
|
+
git clone https://github.com/PQCrypta/pqcrypta-community.git
|
|
589
|
+
cd pqcrypta-community
|
|
590
|
+
cargo build --release
|
|
591
|
+
```
|
|
592
|
+
|
|
593
|
+
### Running Examples
|
|
594
|
+
|
|
595
|
+
```bash
|
|
596
|
+
cargo run --example basic_usage
|
|
597
|
+
cargo run --example with_compression
|
|
598
|
+
cargo run --example cross_platform
|
|
599
|
+
```
|
|
600
|
+
|
|
601
|
+
## ๐ค Contributing
|
|
602
|
+
|
|
603
|
+
We welcome contributions! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
|
|
604
|
+
|
|
605
|
+
### Current Status
|
|
606
|
+
|
|
607
|
+
- **Language Bindings**: โ
**Rust** (native), โ
**Python** (tested v1.0.7), โ
**JavaScript/WASM** (tested v1.0.7), โ
**Go** (tested v1.0.7), โ
**C/C++** (tested v1.0.7)
|
|
608
|
+
- **Examples**: โ
9 validated examples across 6 languages
|
|
609
|
+
- **Package Distribution**: โ
**crates.io published!** | โณ PyPI, npm, pkg.go.dev ready
|
|
610
|
+
|
|
611
|
+
### Areas for Contribution
|
|
612
|
+
|
|
613
|
+
- **Additional Language Bindings**: Java, C#, Ruby, Swift, Kotlin - help us expand!
|
|
614
|
+
- **Documentation**: Tutorials, integration guides, video walkthroughs
|
|
615
|
+
- **Testing**: Additional test cases, fuzzing, property-based testing
|
|
616
|
+
- **Performance**: SIMD optimizations, benchmark improvements
|
|
617
|
+
- **Standards**: Help draft RFC for IETF standardization submission
|
|
618
|
+
- **Package Publishing**: Help publish to PyPI, npm, and other package registries
|
|
619
|
+
|
|
620
|
+
## ๐ License
|
|
621
|
+
|
|
622
|
+
Licensed under either of:
|
|
623
|
+
|
|
624
|
+
- MIT License ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
|
625
|
+
- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
|
|
626
|
+
|
|
627
|
+
at your option.
|
|
628
|
+
|
|
629
|
+
## ๐ Acknowledgments
|
|
630
|
+
|
|
631
|
+
This format was developed as part of the [PQCrypta](https://pqcrypta.com) enterprise post-quantum cryptography platform. Special thanks to:
|
|
632
|
+
|
|
633
|
+
- NIST Post-Quantum Cryptography Project
|
|
634
|
+
- The Rust cryptography community
|
|
635
|
+
- Contributors to pqcrypto, ring, and other foundational crates
|
|
636
|
+
|
|
637
|
+
## ๐ References
|
|
638
|
+
|
|
639
|
+
- [NIST Post-Quantum Cryptography](https://csrc.nist.gov/projects/post-quantum-cryptography)
|
|
640
|
+
- [ML-KEM (Kyber) Specification](https://csrc.nist.gov/pubs/fips/203/final)
|
|
641
|
+
- [ML-DSA (Dilithium) Specification](https://csrc.nist.gov/pubs/fips/204/final)
|
|
642
|
+
- [PQCrypta Documentation](https://pqcrypta.com/docs)
|
|
643
|
+
|
|
644
|
+
## ๐ Related Projects
|
|
645
|
+
|
|
646
|
+
- [pqcrypto](https://github.com/rustpq/pqcrypto) - Rust PQC implementations
|
|
647
|
+
- [Open Quantum Safe](https://openquantumsafe.org/) - PQC library collection
|
|
648
|
+
- [CIRCL](https://github.com/cloudflare/circl) - Cloudflare's crypto library
|
|
649
|
+
|
|
650
|
+
## ๐ฌ Community & Support
|
|
651
|
+
|
|
652
|
+
- **GitHub Issues**: [Report bugs](https://github.com/PQCrypta/pqcrypta-community/issues)
|
|
653
|
+
- **Discussions**: [Ask questions](https://github.com/PQCrypta/pqcrypta-community/discussions)
|
|
654
|
+
- **Website**: [pqcrypta.com](https://pqcrypta.com)
|
|
655
|
+
- **Documentation**: [docs.rs/pqc-binary-format](https://docs.rs/pqc-binary-format)
|
|
656
|
+
|
|
657
|
+
---
|
|
658
|
+
|
|
659
|
+
**Made with โค๏ธ by the PQCrypta Community**
|
|
660
|
+
|
|
661
|
+
*Securing the future, one byte at a time.*
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "pqc-binary-format",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"collaborators": [
|
|
5
|
+
"Allan <allan@pqcrypta.com>"
|
|
6
|
+
],
|
|
7
|
+
"description": "Standardized binary format for post-quantum cryptography encrypted data interchange",
|
|
8
|
+
"version": "1.0.7",
|
|
9
|
+
"license": "MIT OR Apache-2.0",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/PQCrypta/pqcrypta-community"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"pqc_binary_format_bg.wasm",
|
|
16
|
+
"pqc_binary_format.js",
|
|
17
|
+
"pqc_binary_format_bg.js",
|
|
18
|
+
"pqc_binary_format.d.ts"
|
|
19
|
+
],
|
|
20
|
+
"main": "pqc_binary_format.js",
|
|
21
|
+
"homepage": "https://pqcrypta.com",
|
|
22
|
+
"types": "pqc_binary_format.d.ts",
|
|
23
|
+
"sideEffects": [
|
|
24
|
+
"./pqc_binary_format.js",
|
|
25
|
+
"./snippets/*"
|
|
26
|
+
],
|
|
27
|
+
"keywords": [
|
|
28
|
+
"cryptography",
|
|
29
|
+
"post-quantum",
|
|
30
|
+
"pqc",
|
|
31
|
+
"encryption",
|
|
32
|
+
"binary-format"
|
|
33
|
+
]
|
|
34
|
+
}
|