Skip to content

Commit cf34cd2

Browse files
authored
Implement changes from FIP 205 Initial Public Draft -> FIPS 205 Final (#844)
- Implement changes from FIP 205 Initial Public Draft -> FIPS 205 Final - Add SLH-DSA CVP known answer tests - Add E2E tests for sign-with-context and require alloc for KATs
1 parent fe6176a commit cf34cd2

File tree

15 files changed

+2376
-123
lines changed

15 files changed

+2376
-123
lines changed

Cargo.lock

Lines changed: 22 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

slh-dsa/Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "slh-dsa"
33
description = """
44
Pure Rust implementation of SLH-DSA (aka SPHINCS+) as described in the
5-
FIPS-205 Inital Public Draft
5+
FIPS-205 standard
66
"""
77
version = "0.0.2"
88
edition = "2021"
@@ -27,7 +27,7 @@ digest = "0.10.7"
2727

2828
[dev-dependencies]
2929
hex-literal = "0.4.1"
30-
hex = "0.4.1"
30+
hex = { version = "0.4.1", features = ["serde"] }
3131
num-bigint = "0.4.4"
3232
quickcheck = "1"
3333
quickcheck_macros = "1"
@@ -39,6 +39,8 @@ ctr = "0.9.2"
3939
rand_core = "0.6.4"
4040
paste = "1.0.15"
4141
rand = "0.8.5"
42+
serde_json = "1.0.124"
43+
serde = { version = "1.0.207", features = ["derive"] }
4244

4345
[lib]
4446
bench = false

slh-dsa/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
Pure Rust implementation of the SLH-DSA (aka SPHINCS+) signature scheme.
1111

12-
Implemented based on the [FIPS-205 Inital Public Draft].
12+
Implemented based on the [FIPS-205 Standard].
1313

1414
## ⚠️ Security Warning
1515

@@ -53,4 +53,4 @@ dual licensed as above, without any additional terms or conditions.
5353
[//]: # (links)
5454

5555
[RustCrypto]: https://github.com/RustCrypto
56-
[FIPS-205 Inital Public Draft]: https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.205.ipd.pdf
56+
[FIPS-205 Standard]: https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.205.pdf

slh-dsa/src/hashes/sha2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ impl ForsParams for Sha2_192f {
349349
type MD = U<{ (33 * 8 + 7) / 8 }>;
350350
}
351351
impl ParameterSet for Sha2_192f {
352-
const NAME: &'static str = "SLH-DSA-SHA2-128f";
352+
const NAME: &'static str = "SLH-DSA-SHA2-192f";
353353
}
354354

355355
/// SHA2 at L5 security with small signatures

slh-dsa/src/lib.rs

Lines changed: 26 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#![deny(missing_docs)] // Require all public interfaces to be documented
99

1010
//! # Usage
11-
//! This crate implements the Stateless Hash-based Digital Signature Algorithm (SLH-DSA) based on the draft
11+
//! This crate implements the Stateless Hash-based Digital Signature Algorithm (SLH-DSA) based on the finalized
1212
//! standard by NIST in FIPS-205. SLH-DSA (based on the SPHINCS+ submission) is a signature algorithm designed
1313
//! to be resistant to quantum computers.
1414
//!
@@ -80,6 +80,7 @@ mod tests {
8080
use super::*;
8181
use rand::Rng;
8282
use signature::*;
83+
use util::macros::test_parameter_sets;
8384

8485
fn test_sign_verify<P: ParameterSet>() {
8586
let mut rng = rand::thread_rng();
@@ -89,66 +90,7 @@ mod tests {
8990
let sig = sk.try_sign(msg).unwrap();
9091
vk.verify(msg, &sig).unwrap();
9192
}
92-
93-
#[test]
94-
fn test_sign_verify_shake_128f() {
95-
test_sign_verify::<Shake128f>();
96-
}
97-
98-
#[test]
99-
fn test_sign_verify_shake_128s() {
100-
test_sign_verify::<Shake128s>();
101-
}
102-
103-
#[test]
104-
fn test_sign_verify_shake_192f() {
105-
test_sign_verify::<Shake192f>();
106-
}
107-
108-
#[test]
109-
fn test_sign_verify_shake_192s() {
110-
test_sign_verify::<Shake192s>();
111-
}
112-
113-
#[test]
114-
fn test_sign_verify_shake_256f() {
115-
test_sign_verify::<Shake256f>();
116-
}
117-
118-
#[test]
119-
fn test_sign_verify_shake_256s() {
120-
test_sign_verify::<Shake256s>();
121-
}
122-
123-
#[test]
124-
fn test_sign_verify_sha2_128f() {
125-
test_sign_verify::<Sha2_128f>();
126-
}
127-
128-
#[test]
129-
fn test_sign_verify_sha2_128s() {
130-
test_sign_verify::<Sha2_128s>();
131-
}
132-
133-
#[test]
134-
fn test_sign_verify_sha2_192f() {
135-
test_sign_verify::<Sha2_192f>();
136-
}
137-
138-
#[test]
139-
fn test_sign_verify_sha2_192s() {
140-
test_sign_verify::<Sha2_192s>();
141-
}
142-
143-
#[test]
144-
fn test_sign_verify_sha2_256f() {
145-
test_sign_verify::<Sha2_256f>();
146-
}
147-
148-
#[test]
149-
fn test_sign_verify_sha2_256s() {
150-
test_sign_verify::<Sha2_256s>();
151-
}
93+
test_parameter_sets!(test_sign_verify);
15294

15395
// Check signature fails on modified message
15496
#[test]
@@ -212,4 +154,27 @@ mod tests {
212154
"Two successive randomized signatures over the same message should not be equal"
213155
);
214156
}
157+
158+
#[test]
159+
fn test_sign_verify_nonempty_context() {
160+
let mut rng = rand::thread_rng();
161+
let sk = SigningKey::<Shake128f>::new(&mut rng);
162+
let vk = sk.verifying_key();
163+
let msg = b"Hello, world!";
164+
let ctx = b"Test context";
165+
let sig = sk.try_sign_with_context(msg, ctx, None).unwrap();
166+
vk.try_verify_with_context(msg, ctx, &sig).unwrap();
167+
}
168+
169+
#[test]
170+
fn test_sign_verify_wrong_context() {
171+
let mut rng = rand::thread_rng();
172+
let sk = SigningKey::<Shake128f>::new(&mut rng);
173+
let vk = sk.verifying_key();
174+
let msg = b"Hello, world!";
175+
let ctx = b"Test context!";
176+
let wrong_ctx = b"Wrong context";
177+
let sig = sk.try_sign_with_context(msg, ctx, None).unwrap();
178+
assert!(vk.try_verify_with_context(msg, wrong_ctx, &sig).is_err());
179+
}
215180
}

0 commit comments

Comments
 (0)