Make Ring an implementation detail of clsag module

This commit is contained in:
Thomas Eizinger 2021-05-11 12:47:20 +10:00
parent f9cac4b6c9
commit 53916aab6b
No known key found for this signature in database
GPG Key ID: 651AC83A6C6C8B96
3 changed files with 24 additions and 30 deletions

View File

@ -17,8 +17,8 @@ pub fn sign(
signing_key: Scalar,
H_p_pk: EdwardsPoint,
alpha: Scalar,
ring: &Ring,
commitment_ring: &Ring,
ring: &[EdwardsPoint; RING_SIZE],
commitment_ring: &[EdwardsPoint; RING_SIZE],
fake_responses: [Scalar; RING_SIZE - 1],
z: Scalar,
pseudo_output_commitment: EdwardsPoint,
@ -28,6 +28,8 @@ pub fn sign(
) -> Signature {
let D = z * H_p_pk;
let D_inv_8 = D * INV_EIGHT;
let ring = Ring::new(ring);
let commitment_ring = Ring::new(commitment_ring);
let mus = AggregationHashes::new(
&ring,
@ -92,11 +94,14 @@ pub fn sign(
pub fn verify(
sig: &Signature,
msg: &[u8],
ring: &Ring,
commitment_ring: &Ring,
ring: &[EdwardsPoint; RING_SIZE],
commitment_ring: &[EdwardsPoint; RING_SIZE],
pseudo_output_commitment: EdwardsPoint,
H_p_pk: EdwardsPoint,
) -> bool {
let ring = Ring::new(ring);
let commitment_ring = Ring::new(commitment_ring);
let mus = AggregationHashes::new(
&ring,
&commitment_ring,
@ -312,8 +317,6 @@ mod tests {
x * ED25519_BASEPOINT_POINT
});
let ring = Ring::new(ring);
let mut commitment_ring = [EdwardsPoint::default(); RING_SIZE];
let real_commitment_blinding = Scalar::random(&mut OsRng);
@ -323,8 +326,6 @@ mod tests {
x * ED25519_BASEPOINT_POINT
});
let commitment_ring = Ring::new(commitment_ring);
// TODO: document
let pseudo_output_commitment = commitment_ring[0];

View File

@ -14,7 +14,6 @@ use rand::{CryptoRng, Rng};
use tiny_keccak::{Hasher, Keccak};
use clsag::{Signature, RING_SIZE};
use ring::Ring;
mod clsag;
mod ring;
@ -83,9 +82,9 @@ impl AdaptorSignature {
pub struct Alice0 {
// secret index is always 0
ring: Ring,
ring: [EdwardsPoint; RING_SIZE],
fake_responses: [Scalar; RING_SIZE - 1],
commitment_ring: Ring,
commitment_ring: [EdwardsPoint; RING_SIZE],
pseudo_output_commitment: EdwardsPoint,
msg: [u8; 32],
// encryption key
@ -113,9 +112,6 @@ impl Alice0 {
s_prime_a: Scalar,
rng: &mut (impl Rng + CryptoRng),
) -> Result<Self> {
let ring = Ring::new(ring);
let commitment_ring = Ring::new(commitment_ring);
let mut fake_responses = [Scalar::zero(); RING_SIZE - 1];
for response in fake_responses.iter_mut().take(RING_SIZE - 1) {
*response = Scalar::random(rng);
@ -226,9 +222,9 @@ pub struct Alice2 {
}
pub struct Bob0 {
ring: Ring,
ring: [EdwardsPoint; RING_SIZE],
msg: [u8; 32],
commitment_ring: Ring,
commitment_ring: [EdwardsPoint; RING_SIZE],
pseudo_output_commitment: EdwardsPoint,
R_a: EdwardsPoint,
R_prime_a: EdwardsPoint,
@ -251,9 +247,6 @@ impl Bob0 {
s_b: Scalar,
rng: &mut (impl Rng + CryptoRng),
) -> Result<Self> {
let ring = Ring::new(ring);
let commitment_ring = Ring::new(commitment_ring);
let alpha_b = Scalar::random(rng);
let p_k = ring[0];
@ -300,9 +293,9 @@ impl Bob0 {
}
pub struct Bob1 {
ring: Ring,
ring: [EdwardsPoint; RING_SIZE],
msg: [u8; 32],
commitment_ring: Ring,
commitment_ring: [EdwardsPoint; RING_SIZE],
pseudo_output_commitment: EdwardsPoint,
R_a: EdwardsPoint,
R_prime_a: EdwardsPoint,
@ -634,9 +627,9 @@ mod tests {
assert!(clsag::verify(
&sig,
msg_to_sign,
todo!(),
todo!(),
todo!(),
&ring,
&commitment_ring,
pseudo_output_commitment,
todo!()
));
}

View File

@ -3,13 +3,13 @@ use std::ops::Index;
use curve25519_dalek::edwards::EdwardsPoint;
#[derive(Clone)]
pub struct Ring {
elements: [EdwardsPoint; 11],
pub struct Ring<'a> {
elements: &'a [EdwardsPoint; 11],
bytes: [u8; 32 * 11],
}
impl Ring {
pub fn new(elements: [EdwardsPoint; 11]) -> Ring {
impl<'a> Ring<'a> {
pub fn new(elements: &[EdwardsPoint; 11]) -> Ring<'_> {
let mut bytes = [0u8; 32 * 11];
for (i, element) in elements.iter().enumerate() {
@ -23,13 +23,13 @@ impl Ring {
}
}
impl AsRef<[u8]> for Ring {
impl<'a> AsRef<[u8]> for Ring<'a> {
fn as_ref(&self) -> &[u8] {
self.bytes.as_ref()
}
}
impl Index<usize> for Ring {
impl<'a> Index<usize> for Ring<'a> {
type Output = EdwardsPoint;
fn index(&self, index: usize) -> &Self::Output {