mirror of
https://github.com/saymrwulf/fips205-source.git
synced 2026-09-04 20:03:45 +00:00
hhh
This commit is contained in:
parent
429337a4aa
commit
946df93b0b
3 changed files with 74 additions and 24 deletions
16
src/algs.rs
16
src/algs.rs
|
|
@ -125,8 +125,8 @@ pub(crate) fn base_2b(x: &[u8], b: u32, out_len: usize, baseb: &mut [u64]) {
|
||||||
/// Input: Input string `X`, start index `i`, number of steps `s`, public seed `PK.seed`, address `ADRS`. <br>
|
/// Input: Input string `X`, start index `i`, number of steps `s`, public seed `PK.seed`, address `ADRS`. <br>
|
||||||
/// Output: Value of `F` iterated `s` times on `X`.
|
/// Output: Value of `F` iterated `s` times on `X`.
|
||||||
pub(crate) fn chain<K: ArrayLength, LEN: ArrayLength, M: ArrayLength, N: ArrayLength>(
|
pub(crate) fn chain<K: ArrayLength, LEN: ArrayLength, M: ArrayLength, N: ArrayLength>(
|
||||||
hashers: &Hashers<K, LEN, M, N>, cap_x: GenericArray<u8, N>, i: usize, s: usize, pk_seed: &[u8],
|
hashers: &Hashers<K, LEN, M, N>, cap_x: GenericArray<u8, N>, i: usize, s: usize,
|
||||||
adrs: &Adrs,
|
pk_seed: &[u8], adrs: &Adrs,
|
||||||
) -> Option<GenericArray<u8, N>> {
|
) -> Option<GenericArray<u8, N>> {
|
||||||
let mut adrs = adrs.clone();
|
let mut adrs = adrs.clone();
|
||||||
|
|
||||||
|
|
@ -427,7 +427,8 @@ pub(crate) fn xmss_node<
|
||||||
} else {
|
} else {
|
||||||
//
|
//
|
||||||
// 9: lnode ← xmss_node(SK.seed, 2 * i, z − 1, PK.seed, ADRS)
|
// 9: lnode ← xmss_node(SK.seed, 2 * i, z − 1, PK.seed, ADRS)
|
||||||
let lnode = xmss_node::<H, HP, K, LEN, M, N>(hashers, sk_seed, 2 * i, z - 1, pk_seed, &adrs)?;
|
let lnode =
|
||||||
|
xmss_node::<H, HP, K, LEN, M, N>(hashers, sk_seed, 2 * i, z - 1, pk_seed, &adrs)?;
|
||||||
|
|
||||||
// 10: rnode ← xmss_node(SK.seed, 2 * i + 1, z − 1, PK.seed, ADRS)
|
// 10: rnode ← xmss_node(SK.seed, 2 * i + 1, z − 1, PK.seed, ADRS)
|
||||||
let rnode =
|
let rnode =
|
||||||
|
|
@ -467,7 +468,8 @@ pub(crate) fn xmss_sign<
|
||||||
M: ArrayLength,
|
M: ArrayLength,
|
||||||
N: ArrayLength,
|
N: ArrayLength,
|
||||||
>(
|
>(
|
||||||
hashers: &Hashers<K, LEN, M, N>, m: &[u8], sk_seed: &[u8], idx: u32, pk_seed: &[u8], adrs: &Adrs,
|
hashers: &Hashers<K, LEN, M, N>, m: &[u8], sk_seed: &[u8], idx: u32, pk_seed: &[u8],
|
||||||
|
adrs: &Adrs,
|
||||||
) -> Result<XmssSig<HP, LEN, N>, &'static str> {
|
) -> Result<XmssSig<HP, LEN, N>, &'static str> {
|
||||||
let mut adrs = adrs.clone();
|
let mut adrs = adrs.clone();
|
||||||
let mut sig_xmss = XmssSig::default();
|
let mut sig_xmss = XmssSig::default();
|
||||||
|
|
@ -615,7 +617,8 @@ pub(crate) fn ht_sign<
|
||||||
adrs.set_tree_address(idx_tree);
|
adrs.set_tree_address(idx_tree);
|
||||||
|
|
||||||
// 4: SIG_tmp ← xmss_sign(M, SK.seed, idxleaf, PK.seed, ADRS)
|
// 4: SIG_tmp ← xmss_sign(M, SK.seed, idxleaf, PK.seed, ADRS)
|
||||||
let mut sig_tmp = xmss_sign::<H, HP, K, LEN, M, N>(hashers, m, sk_seed, idx_leaf, pk_seed, &adrs)?;
|
let mut sig_tmp =
|
||||||
|
xmss_sign::<H, HP, K, LEN, M, N>(hashers, m, sk_seed, idx_leaf, pk_seed, &adrs)?;
|
||||||
|
|
||||||
// 5: SIG_HT ← SIG_tmp
|
// 5: SIG_HT ← SIG_tmp
|
||||||
let mut sig_ht = HtSig::default();
|
let mut sig_ht = HtSig::default();
|
||||||
|
|
@ -642,7 +645,8 @@ pub(crate) fn ht_sign<
|
||||||
adrs.set_tree_address(idx_tree);
|
adrs.set_tree_address(idx_tree);
|
||||||
|
|
||||||
// 12: SIG_tmp ← xmss_sign(root, SK.seed, idx_leaf, PK.seed, ADRS)
|
// 12: SIG_tmp ← xmss_sign(root, SK.seed, idx_leaf, PK.seed, ADRS)
|
||||||
sig_tmp = xmss_sign::<H, HP, K, LEN, M, N>(hashers, &root, sk_seed, idx_leaf, pk_seed, &adrs)?;
|
sig_tmp =
|
||||||
|
xmss_sign::<H, HP, K, LEN, M, N>(hashers, &root, sk_seed, idx_leaf, pk_seed, &adrs)?;
|
||||||
|
|
||||||
// 13: SIG_HT ← SIG_HT ∥ SIG_tmp
|
// 13: SIG_HT ← SIG_HT ∥ SIG_tmp
|
||||||
sig_ht.xmss_sigs[j as usize] = sig_tmp.clone();
|
sig_ht.xmss_sigs[j as usize] = sig_tmp.clone();
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ pub(crate) mod shake {
|
||||||
use sha3::Shake256;
|
use sha3::Shake256;
|
||||||
|
|
||||||
|
|
||||||
pub(crate) fn shake256_a(input: &[&[u8]], out: &mut [u8]) {
|
fn shake256_a(input: &[&[u8]], out: &mut [u8]) {
|
||||||
let mut hasher = Shake256::default();
|
let mut hasher = Shake256::default();
|
||||||
input.iter().for_each(|item| hasher.update(item));
|
input.iter().for_each(|item| hasher.update(item));
|
||||||
let mut reader = hasher.finalize_xof();
|
let mut reader = hasher.finalize_xof();
|
||||||
|
|
@ -104,5 +104,53 @@ pub(crate) mod shake {
|
||||||
reader.read(&mut result);
|
reader.read(&mut result);
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) mod sha2_cat1 {
|
||||||
|
use crate::types::Adrs;
|
||||||
|
use generic_array::{ArrayLength, GenericArray};
|
||||||
|
|
||||||
|
|
||||||
|
pub(crate) fn h_msg<M: ArrayLength>(
|
||||||
|
_r: &[u8], _pk_seed: &[u8], _pk_root: &[u8], _m: &[u8],
|
||||||
|
) -> GenericArray<u8, M> {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn prf<N: ArrayLength>(
|
||||||
|
_pk_seed: &[u8], _sk_seed: &[u8], _adrs: &Adrs,
|
||||||
|
) -> GenericArray<u8, N> {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn prf_msg<N: ArrayLength>(
|
||||||
|
_sk_prf: &[u8], _opt_rand: &[u8], _m: &[u8],
|
||||||
|
) -> GenericArray<u8, N> {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn f<N: ArrayLength>(_pk_seed: &[u8], _adrs: &Adrs, _m1: &[u8]) -> GenericArray<u8, N> {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn h<N: ArrayLength>(
|
||||||
|
_pk_seed: &[u8], _adrs: &Adrs, _m1: &[u8], _m2: &[u8],
|
||||||
|
) -> GenericArray<u8, N> {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Until a more elegant way is found to covert ml into list of bytes
|
||||||
|
pub(crate) fn t_l<LEN: ArrayLength, N: ArrayLength>(
|
||||||
|
_pk_seed: &[u8], _adrs: &Adrs, _ml: &GenericArray<GenericArray<u8, N>, LEN>,
|
||||||
|
) -> GenericArray<u8, N> {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Squash K and LEN versions
|
||||||
|
// Until a more elegant way is found to covert ml into list of bytes
|
||||||
|
pub(crate) fn t_len<K: ArrayLength, N: ArrayLength>(
|
||||||
|
_pk_seed: &[u8], _adrs: &Adrs, _ml: &GenericArray<GenericArray<u8, N>, K>,
|
||||||
|
) -> GenericArray<u8, N> {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
30
src/lib.rs
30
src/lib.rs
|
|
@ -1,17 +1,16 @@
|
||||||
#![no_std]
|
#![no_std]
|
||||||
#![deny(clippy::pedantic)]
|
#![deny(clippy::pedantic)]
|
||||||
#![deny(warnings)]
|
#![deny(warnings)]
|
||||||
|
|
||||||
|
|
||||||
//#![deny(missing_docs)]
|
//#![deny(missing_docs)]
|
||||||
#[allow(dead_code)]
|
|
||||||
|
/// TKTK crate doc
|
||||||
|
/// crate doc?
|
||||||
// TODO
|
// TODO
|
||||||
// 1. General clean-up
|
// 1. General clean-up
|
||||||
// 2. revisit/clean hash functions
|
// 2. Placeholders for other hash functions
|
||||||
// 3. Doc, of course!
|
// 3. Implement all suites (with internal found-trip test function)
|
||||||
|
// 4. Separate into proper files
|
||||||
// TKTK crate doc
|
// 5. Doc, of course!
|
||||||
/// crate doc?
|
|
||||||
mod algs;
|
mod algs;
|
||||||
mod hashers;
|
mod hashers;
|
||||||
mod test;
|
mod test;
|
||||||
|
|
@ -23,7 +22,7 @@ const LGW: u32 = 4;
|
||||||
const W: u32 = 16;
|
const W: u32 = 16;
|
||||||
const LEN2: u32 = 3;
|
const LEN2: u32 = 3;
|
||||||
|
|
||||||
|
/// blah
|
||||||
macro_rules! functionality {
|
macro_rules! functionality {
|
||||||
() => {
|
() => {
|
||||||
use crate::types::{SlhDsaSig, SlhPrivateKey, SlhPublicKey};
|
use crate::types::{SlhDsaSig, SlhPrivateKey, SlhPublicKey};
|
||||||
|
|
@ -35,7 +34,7 @@ macro_rules! functionality {
|
||||||
pub fn slh_keygen_with_rng(
|
pub fn slh_keygen_with_rng(
|
||||||
rng: &mut impl CryptoRngCore,
|
rng: &mut impl CryptoRngCore,
|
||||||
) -> Result<(SlhPrivateKey<N>, SlhPublicKey<N>), &'static str> {
|
) -> Result<(SlhPrivateKey<N>, SlhPublicKey<N>), &'static str> {
|
||||||
crate::algs::slh_keygen_with_rng::<D, H, HP, K, Sum<Prod<U2, N>, U3>, M, N>(rng, &HASHERS)
|
crate::algs::slh_keygen_with_rng::<D, H, HP, K, LEN, M, N>(rng, &HASHERS)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// blah
|
/// blah
|
||||||
|
|
@ -43,7 +42,7 @@ macro_rules! functionality {
|
||||||
pub fn slh_sign_with_rng(
|
pub fn slh_sign_with_rng(
|
||||||
rng: &mut impl CryptoRngCore, m: &[u8], sk: &SlhPrivateKey<N>, randomize: bool,
|
rng: &mut impl CryptoRngCore, m: &[u8], sk: &SlhPrivateKey<N>, randomize: bool,
|
||||||
) -> Result<[u8; SIG_LEN], &'static str> {
|
) -> Result<[u8; SIG_LEN], &'static str> {
|
||||||
let sig = crate::algs::slh_sign_with_rng::<A, D, H, HP, K, Sum<Prod<U2, N>, U3>, M, N>(
|
let sig = crate::algs::slh_sign_with_rng::<A, D, H, HP, K, LEN, M, N>(
|
||||||
rng, &HASHERS, &m, &sk, randomize,
|
rng, &HASHERS, &m, &sk, randomize,
|
||||||
);
|
);
|
||||||
sig.map(|s| s.deserialize())
|
sig.map(|s| s.deserialize())
|
||||||
|
|
@ -52,10 +51,8 @@ macro_rules! functionality {
|
||||||
/// blah
|
/// blah
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn slh_verify(m: &[u8], sig_bytes: &[u8; SIG_LEN], pk: &SlhPublicKey<N>) -> bool {
|
pub fn slh_verify(m: &[u8], sig_bytes: &[u8; SIG_LEN], pk: &SlhPublicKey<N>) -> bool {
|
||||||
let sig = SlhDsaSig::<A, D, HP, K, Sum<Prod<U2, N>, U3>, N>::serialize(sig_bytes);
|
let sig = SlhDsaSig::<A, D, HP, K, LEN, N>::serialize(sig_bytes);
|
||||||
crate::algs::slh_verify::<A, D, H, HP, K, Sum<Prod<U2, N>, U3>, M, N>(
|
crate::algs::slh_verify::<A, D, H, HP, K, LEN, M, N>(&HASHERS, &m, &sig, &pk)
|
||||||
&HASHERS, &m, &sig, &pk,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
@ -100,7 +97,8 @@ pub mod slh_dsa_sha2_128s {
|
||||||
//const PK_LEN: usize = 32;
|
//const PK_LEN: usize = 32;
|
||||||
const SIG_LEN: usize = 7856;
|
const SIG_LEN: usize = 7856;
|
||||||
//const SK_LEN: usize = 0000;
|
//const SK_LEN: usize = 0000;
|
||||||
static HASHERS: Hashers<K, LEN, M, N> = Hashers::<K, LEN, M, N> { h_msg, prf, prf_msg, f, h, t_l, t_len };
|
static HASHERS: Hashers<K, LEN, M, N> =
|
||||||
|
Hashers::<K, LEN, M, N> { h_msg, prf, prf_msg, f, h, t_l, t_len };
|
||||||
|
|
||||||
functionality!();
|
functionality!();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue