mirror of
https://github.com/saymrwulf/fips205-source.git
synced 2026-09-03 19:53:49 +00:00
much tighter clippy
This commit is contained in:
parent
834e75b603
commit
e68fb16221
6 changed files with 47 additions and 26 deletions
28
src/lib.rs
28
src/lib.rs
|
|
@ -1,7 +1,16 @@
|
|||
#![no_std]
|
||||
#![deny(clippy::pedantic)]
|
||||
#![deny(warnings)]
|
||||
#![deny(missing_docs)]
|
||||
#![deny(clippy::pedantic, warnings, missing_docs, unsafe_code)]
|
||||
// Most of the 'allow' category...
|
||||
#![deny(absolute_paths_not_starting_with_crate, dead_code)]
|
||||
#![deny(elided_lifetimes_in_paths, explicit_outlives_requirements, keyword_idents)]
|
||||
#![deny(let_underscore_drop, macro_use_extern_crate, meta_variable_misuse, missing_abi)]
|
||||
#![deny(non_ascii_idents, rust_2021_incompatible_closure_captures)]
|
||||
#![deny(rust_2021_incompatible_or_patterns, rust_2021_prefixes_incompatible_syntax)]
|
||||
#![deny(rust_2021_prelude_collisions, single_use_lifetimes, trivial_casts)]
|
||||
#![deny(trivial_numeric_casts, unreachable_pub, unsafe_op_in_unsafe_fn, unstable_features)]
|
||||
#![deny(unused_extern_crates, unused_import_braces, unused_lifetimes, unused_macro_rules)]
|
||||
#![deny(unused_qualifications, unused_results, variant_size_differences)]
|
||||
//
|
||||
#![doc = include_str!("../README.md")]
|
||||
|
||||
// Implements FIPS 205 Stateless Hash-Based Digital Signature Standard.
|
||||
|
|
@ -209,7 +218,8 @@ macro_rules! functionality {
|
|||
sig.map(|s| s.serialize())
|
||||
}
|
||||
|
||||
/// blah!
|
||||
/// As of Oct 2 2024, the NIST test vectors are applied to the **internal** functions rather than
|
||||
/// the external API.
|
||||
/// # Errors
|
||||
fn _test_only_raw_sign(
|
||||
&self, rng: &mut impl CryptoRngCore, m: &[u8], randomize: bool,
|
||||
|
|
@ -259,19 +269,15 @@ macro_rules! functionality {
|
|||
let sig = SlhDsaSig::<A, D, HP, K, LEN, N>::deserialize(sig_bytes);
|
||||
let mut phm = [0u8; 64]; // hashers don't all play well with each other (varying output size)
|
||||
let (oid, phm_len) = hash_message(m, ph, &mut phm);
|
||||
let mp: &[&[u8]] = &[
|
||||
&[1u8],
|
||||
&[ctx.len().to_le_bytes()[0]],
|
||||
ctx,
|
||||
&oid,
|
||||
&phm[0..phm_len],
|
||||
];
|
||||
let mp: &[&[u8]] = &[&[1u8], &[ctx.len().to_le_bytes()[0]], ctx, &oid, &phm[0..phm_len]];
|
||||
let res = crate::slh::slh_verify::<A, D, H, HP, K, LEN, M, N>(
|
||||
&HASHERS, &mp, &sig, &self.0,
|
||||
);
|
||||
res
|
||||
}
|
||||
|
||||
/// As of Oct 2 2024, the NIST test vectors are applied to the **internal** functions rather than
|
||||
/// the external API.
|
||||
fn _test_only_raw_verify(
|
||||
&self, m: &[u8], sig_bytes: &[u8; SIG_LEN],
|
||||
) -> Result<bool, &'static str> {
|
||||
|
|
|
|||
|
|
@ -247,8 +247,10 @@ pub trait Signer {
|
|||
) -> Result<Self::Signature, &'static str>;
|
||||
|
||||
|
||||
/// blah
|
||||
/// As of Oct 2 2024, the NIST test vectors are applied to the **internal** functions rather than
|
||||
/// the external API.
|
||||
/// # Errors
|
||||
#[deprecated = "Temporary function to allow application of internal nist vectors; will be removed"]
|
||||
fn _test_only_raw_sign(
|
||||
&self, rng: &mut impl CryptoRngCore, m: &[u8], randomize: bool,
|
||||
) -> Result<Self::Signature, &'static str>;
|
||||
|
|
@ -291,15 +293,16 @@ pub trait Verifier {
|
|||
#[must_use]
|
||||
fn verify(&self, message: &[u8], signature: &Self::Signature, ctx: &[u8]) -> bool;
|
||||
|
||||
|
||||
/// blah
|
||||
/// blah todo
|
||||
#[must_use]
|
||||
fn verify_hash(&self, message: &[u8], signature: &Self::Signature, ctx: &[u8], ph: &Ph)
|
||||
-> bool;
|
||||
|
||||
|
||||
/// blah
|
||||
/// As of Oct 2 2024, the NIST test vectors are applied to the **internal** functions rather than
|
||||
/// the external API.
|
||||
/// # Errors
|
||||
#[deprecated = "Temporary function to allow application of internal nist vectors; will be removed"]
|
||||
fn _test_only_raw_verify(
|
||||
&self, m: &[u8], sig_bytes: &Self::Signature,
|
||||
) -> Result<bool, &'static str>;
|
||||
|
|
|
|||
10
src/types.rs
10
src/types.rs
|
|
@ -32,7 +32,7 @@ pub(crate) struct SlhDsaSig<
|
|||
|
||||
/// Fig 16 on page 33
|
||||
#[derive(Clone, Zeroize, ZeroizeOnDrop)]
|
||||
pub struct SlhPublicKey<const N: usize> {
|
||||
pub(crate) struct SlhPublicKey<const N: usize> {
|
||||
pub(crate) pk_seed: [u8; N],
|
||||
pub(crate) pk_root: [u8; N],
|
||||
}
|
||||
|
|
@ -40,7 +40,7 @@ pub struct SlhPublicKey<const N: usize> {
|
|||
|
||||
/// Fig 15 on page 33
|
||||
#[derive(Clone, Debug, Zeroize, ZeroizeOnDrop)]
|
||||
pub struct SlhPrivateKey<const N: usize> {
|
||||
pub(crate) struct SlhPrivateKey<const N: usize> {
|
||||
pub(crate) sk_seed: [u8; N],
|
||||
pub(crate) sk_prf: [u8; N],
|
||||
pub(crate) pk_seed: [u8; N],
|
||||
|
|
@ -77,18 +77,18 @@ pub(crate) struct HtSig<const D: usize, const HP: usize, const LEN: usize, const
|
|||
|
||||
/// Fig 10 on page 19
|
||||
#[derive(Clone, Debug, Zeroize, ZeroizeOnDrop)]
|
||||
pub struct WotsSig<const LEN: usize, const N: usize> {
|
||||
pub(crate) struct WotsSig<const LEN: usize, const N: usize> {
|
||||
pub(crate) data: [[u8; N]; LEN],
|
||||
}
|
||||
|
||||
|
||||
#[derive(Clone, Zeroize, ZeroizeOnDrop)]
|
||||
pub struct WotsPk<const N: usize>(pub(crate) [u8; N]);
|
||||
pub(crate) struct WotsPk<const N: usize>(pub(crate) [u8; N]);
|
||||
|
||||
|
||||
/// Fig 11 on page 22
|
||||
#[derive(Clone, Debug, Zeroize, ZeroizeOnDrop)]
|
||||
pub struct XmssSig<const HP: usize, const LEN: usize, const N: usize> {
|
||||
pub(crate) struct XmssSig<const HP: usize, const LEN: usize, const N: usize> {
|
||||
pub(crate) sig_wots: WotsSig<LEN, N>,
|
||||
pub(crate) auth: [[u8; N]; HP],
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
use crate::hashers::Hashers;
|
||||
use crate::helpers;
|
||||
use crate::helpers::{base_2b, to_byte};
|
||||
use crate::types::{Adrs, WotsPk, WotsSig, WOTS_PK, WOTS_PRF};
|
||||
|
||||
|
|
@ -82,8 +81,7 @@ pub(crate) fn wots_pkgen<const K: usize, const LEN: usize, const M: usize, const
|
|||
adrs.set_chain_address(i);
|
||||
|
||||
// 8: tmp[i] ← chain(sk, 0, w − 1, PK.seed, ADRS) ▷ Compute public value for chain i
|
||||
tmp[i as usize] =
|
||||
chain(hashers, sk, 0, crate::W - 1, pk_seed, &adrs);
|
||||
tmp[i as usize] = chain(hashers, sk, 0, crate::W - 1, pk_seed, &adrs);
|
||||
|
||||
// 9: end for
|
||||
}
|
||||
|
|
@ -139,7 +137,7 @@ pub(crate) fn wots_sign<const K: usize, const LEN: usize, const M: usize, const
|
|||
|
||||
// 7: msg ← msg ∥ base_2b(toByte(csum, ceil(len2·lgw/8)), lgw, len2) ▷ Convert csum to base w
|
||||
base_2b(
|
||||
&helpers::to_byte(csum, (crate::LEN2 * crate::LGW + 7) / 8),
|
||||
&to_byte(csum, (crate::LEN2 * crate::LGW + 7) / 8),
|
||||
crate::LGW,
|
||||
crate::LEN2,
|
||||
&mut msg[(2 * N)..],
|
||||
|
|
|
|||
|
|
@ -223,6 +223,7 @@ macro_rules! test_sign {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[allow(deprecated)]
|
||||
fn run_signing_tests() {
|
||||
let mut fail_count = 0;
|
||||
let file = "tests/nist_acvp_vectors/SLH-DSA-sigGen-FIPS205/internalProjection.json";
|
||||
|
|
@ -353,6 +354,7 @@ macro_rules! test_verify {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[allow(deprecated)]
|
||||
fn run_verification_tests() {
|
||||
let mut fail_count = 0;
|
||||
let file = "tests/nist_acvp_vectors/SLH-DSA-sigVer-FIPS205/internalProjection.json";
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ impl TestRng {
|
|||
|
||||
|
||||
#[test]
|
||||
#[allow(deprecated)]
|
||||
fn vector_slh_dsa_shake_128s() {
|
||||
use fips205::slh_dsa_shake_128s::KG;
|
||||
let m = decode("D81C4D8D734FCBFBEADE3D3F8A039FAA2A2C9957E835AD55B22E75BF57BB556AC8").unwrap();
|
||||
|
|
@ -62,6 +63,7 @@ fn vector_slh_dsa_shake_128s() {
|
|||
|
||||
|
||||
#[test]
|
||||
#[allow(deprecated)]
|
||||
fn vector_slh_dsa_shake_128f() {
|
||||
use fips205::slh_dsa_shake_128f::KG;
|
||||
let m = decode("D81C4D8D734FCBFBEADE3D3F8A039FAA2A2C9957E835AD55B22E75BF57BB556AC8").unwrap();
|
||||
|
|
@ -85,6 +87,7 @@ fn vector_slh_dsa_shake_128f() {
|
|||
|
||||
|
||||
#[test]
|
||||
#[allow(deprecated)]
|
||||
fn vector_slh_dsa_shake_192s() {
|
||||
use fips205::slh_dsa_shake_192s::KG;
|
||||
let m = decode("D81C4D8D734FCBFBEADE3D3F8A039FAA2A2C9957E835AD55B22E75BF57BB556AC8").unwrap();
|
||||
|
|
@ -108,6 +111,7 @@ fn vector_slh_dsa_shake_192s() {
|
|||
|
||||
|
||||
#[test]
|
||||
#[allow(deprecated)]
|
||||
fn vector_slh_dsa_shake_192f() {
|
||||
use fips205::slh_dsa_shake_192f::KG;
|
||||
let m = decode("D81C4D8D734FCBFBEADE3D3F8A039FAA2A2C9957E835AD55B22E75BF57BB556AC8").unwrap();
|
||||
|
|
@ -131,6 +135,7 @@ fn vector_slh_dsa_shake_192f() {
|
|||
|
||||
|
||||
#[test]
|
||||
#[allow(deprecated)]
|
||||
fn vector_slh_dsa_shake_256s() {
|
||||
use fips205::slh_dsa_shake_256s::KG;
|
||||
let m = decode("D81C4D8D734FCBFBEADE3D3F8A039FAA2A2C9957E835AD55B22E75BF57BB556AC8").unwrap();
|
||||
|
|
@ -154,6 +159,7 @@ fn vector_slh_dsa_shake_256s() {
|
|||
|
||||
|
||||
#[test]
|
||||
#[allow(deprecated)]
|
||||
fn vector_slh_dsa_shake_256f() {
|
||||
use fips205::slh_dsa_shake_256f::KG;
|
||||
let m = decode("D81C4D8D734FCBFBEADE3D3F8A039FAA2A2C9957E835AD55B22E75BF57BB556AC8").unwrap();
|
||||
|
|
@ -177,6 +183,7 @@ fn vector_slh_dsa_shake_256f() {
|
|||
|
||||
|
||||
#[test]
|
||||
#[allow(deprecated)]
|
||||
fn vector_slh_dsa_sha2_128s() {
|
||||
use fips205::slh_dsa_sha2_128s::KG;
|
||||
let m = decode("D81C4D8D734FCBFBEADE3D3F8A039FAA2A2C9957E835AD55B22E75BF57BB556AC8").unwrap();
|
||||
|
|
@ -200,6 +207,7 @@ fn vector_slh_dsa_sha2_128s() {
|
|||
|
||||
|
||||
#[test]
|
||||
#[allow(deprecated)]
|
||||
fn vector_slh_dsa_sha2_128f() {
|
||||
use fips205::slh_dsa_sha2_128f::KG;
|
||||
let m = decode("D81C4D8D734FCBFBEADE3D3F8A039FAA2A2C9957E835AD55B22E75BF57BB556AC8").unwrap();
|
||||
|
|
@ -223,6 +231,7 @@ fn vector_slh_dsa_sha2_128f() {
|
|||
|
||||
|
||||
#[test]
|
||||
#[allow(deprecated)]
|
||||
fn vector_slh_dsa_sha2_192s() {
|
||||
use fips205::slh_dsa_sha2_192s::KG;
|
||||
let m = decode("D81C4D8D734FCBFBEADE3D3F8A039FAA2A2C9957E835AD55B22E75BF57BB556AC8").unwrap();
|
||||
|
|
@ -246,6 +255,7 @@ fn vector_slh_dsa_sha2_192s() {
|
|||
|
||||
|
||||
#[test]
|
||||
#[allow(deprecated)]
|
||||
fn vector_slh_dsa_sha2_192f() {
|
||||
use fips205::slh_dsa_sha2_192f::KG;
|
||||
let m = decode("D81C4D8D734FCBFBEADE3D3F8A039FAA2A2C9957E835AD55B22E75BF57BB556AC8").unwrap();
|
||||
|
|
@ -269,6 +279,7 @@ fn vector_slh_dsa_sha2_192f() {
|
|||
|
||||
|
||||
#[test]
|
||||
#[allow(deprecated)]
|
||||
fn vector_slh_dsa_sha2_256s() {
|
||||
use fips205::slh_dsa_sha2_256s::KG;
|
||||
let m = decode("D81C4D8D734FCBFBEADE3D3F8A039FAA2A2C9957E835AD55B22E75BF57BB556AC8").unwrap();
|
||||
|
|
@ -292,6 +303,7 @@ fn vector_slh_dsa_sha2_256s() {
|
|||
|
||||
|
||||
#[test]
|
||||
#[allow(deprecated)]
|
||||
fn vector_slh_dsa_sha2_256f() {
|
||||
use fips205::slh_dsa_sha2_256f::KG;
|
||||
let m = decode("D81C4D8D734FCBFBEADE3D3F8A039FAA2A2C9957E835AD55B22E75BF57BB556AC8").unwrap();
|
||||
|
|
|
|||
Loading…
Reference in a new issue