Skip to content

Commit b9b2273

Browse files
committed
[frontend] Add public key hash tweak
1 parent db4c440 commit b9b2273

File tree

6 files changed

+429
-41
lines changed

6 files changed

+429
-41
lines changed

crates/frontend/src/circuits/hash_based_sig/hashing/chain.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,33 @@ pub fn build_chain_hash(
112112
message
113113
}
114114

115+
/// Computes a hash chain for Winternitz OTS signature verification.
116+
///
117+
/// # Arguments
118+
/// * `param` - Cryptographic parameter
119+
/// * `chain_index` - Index of the chain being computed
120+
/// * `start_hash` - Starting hash value
121+
/// * `start_pos` - Starting position in the chain
122+
/// * `num_hashes` - Number of hash iterations to perform
123+
pub fn hash_chain_keccak(
124+
param: &[u8],
125+
chain_index: usize,
126+
start_hash: &[u8; 32],
127+
start_pos: usize,
128+
num_hashes: usize,
129+
) -> [u8; 32] {
130+
use sha3::{Digest, Keccak256};
131+
132+
let mut current = *start_hash;
133+
for i in 0..num_hashes {
134+
let position = start_pos + i + 1;
135+
let tweaked_message =
136+
build_chain_hash(param, &current, chain_index as u64, position as u64);
137+
current = Keccak256::digest(tweaked_message).into();
138+
}
139+
current
140+
}
141+
115142
#[cfg(test)]
116143
mod tests {
117144
use binius_core::Word;

crates/frontend/src/circuits/hash_based_sig/hashing/mod.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,16 @@
22
mod base;
33
mod chain;
44
mod message;
5+
mod public_key;
56
mod tree;
67

7-
pub use chain::{CHAIN_TWEAK, FIXED_MESSAGE_OVERHEAD, build_chain_hash, circuit_chain_hash};
8+
pub use chain::{
9+
CHAIN_TWEAK, FIXED_MESSAGE_OVERHEAD, build_chain_hash, circuit_chain_hash, hash_chain_keccak,
10+
};
811
pub use message::{MESSAGE_TWEAK, build_message_hash, circuit_message_hash, hash_message};
9-
pub use tree::{TREE_MESSAGE_OVERHEAD, TREE_TWEAK, build_tree_hash, circuit_tree_hash};
12+
pub use public_key::{
13+
PUBLIC_KEY_TWEAK, build_public_key_hash, circuit_public_key_hash, hash_public_key_keccak,
14+
};
15+
pub use tree::{
16+
TREE_MESSAGE_OVERHEAD, TREE_TWEAK, build_tree_hash, circuit_tree_hash, hash_tree_node_keccak,
17+
};

0 commit comments

Comments
 (0)