@lib-q/fn-dsa 0.0.2 → 0.0.5

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 CHANGED
@@ -1,232 +1,232 @@
1
- # lib-Q FN-DSA
2
-
3
- A production-ready implementation of FN-DSA (FIPS 206) post-quantum digital signatures, fully integrated into the libQ cryptography library.
4
-
5
- ## Overview
6
-
7
- FN-DSA (Falcon-based Digital Signature Algorithm) is a NIST-approved post-quantum digital signature scheme that provides compact signatures with strong security guarantees. This implementation follows the FIPS 206 standard and is designed for high-performance applications requiring quantum-resistant cryptography.
8
-
9
- ## Key Features
10
-
11
- - **NIST-Approved**: Implements the FIPS 206 standard for FN-DSA
12
- - **High Performance**: Optimized implementations for x86_64 and ARM64 architectures
13
- - **Compact Signatures**: Significantly smaller signature sizes compared to other post-quantum schemes
14
- - **Multiple Security Levels**: Supports Level 1 (128-bit) and Level 5 (256-bit) security
15
- - **Memory Safe**: Zero unsafe code with automatic secure memory management
16
- - **Constant-Time Operations**: All cryptographic operations are constant-time to prevent timing attacks
17
- - **WASM Compatible**: Full WebAssembly support for web applications
18
- - **Comprehensive Testing**: Extensive test suite including security, performance, and interoperability tests
19
-
20
- ## Security Levels
21
-
22
- | Security Level | Parameter Set | Security (bits) | Use Case |
23
- |----------------|---------------|-----------------|----------|
24
- | Level 1 | FN-DSA-512 | 128 | General applications, IoT devices |
25
- | Level 5 | FN-DSA-1024 | 256 | High-security applications, government use |
26
-
27
- ## Installation
28
-
29
- ### Rust
30
-
31
- Add to your `Cargo.toml`:
32
-
33
- ```toml
34
- [dependencies]
35
- lib-q-fn-dsa = "0.0.2"
36
- ```
37
-
38
- ### Node.js
39
-
40
- ```bash
41
- npm install @lib-q/fn-dsa
42
- ```
43
-
44
- ## Usage
45
-
46
- ### Basic Usage
47
-
48
- ```rust
49
- use lib_q_fn_dsa::{FnDsa512, FnDsa1024};
50
-
51
- // Create an FN-DSA instance
52
- let fn_dsa = FnDsa512::new();
53
-
54
- // Generate a keypair
55
- let keypair = fn_dsa.generate_keypair()?;
56
-
57
- // Sign a message
58
- let message = b"Hello, FN-DSA!";
59
- let signature = fn_dsa.sign(&keypair.secret_key, message)?;
60
-
61
- // Verify the signature
62
- let is_valid = fn_dsa.verify(&keypair.public_key, message, &signature)?;
63
- assert!(is_valid);
64
- ```
65
-
66
- ### Advanced Usage
67
-
68
- ```rust
69
- use lib_q_fn_dsa::{FnDsa1024, KeyPair, Signature};
70
-
71
- // High-security application
72
- let fn_dsa = FnDsa1024::new();
73
-
74
- // Generate keypair with custom entropy
75
- let mut rng = rand::thread_rng();
76
- let keypair = fn_dsa.generate_keypair_with_rng(&mut rng)?;
77
-
78
- // Sign with additional context
79
- let context = b"application_context";
80
- let signature = fn_dsa.sign_with_context(
81
- &keypair.secret_key,
82
- message,
83
- context
84
- )?;
85
-
86
- // Verify with context
87
- let is_valid = fn_dsa.verify_with_context(
88
- &keypair.public_key,
89
- message,
90
- &signature,
91
- context
92
- )?;
93
- ```
94
-
95
- ### WebAssembly Usage
96
-
97
- ```javascript
98
- import { FnDsa512 } from '@lib-q/fn-dsa';
99
-
100
- // Initialize FN-DSA
101
- const fnDsa = new FnDsa512();
102
-
103
- // Generate keypair
104
- const keypair = fnDsa.generateKeypair();
105
-
106
- // Sign message
107
- const message = new TextEncoder().encode("Hello, FN-DSA!");
108
- const signature = fnDsa.sign(keypair.secretKey, message);
109
-
110
- // Verify signature
111
- const isValid = fnDsa.verify(keypair.publicKey, message, signature);
112
- console.log('Signature valid:', isValid);
113
- ```
114
-
115
- ## API Reference
116
-
117
- ### Core Types
118
-
119
- - **`FnDsa512`**: FN-DSA implementation with 512-bit parameters (Level 1 security)
120
- - **`FnDsa1024`**: FN-DSA implementation with 1024-bit parameters (Level 5 security)
121
- - **`KeyPair`**: Container for public and secret keys
122
- - **`PublicKey`**: Public key for signature verification
123
- - **`SecretKey`**: Secret key for signature generation
124
- - **`Signature`**: Digital signature
125
-
126
- ### Key Methods
127
-
128
- - **`generate_keypair()`**: Generate a new keypair using system entropy
129
- - **`generate_keypair_with_rng(rng)`**: Generate keypair with custom random number generator
130
- - **`sign(secret_key, message)`**: Sign a message
131
- - **`sign_with_context(secret_key, message, context)`**: Sign with additional context
132
- - **`verify(public_key, message, signature)`**: Verify a signature
133
- - **`verify_with_context(public_key, message, signature, context)`**: Verify with context
134
-
135
- ## Documentation
136
-
137
- - [Constrained-device signature suite](docs/CONSTRAINED_DEVICE_SUITE.md) — FN-DSA vs ML-DSA-65 bandwidth trade-offs for IoT and low-rate links.
138
- - [KAT verification against FIPS 206](docs/KAT_VERIFICATION.md) — how internal vectors relate to published test data and optional `shake256x4` divergence.
139
-
140
- ## Testing
141
-
142
- ### Run All Tests
143
-
144
- ```bash
145
- cargo test
146
- ```
147
-
148
- ### Run Security Tests
149
-
150
- ```bash
151
- cargo test --test security_tests
152
- ```
153
-
154
- ### Run Performance Benchmarks
155
-
156
- ```bash
157
- cargo bench
158
- ```
159
-
160
- ### Run Constant-Time Tests
161
-
162
- ```bash
163
- cargo test --test constant_time
164
- ```
165
-
166
- ## Integration
167
-
168
- This crate is fully integrated into the libQ ecosystem:
169
-
170
- - **Algorithm Registry**: Registered in `lib-q-core` for automatic discovery
171
- - **CI/CD Pipeline**: Complete testing, security validation, and publishing workflows
172
- - **WASM Support**: Automatic WebAssembly compilation and publishing
173
- - **Documentation**: Integrated into main libQ documentation
174
-
175
- ## Implementation Notes
176
-
177
- ### Version Differences
178
-
179
- This implementation is based on the upstream `fn-dsa` reference implementation but uses version `0.0.2` of the internal crates (`fn-dsa-comm`, `fn-dsa-kgen`, `fn-dsa-sign`, `fn-dsa-vrfy`) rather than the upstream `0.3.0` version. This version difference was chosen during integration into the libQ workspace to maintain consistency with the libQ versioning scheme.
180
-
181
- ### Security Improvements
182
-
183
- This implementation includes security enhancements over the upstream reference:
184
-
185
- 1. **Removed HASH_ID_ORIGINAL_FALCON**: The original Falcon design bypassed domain separation, creating a critical security vulnerability that could enable cross-protocol attacks. This implementation enforces proper FN-DSA domain separation as specified in the NIST standard.
186
- 2. **Hardened hash_to_point**: The `hash_to_point` function no longer supports the insecure original Falcon mode, ensuring all operations use proper domain separation.
187
-
188
- ### API Compatibility Differences
189
-
190
- Due to dependency version differences, there are minor API differences from the upstream reference:
191
-
192
- 1. **RngError type**:
193
- - Reference uses `rand_core::Error` from rand_core 0.6.4
194
- - This implementation uses `core::fmt::Error` because rand_core 0.9.3 (used in libQ) does not export `Error` directly
195
- - Both are compatible with `no_std` and provide equivalent functionality
196
-
197
- ### SHAKE256x4 Implementation Differences
198
-
199
- When the `shake256x4` feature is enabled, the Known Answer Test (KAT) values differ from the upstream reference implementation. This is due to:
200
-
201
- 1. **Dependency Version Differences**: Different versions of `cpufeatures` and potentially `rand_core` between this implementation and upstream
202
- 2. **AVX2 Code Generation**: Subtle differences in how the compiler generates AVX2 instructions or manages state
203
- 3. **Integration Changes**: Minor adaptations made during integration into the libQ workspace structure
204
-
205
- **Important**: These differences do NOT affect cryptographic correctness or interoperability:
206
- - All signatures are mathematically valid and verify correctly
207
- - The implementation is fully FIPS 206-compliant
208
- - Signatures generated by this implementation can be verified by any FIPS 206-compliant implementation
209
- - Signatures from other FIPS 206-compliant implementations can be verified by this implementation
210
-
211
- The KAT differences only affect the internal test vectors used for regression testing. The actual signature format and verification logic are identical to the standard.
212
-
213
- ### Interoperability
214
-
215
- This implementation is fully interoperable with other FIPS 206-compliant FN-DSA implementations:
216
-
217
- - **Signature Format**: Uses the standard FIPS 206 signature encoding
218
- - **Key Format**: Uses the standard FIPS 206 key encoding
219
- - **Verification**: Implements the standard FIPS 206 verification algorithm
220
- - **Domain Separation**: Correctly implements FIPS 206 domain separation
221
-
222
- Signatures generated by this implementation will be accepted by any compliant FN-DSA verifier, and this implementation will accept signatures from any compliant FN-DSA signer.
223
-
224
- ## Workspace
225
-
226
- Enable via [`lib-q-sig`](../lib-q-sig) with feature `fn-dsa`, or use this crate directly. See the [workspace README](../README.md).
227
-
228
- ## License
229
-
1
+ # lib-Q FN-DSA
2
+
3
+ A production-ready implementation of FN-DSA (FIPS 206) post-quantum digital signatures, fully integrated into the libQ cryptography library.
4
+
5
+ ## Overview
6
+
7
+ FN-DSA (Falcon-based Digital Signature Algorithm) is a NIST-approved post-quantum digital signature scheme that provides compact signatures with strong security guarantees. This implementation follows the FIPS 206 standard and is designed for high-performance applications requiring quantum-resistant cryptography.
8
+
9
+ ## Key Features
10
+
11
+ - **NIST-Approved**: Implements the FIPS 206 standard for FN-DSA
12
+ - **High Performance**: Optimized implementations for x86_64 and ARM64 architectures
13
+ - **Compact Signatures**: Significantly smaller signature sizes compared to other post-quantum schemes
14
+ - **Multiple Security Levels**: Supports Level 1 (128-bit) and Level 5 (256-bit) security
15
+ - **Memory Safe**: Zero unsafe code with automatic secure memory management
16
+ - **Constant-Time Operations**: All cryptographic operations are constant-time to prevent timing attacks
17
+ - **WASM Compatible**: Full WebAssembly support for web applications
18
+ - **Comprehensive Testing**: Extensive test suite including security, performance, and interoperability tests
19
+
20
+ ## Security Levels
21
+
22
+ | Security Level | Parameter Set | Security (bits) | Use Case |
23
+ |----------------|---------------|-----------------|----------|
24
+ | Level 1 | FN-DSA-512 | 128 | General applications, IoT devices |
25
+ | Level 5 | FN-DSA-1024 | 256 | High-security applications, government use |
26
+
27
+ ## Installation
28
+
29
+ ### Rust
30
+
31
+ Add to your `Cargo.toml`:
32
+
33
+ ```toml
34
+ [dependencies]
35
+ lib-q-fn-dsa = "0.0.5"
36
+ ```
37
+
38
+ ### Node.js
39
+
40
+ ```bash
41
+ npm install @lib-q/fn-dsa
42
+ ```
43
+
44
+ ## Usage
45
+
46
+ ### Basic Usage
47
+
48
+ ```rust
49
+ use lib_q_fn_dsa::{FnDsa512, FnDsa1024};
50
+
51
+ // Create an FN-DSA instance
52
+ let fn_dsa = FnDsa512::new();
53
+
54
+ // Generate a keypair
55
+ let keypair = fn_dsa.generate_keypair()?;
56
+
57
+ // Sign a message
58
+ let message = b"Hello, FN-DSA!";
59
+ let signature = fn_dsa.sign(&keypair.secret_key, message)?;
60
+
61
+ // Verify the signature
62
+ let is_valid = fn_dsa.verify(&keypair.public_key, message, &signature)?;
63
+ assert!(is_valid);
64
+ ```
65
+
66
+ ### Advanced Usage
67
+
68
+ ```rust
69
+ use lib_q_fn_dsa::{FnDsa1024, KeyPair, Signature};
70
+
71
+ // High-security application
72
+ let fn_dsa = FnDsa1024::new();
73
+
74
+ // Generate keypair with custom entropy
75
+ let mut rng = rand::thread_rng();
76
+ let keypair = fn_dsa.generate_keypair_with_rng(&mut rng)?;
77
+
78
+ // Sign with additional context
79
+ let context = b"application_context";
80
+ let signature = fn_dsa.sign_with_context(
81
+ &keypair.secret_key,
82
+ message,
83
+ context
84
+ )?;
85
+
86
+ // Verify with context
87
+ let is_valid = fn_dsa.verify_with_context(
88
+ &keypair.public_key,
89
+ message,
90
+ &signature,
91
+ context
92
+ )?;
93
+ ```
94
+
95
+ ### WebAssembly Usage
96
+
97
+ ```javascript
98
+ import { FnDsa512 } from '@lib-q/fn-dsa';
99
+
100
+ // Initialize FN-DSA
101
+ const fnDsa = new FnDsa512();
102
+
103
+ // Generate keypair
104
+ const keypair = fnDsa.generateKeypair();
105
+
106
+ // Sign message
107
+ const message = new TextEncoder().encode("Hello, FN-DSA!");
108
+ const signature = fnDsa.sign(keypair.secretKey, message);
109
+
110
+ // Verify signature
111
+ const isValid = fnDsa.verify(keypair.publicKey, message, signature);
112
+ console.log('Signature valid:', isValid);
113
+ ```
114
+
115
+ ## API Reference
116
+
117
+ ### Core Types
118
+
119
+ - **`FnDsa512`**: FN-DSA implementation with 512-bit parameters (Level 1 security)
120
+ - **`FnDsa1024`**: FN-DSA implementation with 1024-bit parameters (Level 5 security)
121
+ - **`KeyPair`**: Container for public and secret keys
122
+ - **`PublicKey`**: Public key for signature verification
123
+ - **`SecretKey`**: Secret key for signature generation
124
+ - **`Signature`**: Digital signature
125
+
126
+ ### Key Methods
127
+
128
+ - **`generate_keypair()`**: Generate a new keypair using system entropy
129
+ - **`generate_keypair_with_rng(rng)`**: Generate keypair with custom random number generator
130
+ - **`sign(secret_key, message)`**: Sign a message
131
+ - **`sign_with_context(secret_key, message, context)`**: Sign with additional context
132
+ - **`verify(public_key, message, signature)`**: Verify a signature
133
+ - **`verify_with_context(public_key, message, signature, context)`**: Verify with context
134
+
135
+ ## Documentation
136
+
137
+ - [Constrained-device signature suite](docs/CONSTRAINED_DEVICE_SUITE.md) — FN-DSA vs ML-DSA-65 bandwidth trade-offs for IoT and low-rate links.
138
+ - [KAT verification against FIPS 206](docs/KAT_VERIFICATION.md) — how internal vectors relate to published test data and optional `shake256x4` divergence.
139
+
140
+ ## Testing
141
+
142
+ ### Run All Tests
143
+
144
+ ```bash
145
+ cargo test
146
+ ```
147
+
148
+ ### Run Security Tests
149
+
150
+ ```bash
151
+ cargo test --test security_tests
152
+ ```
153
+
154
+ ### Run Performance Benchmarks
155
+
156
+ ```bash
157
+ cargo bench
158
+ ```
159
+
160
+ ### Run Constant-Time Tests
161
+
162
+ ```bash
163
+ cargo test --test constant_time
164
+ ```
165
+
166
+ ## Integration
167
+
168
+ This crate is fully integrated into the libQ ecosystem:
169
+
170
+ - **Algorithm Registry**: Registered in `lib-q-core` for automatic discovery
171
+ - **CI/CD Pipeline**: Complete testing, security validation, and publishing workflows
172
+ - **WASM Support**: Automatic WebAssembly compilation and publishing
173
+ - **Documentation**: Integrated into main libQ documentation
174
+
175
+ ## Implementation Notes
176
+
177
+ ### Version Differences
178
+
179
+ This implementation is based on the upstream `fn-dsa` reference implementation but uses version `0.0.5` of the internal crates (`fn-dsa-comm`, `fn-dsa-kgen`, `fn-dsa-sign`, `fn-dsa-vrfy`) rather than the upstream `0.3.0` version. This version difference was chosen during integration into the libQ workspace to maintain consistency with the libQ versioning scheme.
180
+
181
+ ### Security Improvements
182
+
183
+ This implementation includes security enhancements over the upstream reference:
184
+
185
+ 1. **Removed HASH_ID_ORIGINAL_FALCON**: The original Falcon design bypassed domain separation, creating a critical security vulnerability that could enable cross-protocol attacks. This implementation enforces proper FN-DSA domain separation as specified in the NIST standard.
186
+ 2. **Hardened hash_to_point**: The `hash_to_point` function no longer supports the insecure original Falcon mode, ensuring all operations use proper domain separation.
187
+
188
+ ### API Compatibility Differences
189
+
190
+ Due to dependency version differences, there are minor API differences from the upstream reference:
191
+
192
+ 1. **RngError type**:
193
+ - Reference uses `rand_core::Error` from rand_core 0.6.4
194
+ - This implementation uses `core::fmt::Error` because rand_core 0.9.3 (used in libQ) does not export `Error` directly
195
+ - Both are compatible with `no_std` and provide equivalent functionality
196
+
197
+ ### SHAKE256x4 Implementation Differences
198
+
199
+ When the `shake256x4` feature is enabled, the Known Answer Test (KAT) values differ from the upstream reference implementation. This is due to:
200
+
201
+ 1. **Dependency Version Differences**: Different versions of `cpufeatures` and potentially `rand_core` between this implementation and upstream
202
+ 2. **AVX2 Code Generation**: Subtle differences in how the compiler generates AVX2 instructions or manages state
203
+ 3. **Integration Changes**: Minor adaptations made during integration into the libQ workspace structure
204
+
205
+ **Important**: These differences do NOT affect cryptographic correctness or interoperability:
206
+ - All signatures are mathematically valid and verify correctly
207
+ - The implementation is fully FIPS 206-compliant
208
+ - Signatures generated by this implementation can be verified by any FIPS 206-compliant implementation
209
+ - Signatures from other FIPS 206-compliant implementations can be verified by this implementation
210
+
211
+ The KAT differences only affect the internal test vectors used for regression testing. The actual signature format and verification logic are identical to the standard.
212
+
213
+ ### Interoperability
214
+
215
+ This implementation is fully interoperable with other FIPS 206-compliant FN-DSA implementations:
216
+
217
+ - **Signature Format**: Uses the standard FIPS 206 signature encoding
218
+ - **Key Format**: Uses the standard FIPS 206 key encoding
219
+ - **Verification**: Implements the standard FIPS 206 verification algorithm
220
+ - **Domain Separation**: Correctly implements FIPS 206 domain separation
221
+
222
+ Signatures generated by this implementation will be accepted by any compliant FN-DSA verifier, and this implementation will accept signatures from any compliant FN-DSA signer.
223
+
224
+ ## Workspace
225
+
226
+ Enable via [`lib-q-sig`](../lib-q-sig) with feature `fn-dsa`, or use this crate directly. See the [workspace README](../README.md).
227
+
228
+ ## License
229
+
230
230
  This project is licensed under the Apache 2.0 License - see the [LICENSE](../LICENSE) file for details.
231
231
  ## Subresource integrity (SHA-384)
232
- Paths in `integrity-manifest.json` are relative to the package root.
232
+ Paths in `integrity-manifest.json` are relative to the package root (including `web/` and `nodejs/` when both ship).
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "integrity": {
3
- "nodejs/lib_q_fn_dsa_bg.wasm": "sha384-qwk+k92xADJ0GytJwl0rcceVDNnNhB7iGxVNOJiP1BqR7f35UIp4e/rUxqiS4C7C",
4
- "web/lib_q_fn_dsa_bg.wasm": "sha384-qwk+k92xADJ0GytJwl0rcceVDNnNhB7iGxVNOJiP1BqR7f35UIp4e/rUxqiS4C7C"
3
+ "nodejs/lib_q_fn_dsa_bg.wasm": "sha384-dF0csQXgAWA8m8rAEE55S7A7CrSNa7KYwuFqB10vPFVkyq+r/AXs1gli7xIJklhp",
4
+ "web/lib_q_fn_dsa_bg.wasm": "sha384-dF0csQXgAWA8m8rAEE55S7A7CrSNa7KYwuFqB10vPFVkyq+r/AXs1gli7xIJklhp"
5
5
  }
6
6
  }