Skip to content

Commit

Permalink
s/XMSS/Xmss/g
Browse files Browse the repository at this point in the history
  • Loading branch information
tjade273 committed Apr 10, 2024
1 parent 9adb068 commit a5f69ea
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 43 deletions.
14 changes: 7 additions & 7 deletions slh-dsa/src/hashes/sha2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use core::fmt::Debug;
use crate::hashes::HashSuite;
use crate::{
address::Address, fors::ForsParams, hypertree::HypertreeParams, wots::WotsParams,
xmss::XMSSParams, ParameterSet,
xmss::XmssParams, ParameterSet,
};
use crate::{PkSeed, SkPrf, SkSeed};
use digest::{Digest, Mac};
Expand Down Expand Up @@ -151,7 +151,7 @@ impl WotsParams for Sha2_128s {
type WotsMsgLen = U<32>;
type WotsSigLen = U<35>;
}
impl XMSSParams for Sha2_128s {
impl XmssParams for Sha2_128s {
type HPrime = U<9>;
}
impl HypertreeParams for Sha2_128s {
Expand All @@ -173,7 +173,7 @@ impl WotsParams for Sha2_128f {
type WotsMsgLen = U<32>;
type WotsSigLen = U<35>;
}
impl XMSSParams for Sha2_128f {
impl XmssParams for Sha2_128f {
type HPrime = U<3>;
}
impl HypertreeParams for Sha2_128f {
Expand Down Expand Up @@ -311,7 +311,7 @@ impl WotsParams for Sha2_192s {
type WotsMsgLen = U<{ 24 * 2 }>;
type WotsSigLen = U<{ 24 * 2 + 3 }>;
}
impl XMSSParams for Sha2_192s {
impl XmssParams for Sha2_192s {
type HPrime = U<9>;
}
impl HypertreeParams for Sha2_192s {
Expand All @@ -333,7 +333,7 @@ impl WotsParams for Sha2_192f {
type WotsMsgLen = U<{ 24 * 2 }>;
type WotsSigLen = U<{ 24 * 2 + 3 }>;
}
impl XMSSParams for Sha2_192f {
impl XmssParams for Sha2_192f {
type HPrime = U<3>;
}
impl HypertreeParams for Sha2_192f {
Expand All @@ -355,7 +355,7 @@ impl WotsParams for Sha2_256s {
type WotsMsgLen = U<{ 32 * 2 }>;
type WotsSigLen = U<{ 32 * 2 + 3 }>;
}
impl XMSSParams for Sha2_256s {
impl XmssParams for Sha2_256s {
type HPrime = U<8>;
}
impl HypertreeParams for Sha2_256s {
Expand All @@ -377,7 +377,7 @@ impl WotsParams for Sha2_256f {
type WotsMsgLen = U<{ 32 * 2 }>;
type WotsSigLen = U<{ 32 * 2 + 3 }>;
}
impl XMSSParams for Sha2_256f {
impl XmssParams for Sha2_256f {
type HPrime = U<4>;
}
impl HypertreeParams for Sha2_256f {
Expand Down
14 changes: 7 additions & 7 deletions slh-dsa/src/hashes/shake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::fors::ForsParams;
use crate::hashes::HashSuite;
use crate::hypertree::HypertreeParams;
use crate::wots::WotsParams;
use crate::xmss::XMSSParams;
use crate::xmss::XmssParams;
use crate::{ParameterSet, PkSeed, SkPrf, SkSeed};
use digest::{ExtendableOutput, Update};
use hybrid_array::typenum::consts::{U16, U30, U32};
Expand Down Expand Up @@ -130,7 +130,7 @@ impl WotsParams for Shake128s {
type WotsMsgLen = U<32>;
type WotsSigLen = U<35>;
}
impl XMSSParams for Shake128s {
impl XmssParams for Shake128s {
type HPrime = U<9>;
}
impl HypertreeParams for Shake128s {
Expand All @@ -152,7 +152,7 @@ impl WotsParams for Shake128f {
type WotsMsgLen = U<32>;
type WotsSigLen = U<35>;
}
impl XMSSParams for Shake128f {
impl XmssParams for Shake128f {
type HPrime = U<3>;
}
impl HypertreeParams for Shake128f {
Expand All @@ -174,7 +174,7 @@ impl WotsParams for Shake192s {
type WotsMsgLen = U<{ 24 * 2 }>;
type WotsSigLen = U<{ 24 * 2 + 3 }>;
}
impl XMSSParams for Shake192s {
impl XmssParams for Shake192s {
type HPrime = U<9>;
}
impl HypertreeParams for Shake192s {
Expand All @@ -196,7 +196,7 @@ impl WotsParams for Shake192f {
type WotsMsgLen = U<{ 24 * 2 }>;
type WotsSigLen = U<{ 24 * 2 + 3 }>;
}
impl XMSSParams for Shake192f {
impl XmssParams for Shake192f {
type HPrime = U<3>;
}
impl HypertreeParams for Shake192f {
Expand All @@ -218,7 +218,7 @@ impl WotsParams for Shake256s {
type WotsMsgLen = U<{ 32 * 2 }>;
type WotsSigLen = U<{ 32 * 2 + 3 }>;
}
impl XMSSParams for Shake256s {
impl XmssParams for Shake256s {
type HPrime = U<8>;
}
impl HypertreeParams for Shake256s {
Expand All @@ -240,7 +240,7 @@ impl WotsParams for Shake256f {
type WotsMsgLen = U<{ 32 * 2 }>;
type WotsSigLen = U<{ 32 * 2 + 3 }>;
}
impl XMSSParams for Shake256f {
impl XmssParams for Shake256f {
type HPrime = U<4>;
}
impl HypertreeParams for Shake256f {
Expand Down
14 changes: 7 additions & 7 deletions slh-dsa/src/hypertree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ use typenum::Unsigned;

use crate::{
address::WotsHash,
xmss::{XMSSParams, XMSSSig},
xmss::{XmssParams, XmssSig},
};

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct HypertreeSig<P: HypertreeParams>(Array<XMSSSig<P>, P::D>);
pub struct HypertreeSig<P: HypertreeParams>(Array<XmssSig<P>, P::D>);

impl<P: HypertreeParams> HypertreeSig<P> {
pub const SIZE: usize = XMSSSig::<P>::SIZE * P::D::USIZE;
pub const SIZE: usize = XmssSig::<P>::SIZE * P::D::USIZE;

pub fn write_to(&self, buf: &mut [u8]) {
debug_assert!(
Expand All @@ -22,7 +22,7 @@ impl<P: HypertreeParams> HypertreeSig<P> {
Self::SIZE
);

buf.chunks_exact_mut(XMSSSig::<P>::SIZE)
buf.chunks_exact_mut(XmssSig::<P>::SIZE)
.zip(self.0.iter())
.for_each(|(buf, sig)| sig.write_to(buf));
}
Expand All @@ -43,14 +43,14 @@ impl<P: HypertreeParams> TryFrom<&[u8]> for HypertreeSig<P> {
return Err(());
}
let sig = value
.chunks(XMSSSig::<P>::SIZE)
.map(|c| XMSSSig::try_from(c).unwrap())
.chunks(XmssSig::<P>::SIZE)
.map(|c| XmssSig::try_from(c).unwrap())
.collect();
Ok(HypertreeSig(sig))
}
}

pub trait HypertreeParams: XMSSParams + Sized {
pub trait HypertreeParams: XmssParams + Sized {
type D: ArraySize + Debug + Eq;
type H: ArraySize; // HPrime * D

Expand Down
2 changes: 1 addition & 1 deletion slh-dsa/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub fn base_2b<OutLen: ArraySize, B: Unsigned>(x: &[u8]) -> Array<u16, OutLen> {
})
}

/// Separates the digest into the FORS message, the XMSS tree index, and the XMSS leaf index.
/// Separates the digest into the FORS message, the Xmss tree index, and the Xmss leaf index.
pub fn split_digest<P: ForsParams>(digest: &Array<u8, P::M>) -> (&Array<u8, P::MD>, u64, u32) {
let m = Array::from_slice(&digest[..P::MD::USIZE]);
let idx_tree_size = (P::H::USIZE - P::HPrime::USIZE).div_ceil(8);
Expand Down
42 changes: 21 additions & 21 deletions slh-dsa/src/xmss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ use crate::{PkSeed, SkSeed};
use core::fmt::Debug;

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct XMSSSig<P: XMSSParams> {
pub struct XmssSig<P: XmssParams> {
pub(crate) sig: WotsSig<P>,
pub(crate) auth: Array<Array<u8, P::N>, P::HPrime>,
}

impl<P: XMSSParams> XMSSSig<P> {
impl<P: XmssParams> XmssSig<P> {
pub const SIZE: usize = WotsSig::<P>::SIZE + P::HPrime::USIZE * P::N::USIZE;

pub fn write_to(&self, buf: &mut [u8]) {
debug_assert!(buf.len() == Self::SIZE, "XMSS serialize length mismatch");
debug_assert!(buf.len() == Self::SIZE, "Xmss serialize length mismatch");

let (wots, auth) = buf.split_at_mut(WotsSig::<P>::SIZE);
self.sig.write_to(wots);
Expand All @@ -34,7 +34,7 @@ impl<P: XMSSParams> XMSSSig<P> {
}
}

impl<P: XMSSParams> TryFrom<&[u8]> for XMSSSig<P> {
impl<P: XmssParams> TryFrom<&[u8]> for XmssSig<P> {
// TODO: Real error
type Error = ();

Expand All @@ -50,11 +50,11 @@ impl<P: XMSSParams> TryFrom<&[u8]> for XMSSSig<P> {
..WotsSig::<P>::SIZE + (i + 1) * P::N::USIZE],
);
}
Ok(XMSSSig { sig, auth })
Ok(XmssSig { sig, auth })
}
}

pub(crate) trait XMSSParams: WotsParams + Sized {
pub(crate) trait XmssParams: WotsParams + Sized {
type HPrime: ArraySize + Debug + Eq;

fn xmss_node(
Expand Down Expand Up @@ -86,7 +86,7 @@ pub(crate) trait XMSSParams: WotsParams + Sized {
pk_seed: &PkSeed<Self::N>,
idx: u32,
adrs: &address::WotsHash,
) -> XMSSSig<Self> {
) -> XmssSig<Self> {
let mut adrs = adrs.clone();
adrs.key_pair_adrs.set(idx);

Expand All @@ -100,12 +100,12 @@ pub(crate) trait XMSSParams: WotsParams + Sized {
auth[j as usize] = node;
}

XMSSSig { sig, auth }
XmssSig { sig, auth }
}

fn xmss_pk_from_sig(
idx: u32,
sig: &XMSSSig<Self>,
sig: &XmssSig<Self>,
m: &Array<u8, Self::N>,
pk_seed: &PkSeed<Self::N>,
adrs: &address::WotsHash,
Expand Down Expand Up @@ -148,7 +148,7 @@ mod tests {

use typenum::Unsigned;

use crate::{address::WotsHash, hashes::Shake128f, xmss::XMSSParams};
use crate::{address::WotsHash, hashes::Shake128f, xmss::XmssParams};

#[test]
fn test_xmss_node_shake128f_kat() {
Expand All @@ -158,7 +158,7 @@ mod tests {
let node = Shake128f::xmss_node(
&sk_seed,
0,
<Shake128f as XMSSParams>::HPrime::U32,
<Shake128f as XmssParams>::HPrime::U32,
&pk_seed,
&adrs,
);
Expand Down Expand Up @@ -204,7 +204,7 @@ mod tests {
assert_eq!(sig.to_vec(), expected);
}

fn test_sign_verify<XMSS: XMSSParams>() {
fn test_sign_verify<Xmss: XmssParams>() {
// Generate random sk_seed, pk_seed, message, index, address
let mut rng = thread_rng();

Expand All @@ -215,21 +215,21 @@ mod tests {
let mut msg = Array::<u8, _>::default();
rng.fill_bytes(msg.as_mut_slice());

let idx = rng.gen_range(0..(1 << XMSS::HPrime::U32));
let idx = rng.gen_range(0..(1 << Xmss::HPrime::U32));

let adrs = WotsHash::default();

let pk = XMSS::xmss_node(&sk_seed, 0, XMSS::HPrime::U32, &pk_seed, &adrs);
let pk = Xmss::xmss_node(&sk_seed, 0, Xmss::HPrime::U32, &pk_seed, &adrs);

let sig = XMSS::xmss_sign(&msg, &sk_seed, &pk_seed, idx, &adrs);
let pk_recovered = XMSS::xmss_pk_from_sig(idx, &sig, &msg, &pk_seed, &adrs);
let sig = Xmss::xmss_sign(&msg, &sk_seed, &pk_seed, idx, &adrs);
let pk_recovered = Xmss::xmss_pk_from_sig(idx, &sig, &msg, &pk_seed, &adrs);

assert_eq!(pk, pk_recovered);
}

test_parameter_sets!(test_sign_verify);

fn test_sign_verify_fail<XMSS: XMSSParams>() {
fn test_sign_verify_fail<Xmss: XmssParams>() {
// Generate random sk_seed, pk_seed, message, index, address
let mut rng = thread_rng();

Expand All @@ -240,18 +240,18 @@ mod tests {
let mut msg = Array::<u8, _>::default();
rng.fill_bytes(msg.as_mut_slice());

let idx = rng.gen_range(0..(1 << XMSS::HPrime::U32));
let idx = rng.gen_range(0..(1 << Xmss::HPrime::U32));

let adrs = WotsHash::default();

let pk = XMSS::xmss_node(&sk_seed, 0, XMSS::HPrime::U32, &pk_seed, &adrs);
let pk = Xmss::xmss_node(&sk_seed, 0, Xmss::HPrime::U32, &pk_seed, &adrs);

let sig = XMSS::xmss_sign(&msg, &sk_seed, &pk_seed, idx, &adrs);
let sig = Xmss::xmss_sign(&msg, &sk_seed, &pk_seed, idx, &adrs);

// Tweak message
msg[0] ^= 0xff;

let pk_recovered = XMSS::xmss_pk_from_sig(idx, &sig, &msg, &pk_seed, &adrs);
let pk_recovered = Xmss::xmss_pk_from_sig(idx, &sig, &msg, &pk_seed, &adrs);

assert_ne!(pk, pk_recovered);
}
Expand Down

0 comments on commit a5f69ea

Please sign in to comment.