mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-10-01 01:45:40 -04:00
Make Ring an implementation detail of clsag
This commit is contained in:
parent
c6b36449dc
commit
5342eb5564
@ -1,8 +1,8 @@
|
||||
use crate::ring::Ring;
|
||||
use curve25519_dalek::constants::ED25519_BASEPOINT_POINT;
|
||||
use curve25519_dalek::edwards::EdwardsPoint;
|
||||
use curve25519_dalek::scalar::Scalar;
|
||||
use hash_edwards_to_edwards::hash_point_to_point;
|
||||
use std::ops::Index;
|
||||
|
||||
pub const RING_SIZE: usize = 11;
|
||||
|
||||
@ -191,6 +191,41 @@ impl From<Signature> for monero::util::ringct::Clsag {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub(crate) struct Ring<'a> {
|
||||
elements: &'a [EdwardsPoint; 11],
|
||||
bytes: [u8; 32 * 11],
|
||||
}
|
||||
|
||||
impl<'a> Ring<'a> {
|
||||
fn new(elements: &[EdwardsPoint; 11]) -> Ring<'_> {
|
||||
let mut bytes = [0u8; 32 * 11];
|
||||
|
||||
for (i, element) in elements.iter().enumerate() {
|
||||
let start = i * 32;
|
||||
let end = (i + 1) * 32;
|
||||
|
||||
bytes[start..end].copy_from_slice(element.compress().as_bytes());
|
||||
}
|
||||
|
||||
Ring { elements, bytes }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> AsRef<[u8]> for Ring<'a> {
|
||||
fn as_ref(&self) -> &[u8] {
|
||||
self.bytes.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Index<usize> for Ring<'a> {
|
||||
type Output = EdwardsPoint;
|
||||
|
||||
fn index(&self, index: usize) -> &Self::Output {
|
||||
&self.elements[index]
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
@ -18,7 +18,6 @@ use clsag::{Signature, RING_SIZE};
|
||||
#[macro_use]
|
||||
mod macros;
|
||||
mod clsag;
|
||||
mod ring;
|
||||
|
||||
// for every iteration we compute:
|
||||
// c_p = h_prev * mu_P; and
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::ring::Ring;
|
||||
use crate::clsag::Ring;
|
||||
use curve25519_dalek::edwards::{CompressedEdwardsY, EdwardsPoint};
|
||||
use std::borrow::Cow;
|
||||
|
||||
|
@ -1,38 +0,0 @@
|
||||
use std::ops::Index;
|
||||
|
||||
use curve25519_dalek::edwards::EdwardsPoint;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Ring<'a> {
|
||||
elements: &'a [EdwardsPoint; 11],
|
||||
bytes: [u8; 32 * 11],
|
||||
}
|
||||
|
||||
impl<'a> Ring<'a> {
|
||||
pub fn new(elements: &[EdwardsPoint; 11]) -> Ring<'_> {
|
||||
let mut bytes = [0u8; 32 * 11];
|
||||
|
||||
for (i, element) in elements.iter().enumerate() {
|
||||
let start = i * 32;
|
||||
let end = (i + 1) * 32;
|
||||
|
||||
bytes[start..end].copy_from_slice(element.compress().as_bytes());
|
||||
}
|
||||
|
||||
Ring { elements, bytes }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> AsRef<[u8]> for Ring<'a> {
|
||||
fn as_ref(&self) -> &[u8] {
|
||||
self.bytes.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Index<usize> for Ring<'a> {
|
||||
type Output = EdwardsPoint;
|
||||
|
||||
fn index(&self, index: usize) -> &Self::Output {
|
||||
&self.elements[index]
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user