mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-01-10 15:09:44 -05:00
Make Ring
an implementation detail of clsag module
This commit is contained in:
parent
f9cac4b6c9
commit
53916aab6b
@ -17,8 +17,8 @@ pub fn sign(
|
|||||||
signing_key: Scalar,
|
signing_key: Scalar,
|
||||||
H_p_pk: EdwardsPoint,
|
H_p_pk: EdwardsPoint,
|
||||||
alpha: Scalar,
|
alpha: Scalar,
|
||||||
ring: &Ring,
|
ring: &[EdwardsPoint; RING_SIZE],
|
||||||
commitment_ring: &Ring,
|
commitment_ring: &[EdwardsPoint; RING_SIZE],
|
||||||
fake_responses: [Scalar; RING_SIZE - 1],
|
fake_responses: [Scalar; RING_SIZE - 1],
|
||||||
z: Scalar,
|
z: Scalar,
|
||||||
pseudo_output_commitment: EdwardsPoint,
|
pseudo_output_commitment: EdwardsPoint,
|
||||||
@ -28,6 +28,8 @@ pub fn sign(
|
|||||||
) -> Signature {
|
) -> Signature {
|
||||||
let D = z * H_p_pk;
|
let D = z * H_p_pk;
|
||||||
let D_inv_8 = D * INV_EIGHT;
|
let D_inv_8 = D * INV_EIGHT;
|
||||||
|
let ring = Ring::new(ring);
|
||||||
|
let commitment_ring = Ring::new(commitment_ring);
|
||||||
|
|
||||||
let mus = AggregationHashes::new(
|
let mus = AggregationHashes::new(
|
||||||
&ring,
|
&ring,
|
||||||
@ -92,11 +94,14 @@ pub fn sign(
|
|||||||
pub fn verify(
|
pub fn verify(
|
||||||
sig: &Signature,
|
sig: &Signature,
|
||||||
msg: &[u8],
|
msg: &[u8],
|
||||||
ring: &Ring,
|
ring: &[EdwardsPoint; RING_SIZE],
|
||||||
commitment_ring: &Ring,
|
commitment_ring: &[EdwardsPoint; RING_SIZE],
|
||||||
pseudo_output_commitment: EdwardsPoint,
|
pseudo_output_commitment: EdwardsPoint,
|
||||||
H_p_pk: EdwardsPoint,
|
H_p_pk: EdwardsPoint,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
|
let ring = Ring::new(ring);
|
||||||
|
let commitment_ring = Ring::new(commitment_ring);
|
||||||
|
|
||||||
let mus = AggregationHashes::new(
|
let mus = AggregationHashes::new(
|
||||||
&ring,
|
&ring,
|
||||||
&commitment_ring,
|
&commitment_ring,
|
||||||
@ -312,8 +317,6 @@ mod tests {
|
|||||||
x * ED25519_BASEPOINT_POINT
|
x * ED25519_BASEPOINT_POINT
|
||||||
});
|
});
|
||||||
|
|
||||||
let ring = Ring::new(ring);
|
|
||||||
|
|
||||||
let mut commitment_ring = [EdwardsPoint::default(); RING_SIZE];
|
let mut commitment_ring = [EdwardsPoint::default(); RING_SIZE];
|
||||||
|
|
||||||
let real_commitment_blinding = Scalar::random(&mut OsRng);
|
let real_commitment_blinding = Scalar::random(&mut OsRng);
|
||||||
@ -323,8 +326,6 @@ mod tests {
|
|||||||
x * ED25519_BASEPOINT_POINT
|
x * ED25519_BASEPOINT_POINT
|
||||||
});
|
});
|
||||||
|
|
||||||
let commitment_ring = Ring::new(commitment_ring);
|
|
||||||
|
|
||||||
// TODO: document
|
// TODO: document
|
||||||
let pseudo_output_commitment = commitment_ring[0];
|
let pseudo_output_commitment = commitment_ring[0];
|
||||||
|
|
||||||
|
@ -14,7 +14,6 @@ use rand::{CryptoRng, Rng};
|
|||||||
use tiny_keccak::{Hasher, Keccak};
|
use tiny_keccak::{Hasher, Keccak};
|
||||||
|
|
||||||
use clsag::{Signature, RING_SIZE};
|
use clsag::{Signature, RING_SIZE};
|
||||||
use ring::Ring;
|
|
||||||
|
|
||||||
mod clsag;
|
mod clsag;
|
||||||
mod ring;
|
mod ring;
|
||||||
@ -83,9 +82,9 @@ impl AdaptorSignature {
|
|||||||
|
|
||||||
pub struct Alice0 {
|
pub struct Alice0 {
|
||||||
// secret index is always 0
|
// secret index is always 0
|
||||||
ring: Ring,
|
ring: [EdwardsPoint; RING_SIZE],
|
||||||
fake_responses: [Scalar; RING_SIZE - 1],
|
fake_responses: [Scalar; RING_SIZE - 1],
|
||||||
commitment_ring: Ring,
|
commitment_ring: [EdwardsPoint; RING_SIZE],
|
||||||
pseudo_output_commitment: EdwardsPoint,
|
pseudo_output_commitment: EdwardsPoint,
|
||||||
msg: [u8; 32],
|
msg: [u8; 32],
|
||||||
// encryption key
|
// encryption key
|
||||||
@ -113,9 +112,6 @@ impl Alice0 {
|
|||||||
s_prime_a: Scalar,
|
s_prime_a: Scalar,
|
||||||
rng: &mut (impl Rng + CryptoRng),
|
rng: &mut (impl Rng + CryptoRng),
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let ring = Ring::new(ring);
|
|
||||||
let commitment_ring = Ring::new(commitment_ring);
|
|
||||||
|
|
||||||
let mut fake_responses = [Scalar::zero(); RING_SIZE - 1];
|
let mut fake_responses = [Scalar::zero(); RING_SIZE - 1];
|
||||||
for response in fake_responses.iter_mut().take(RING_SIZE - 1) {
|
for response in fake_responses.iter_mut().take(RING_SIZE - 1) {
|
||||||
*response = Scalar::random(rng);
|
*response = Scalar::random(rng);
|
||||||
@ -226,9 +222,9 @@ pub struct Alice2 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct Bob0 {
|
pub struct Bob0 {
|
||||||
ring: Ring,
|
ring: [EdwardsPoint; RING_SIZE],
|
||||||
msg: [u8; 32],
|
msg: [u8; 32],
|
||||||
commitment_ring: Ring,
|
commitment_ring: [EdwardsPoint; RING_SIZE],
|
||||||
pseudo_output_commitment: EdwardsPoint,
|
pseudo_output_commitment: EdwardsPoint,
|
||||||
R_a: EdwardsPoint,
|
R_a: EdwardsPoint,
|
||||||
R_prime_a: EdwardsPoint,
|
R_prime_a: EdwardsPoint,
|
||||||
@ -251,9 +247,6 @@ impl Bob0 {
|
|||||||
s_b: Scalar,
|
s_b: Scalar,
|
||||||
rng: &mut (impl Rng + CryptoRng),
|
rng: &mut (impl Rng + CryptoRng),
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let ring = Ring::new(ring);
|
|
||||||
let commitment_ring = Ring::new(commitment_ring);
|
|
||||||
|
|
||||||
let alpha_b = Scalar::random(rng);
|
let alpha_b = Scalar::random(rng);
|
||||||
|
|
||||||
let p_k = ring[0];
|
let p_k = ring[0];
|
||||||
@ -300,9 +293,9 @@ impl Bob0 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct Bob1 {
|
pub struct Bob1 {
|
||||||
ring: Ring,
|
ring: [EdwardsPoint; RING_SIZE],
|
||||||
msg: [u8; 32],
|
msg: [u8; 32],
|
||||||
commitment_ring: Ring,
|
commitment_ring: [EdwardsPoint; RING_SIZE],
|
||||||
pseudo_output_commitment: EdwardsPoint,
|
pseudo_output_commitment: EdwardsPoint,
|
||||||
R_a: EdwardsPoint,
|
R_a: EdwardsPoint,
|
||||||
R_prime_a: EdwardsPoint,
|
R_prime_a: EdwardsPoint,
|
||||||
@ -634,9 +627,9 @@ mod tests {
|
|||||||
assert!(clsag::verify(
|
assert!(clsag::verify(
|
||||||
&sig,
|
&sig,
|
||||||
msg_to_sign,
|
msg_to_sign,
|
||||||
todo!(),
|
&ring,
|
||||||
todo!(),
|
&commitment_ring,
|
||||||
todo!(),
|
pseudo_output_commitment,
|
||||||
todo!()
|
todo!()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
@ -3,13 +3,13 @@ use std::ops::Index;
|
|||||||
use curve25519_dalek::edwards::EdwardsPoint;
|
use curve25519_dalek::edwards::EdwardsPoint;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Ring {
|
pub struct Ring<'a> {
|
||||||
elements: [EdwardsPoint; 11],
|
elements: &'a [EdwardsPoint; 11],
|
||||||
bytes: [u8; 32 * 11],
|
bytes: [u8; 32 * 11],
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Ring {
|
impl<'a> Ring<'a> {
|
||||||
pub fn new(elements: [EdwardsPoint; 11]) -> Ring {
|
pub fn new(elements: &[EdwardsPoint; 11]) -> Ring<'_> {
|
||||||
let mut bytes = [0u8; 32 * 11];
|
let mut bytes = [0u8; 32 * 11];
|
||||||
|
|
||||||
for (i, element) in elements.iter().enumerate() {
|
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] {
|
fn as_ref(&self) -> &[u8] {
|
||||||
self.bytes.as_ref()
|
self.bytes.as_ref()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Index<usize> for Ring {
|
impl<'a> Index<usize> for Ring<'a> {
|
||||||
type Output = EdwardsPoint;
|
type Output = EdwardsPoint;
|
||||||
|
|
||||||
fn index(&self, index: usize) -> &Self::Output {
|
fn index(&self, index: usize) -> &Self::Output {
|
||||||
|
Loading…
Reference in New Issue
Block a user