Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/inc_encoding/target_sum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub enum TargetSumError {
/// const MAX_CHUNK_VALUE: usize = MH::BASE - 1
/// const EXPECTED_SUM: usize = MH::DIMENSION * MAX_CHUNK_VALUE / 2
/// ```
#[derive(Clone)]
pub struct TargetSumEncoding<MH: MessageHash, const TARGET_SUM: usize> {
_marker_mh: std::marker::PhantomData<MH>,
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub(crate) mod inc_encoding;
pub mod serialization;
pub mod signature;
pub(crate) mod simd_utils;
pub(crate) mod symmetric;
pub mod symmetric;

// Cached Poseidon2 permutations.
//
Expand Down
28 changes: 26 additions & 2 deletions src/signature/generalized_xmss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,28 @@ pub struct GeneralizedXMSSSignatureScheme<

/// Signature for GeneralizedXMSSSignatureScheme
/// It contains a Merkle authentication path, encoding randomness, and a list of hashes
#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Clone)]
#[serde(bound = "")]
pub struct GeneralizedXMSSSignature<IE: IncomparableEncoding, TH: TweakableHash> {
path: HashTreeOpening<TH>,
rho: IE::Randomness,
hashes: Vec<TH::Domain>,
}

impl<IE: IncomparableEncoding, TH: TweakableHash> GeneralizedXMSSSignature<IE, TH> {
pub const fn path(&self) -> &HashTreeOpening<TH> {
&self.path
}

pub const fn rho(&self) -> &IE::Randomness {
&self.rho
}

pub const fn hashes(&self) -> &Vec<TH::Domain> {
&self.hashes
}
}

impl<IE: IncomparableEncoding, TH: TweakableHash> Encode for GeneralizedXMSSSignature<IE, TH> {
fn is_ssz_fixed_len() -> bool {
false
Expand Down Expand Up @@ -174,12 +188,22 @@ impl<IE: IncomparableEncoding, TH: TweakableHash> Decode for GeneralizedXMSSSign

/// Public key for GeneralizedXMSSSignatureScheme
/// It contains a Merkle root and a parameter for the tweakable hash
#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Clone)]
pub struct GeneralizedXMSSPublicKey<TH: TweakableHash> {
root: TH::Domain,
parameter: TH::Parameter,
}

impl<TH: TweakableHash> GeneralizedXMSSPublicKey<TH> {
pub const fn root(&self) -> &TH::Domain {
&self.root
}

pub const fn parameter(&self) -> &TH::Parameter {
&self.parameter
}
}

/// Secret key for GeneralizedXMSSSignatureScheme
/// It contains a PRF key and a Merkle tree.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ pub mod lifetime_2_to_the_32 {

use crate::{
inc_encoding::target_sum::TargetSumEncoding,
signature::generalized_xmss::GeneralizedXMSSSignatureScheme,
signature::generalized_xmss::{
GeneralizedXMSSPublicKey, GeneralizedXMSSSignature, GeneralizedXMSSSignatureScheme,
},
symmetric::{
message_hash::top_level_poseidon::TopLevelPoseidonMessageHash,
prf::shake_to_field::ShakePRFtoF, tweak_hash::poseidon::PoseidonTweakHash,
Expand All @@ -101,18 +103,18 @@ pub mod lifetime_2_to_the_32 {
const TARGET_SUM: usize = 375;

const PARAMETER_LEN: usize = 5;
const TWEAK_LEN_FE: usize = 2;
pub const TWEAK_LEN_FE: usize = 2;
const MSG_LEN_FE: usize = 9;
const RAND_LEN_FE: usize = 7;
const HASH_LEN_FE: usize = 8;
pub const RAND_LEN_FE: usize = 7;
pub const HASH_LEN_FE: usize = 8;

const CAPACITY: usize = 9;

const POS_OUTPUT_LEN_PER_INV_FE: usize = 15;
const POS_INVOCATIONS: usize = 1;
const POS_OUTPUT_LEN_FE: usize = POS_OUTPUT_LEN_PER_INV_FE * POS_INVOCATIONS;

type MH = TopLevelPoseidonMessageHash<
pub type MH = TopLevelPoseidonMessageHash<
POS_OUTPUT_LEN_PER_INV_FE,
POS_INVOCATIONS,
POS_OUTPUT_LEN_FE,
Expand All @@ -130,6 +132,8 @@ pub mod lifetime_2_to_the_32 {

pub type SIGTopLevelTargetSumLifetime32Dim64Base8 =
GeneralizedXMSSSignatureScheme<PRF, IE, TH, LOG_LIFETIME>;
pub type PubKeyTopLevelTargetSumLifetime32Dim64Base8 = GeneralizedXMSSPublicKey<TH>;
pub type SigTopLevelTargetSumLifetime32Dim64Base8 = GeneralizedXMSSSignature<IE, TH>;

#[cfg(test)]
mod test {
Expand Down
1 change: 1 addition & 0 deletions src/symmetric/message_hash/top_level_poseidon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ fn map_into_hypercube_part<
/// - `POS_INVOCATIONS` must be at most 2^8.
/// - `POS_OUTPUT_LEN_FE` must be equal to `POS_INVOCATIONS * POS_OUTPUT_LEN_PER_INV_FE`.
/// - `BASE` must be at most 2^8.
#[derive(Clone)]
pub struct TopLevelPoseidonMessageHash<
const POS_OUTPUT_LEN_PER_INV_FE: usize,
const POS_INVOCATIONS: usize,
Expand Down
1 change: 1 addition & 0 deletions src/symmetric/tweak_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ pub trait TweakableHash {
/// We start walking the chain at position `start_pos_in_chain` with `start`,
/// and then walk the chain for `steps` many steps. For example, walking two steps
/// with `start = A` would mean we walk A -> B -> C, and then return C.
#[allow(clippy::too_long_first_doc_paragraph)]
pub fn chain<TH: TweakableHash>(
parameter: &TH::Parameter,
epoch: u32,
Expand Down
4 changes: 3 additions & 1 deletion src/symmetric/tweak_hash/poseidon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const CHAIN_COMPRESSION_WIDTH: usize = 16;
const MERGE_COMPRESSION_WIDTH: usize = 24;

/// Enum to implement tweaks.
#[derive(Debug)]
pub enum PoseidonTweak {
TreeTweak {
level: u8,
Expand All @@ -36,7 +37,7 @@ pub enum PoseidonTweak {
}

impl PoseidonTweak {
fn to_field_elements<const TWEAK_LEN: usize>(&self) -> [F; TWEAK_LEN] {
pub fn to_field_elements<const TWEAK_LEN: usize>(&self) -> [F; TWEAK_LEN] {
// We first represent the entire tweak as one big integer
let mut acc = match self {
Self::TreeTweak {
Expand Down Expand Up @@ -248,6 +249,7 @@ where
///
/// Note: HASH_LEN, TWEAK_LEN, CAPACITY, and PARAMETER_LEN must
/// be given in the unit "number of field elements".
#[derive(Clone)]
pub struct PoseidonTweakHash<
const PARAMETER_LEN: usize,
const HASH_LEN: usize,
Expand Down
3 changes: 2 additions & 1 deletion src/symmetric/tweak_hash_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ impl<TH: TweakableHash> Decode for HashSubTree<TH> {
}

/// Opening in a hash-tree: a co-path, without the leaf
#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Clone)]
#[serde(bound = "")]
pub struct HashTreeOpening<TH: TweakableHash> {
/// The co-path needed to verify
Expand Down Expand Up @@ -562,6 +562,7 @@ where

/// Function to compute a Merkle authentication path from a tree that is
/// splitted into top tree and bottom trees.
#[must_use]
pub fn combined_path<TH: TweakableHash>(
top_tree: &HashSubTree<TH>,
bottom_tree: &HashSubTree<TH>,
Expand Down