Skip to content

Commit

Permalink
Implement changes from FIP 205 Initial Public Draft -> FIPS 205 Final (
Browse files Browse the repository at this point in the history
…#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
  • Loading branch information
tjade273 authored Aug 18, 2024
1 parent fe6176a commit cf34cd2
Show file tree
Hide file tree
Showing 15 changed files with 2,376 additions and 123 deletions.
38 changes: 22 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions slh-dsa/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "slh-dsa"
description = """
Pure Rust implementation of SLH-DSA (aka SPHINCS+) as described in the
FIPS-205 Inital Public Draft
FIPS-205 standard
"""
version = "0.0.2"
edition = "2021"
Expand All @@ -27,7 +27,7 @@ digest = "0.10.7"

[dev-dependencies]
hex-literal = "0.4.1"
hex = "0.4.1"
hex = { version = "0.4.1", features = ["serde"] }
num-bigint = "0.4.4"
quickcheck = "1"
quickcheck_macros = "1"
Expand All @@ -39,6 +39,8 @@ ctr = "0.9.2"
rand_core = "0.6.4"
paste = "1.0.15"
rand = "0.8.5"
serde_json = "1.0.124"
serde = { version = "1.0.207", features = ["derive"] }

[lib]
bench = false
Expand Down
4 changes: 2 additions & 2 deletions slh-dsa/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

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

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

## ⚠️ Security Warning

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

[RustCrypto]: https://github.com/RustCrypto
[FIPS-205 Inital Public Draft]: https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.205.ipd.pdf
[FIPS-205 Standard]: https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.205.pdf
2 changes: 1 addition & 1 deletion slh-dsa/src/hashes/sha2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ impl ForsParams for Sha2_192f {
type MD = U<{ (33 * 8 + 7) / 8 }>;
}
impl ParameterSet for Sha2_192f {
const NAME: &'static str = "SLH-DSA-SHA2-128f";
const NAME: &'static str = "SLH-DSA-SHA2-192f";
}

/// SHA2 at L5 security with small signatures
Expand Down
87 changes: 26 additions & 61 deletions slh-dsa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#![deny(missing_docs)] // Require all public interfaces to be documented

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

fn test_sign_verify<P: ParameterSet>() {
let mut rng = rand::thread_rng();
Expand All @@ -89,66 +90,7 @@ mod tests {
let sig = sk.try_sign(msg).unwrap();
vk.verify(msg, &sig).unwrap();
}

#[test]
fn test_sign_verify_shake_128f() {
test_sign_verify::<Shake128f>();
}

#[test]
fn test_sign_verify_shake_128s() {
test_sign_verify::<Shake128s>();
}

#[test]
fn test_sign_verify_shake_192f() {
test_sign_verify::<Shake192f>();
}

#[test]
fn test_sign_verify_shake_192s() {
test_sign_verify::<Shake192s>();
}

#[test]
fn test_sign_verify_shake_256f() {
test_sign_verify::<Shake256f>();
}

#[test]
fn test_sign_verify_shake_256s() {
test_sign_verify::<Shake256s>();
}

#[test]
fn test_sign_verify_sha2_128f() {
test_sign_verify::<Sha2_128f>();
}

#[test]
fn test_sign_verify_sha2_128s() {
test_sign_verify::<Sha2_128s>();
}

#[test]
fn test_sign_verify_sha2_192f() {
test_sign_verify::<Sha2_192f>();
}

#[test]
fn test_sign_verify_sha2_192s() {
test_sign_verify::<Sha2_192s>();
}

#[test]
fn test_sign_verify_sha2_256f() {
test_sign_verify::<Sha2_256f>();
}

#[test]
fn test_sign_verify_sha2_256s() {
test_sign_verify::<Sha2_256s>();
}
test_parameter_sets!(test_sign_verify);

// Check signature fails on modified message
#[test]
Expand Down Expand Up @@ -212,4 +154,27 @@ mod tests {
"Two successive randomized signatures over the same message should not be equal"
);
}

#[test]
fn test_sign_verify_nonempty_context() {
let mut rng = rand::thread_rng();
let sk = SigningKey::<Shake128f>::new(&mut rng);
let vk = sk.verifying_key();
let msg = b"Hello, world!";
let ctx = b"Test context";
let sig = sk.try_sign_with_context(msg, ctx, None).unwrap();
vk.try_verify_with_context(msg, ctx, &sig).unwrap();
}

#[test]
fn test_sign_verify_wrong_context() {
let mut rng = rand::thread_rng();
let sk = SigningKey::<Shake128f>::new(&mut rng);
let vk = sk.verifying_key();
let msg = b"Hello, world!";
let ctx = b"Test context!";
let wrong_ctx = b"Wrong context";
let sig = sk.try_sign_with_context(msg, ctx, None).unwrap();
assert!(vk.try_verify_with_context(msg, wrong_ctx, &sig).is_err());
}
}
Loading

0 comments on commit cf34cd2

Please sign in to comment.