Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 7 additions & 7 deletions src/signature/generalized_xmss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ 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>,
pub path: HashTreeOpening<TH>,
pub rho: IE::Randomness,
pub hashes: Vec<TH::Domain>,
}

impl<IE: IncomparableEncoding, TH: TweakableHash> Encode for GeneralizedXMSSSignature<IE, TH> {
Expand Down Expand Up @@ -174,10 +174,10 @@ 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,
pub root: TH::Domain,
pub parameter: TH::Parameter,
}

/// Secret key for GeneralizedXMSSSignatureScheme
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
6 changes: 4 additions & 2 deletions src/symmetric/tweak_hash.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt::Debug;

use rand::Rng;

use crate::serialization::Serializable;
Expand All @@ -20,10 +22,10 @@
type Parameter: Copy + Send + Sync + Serializable;

/// Tweak type for domain separation
type Tweak;
type Tweak: Debug;

/// Domain element type (defines output and input types to the hash)
type Domain: Copy + PartialEq + Send + Sync + Serializable;
type Domain: Copy + PartialEq + Send + Sync + Serializable + Debug;

/// Generates a random public parameter.
fn rand_parameter<R: Rng>(rng: &mut R) -> Self::Parameter;
Expand Down Expand Up @@ -68,7 +70,7 @@
fn internal_consistency_check();
}

/// Function implementing hash chains, implemented over a tweakable hash function

Check failure on line 73 in src/symmetric/tweak_hash.rs

View workflow job for this annotation

GitHub Actions / Clippy

first doc comment paragraph is too long
/// The chain is specific to an epoch `epoch`, and an index `chain_index`. All
/// evaluations of the tweakable hash function use the given parameter `parameter`
/// and tweaks determined by `epoch`, `chain_index`, and their position in the chain.
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
2 changes: 1 addition & 1 deletion src/symmetric/tweak_hash_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@
}

/// 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,7 +562,7 @@

/// Function to compute a Merkle authentication path from a tree that is
/// splitted into top tree and bottom trees.
pub fn combined_path<TH: TweakableHash>(

Check failure on line 565 in src/symmetric/tweak_hash_tree.rs

View workflow job for this annotation

GitHub Actions / Clippy

this function could have a `#[must_use]` attribute
top_tree: &HashSubTree<TH>,
bottom_tree: &HashSubTree<TH>,
position: u32,
Expand Down
Loading