Move Signature::verify under sign

This commit is contained in:
Thomas Eizinger 2021-05-11 12:31:37 +10:00
parent 07d544adde
commit 874179685a
No known key found for this signature in database
GPG Key ID: 651AC83A6C6C8B96
2 changed files with 33 additions and 32 deletions

View File

@ -89,6 +89,37 @@ pub struct Signature {
pub D: EdwardsPoint, pub D: EdwardsPoint,
} }
impl Signature {
#[cfg(test)]
#[must_use]
pub fn verify(&self, ring: [EdwardsPoint; RING_SIZE], msg: &[u8; 32]) -> bool {
let ring_concat = ring
.iter()
.flat_map(|pk| pk.compress().as_bytes().to_vec())
.collect::<Vec<u8>>();
let mut h = self.h_0;
let mus = todo!();
let adjusted_commitment_i = todo!();
for (i, s_i) in self.responses.iter().enumerate() {
let pk_i = ring[(i + 1) % RING_SIZE];
let prefix = clsag_round_hash_prefix(&ring_concat, todo!(), todo!(), msg);
let L_i = compute_L(h, mus, *s_i, pk_i, adjusted_commitment_i);
let R_i = compute_R(h, mus, pk_i, *s_i, self.I, self.D);
h = hash_to_scalar(&[
&prefix,
L_i.compress().as_bytes().as_ref(),
R_i.compress().as_bytes().as_ref(),
])
}
h == self.h_0
}
}
/// Compute the prefix for the hash common to every iteration of the ring /// Compute the prefix for the hash common to every iteration of the ring
/// signature algorithm. /// signature algorithm.
/// ///
@ -158,7 +189,7 @@ struct AggregationHashes {
} }
impl AggregationHashes { impl AggregationHashes {
pub fn new( fn new(
ring: &Ring, ring: &Ring,
commitment_ring: &Ring, commitment_ring: &Ring,
I: CompressedEdwardsY, I: CompressedEdwardsY,
@ -192,36 +223,6 @@ impl AggregationHashes {
} }
} }
impl Signature {
#[cfg(test)]
pub fn verify(&self, ring: [EdwardsPoint; RING_SIZE], msg: &[u8; 32]) -> anyhow::Result<bool> {
let ring_concat = ring
.iter()
.flat_map(|pk| pk.compress().as_bytes().to_vec())
.collect::<Vec<u8>>();
let mut h = self.h_0;
let mus = todo!();
let adjusted_commitment_i = todo!();
for (i, s_i) in self.responses.iter().enumerate() {
let pk_i = ring[(i + 1) % RING_SIZE];
let prefix = clsag_round_hash_prefix(&ring_concat, todo!(), todo!(), msg);
let L_i = compute_L(h, mus, *s_i, pk_i, adjusted_commitment_i);
let R_i = compute_R(h, mus, pk_i, *s_i, self.I, self.D);
h = hash_to_scalar(&[
&prefix,
L_i.compress().as_bytes().as_ref(),
R_i.compress().as_bytes().as_ref(),
])
}
Ok(h == self.h_0)
}
}
impl From<Signature> for monero::util::ringct::Clsag { impl From<Signature> for monero::util::ringct::Clsag {
fn from(from: Signature) -> Self { fn from(from: Signature) -> Self {
Self { Self {

View File

@ -631,6 +631,6 @@ mod tests {
let sig = alice.adaptor_sig.adapt(r_a); let sig = alice.adaptor_sig.adapt(r_a);
assert!(sig.verify(ring, msg_to_sign).unwrap()); assert!(sig.verify(ring, msg_to_sign));
} }
} }