diff --git a/monero-adaptor/src/clsag.rs b/monero-adaptor/src/clsag.rs index e3494c1f..2240a306 100644 --- a/monero-adaptor/src/clsag.rs +++ b/monero-adaptor/src/clsag.rs @@ -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 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 for Ring<'a> { + type Output = EdwardsPoint; + + fn index(&self, index: usize) -> &Self::Output { + &self.elements[index] + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/monero-adaptor/src/lib.rs b/monero-adaptor/src/lib.rs index 41efe02a..a46b3235 100644 --- a/monero-adaptor/src/lib.rs +++ b/monero-adaptor/src/lib.rs @@ -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 diff --git a/monero-adaptor/src/macros.rs b/monero-adaptor/src/macros.rs index 2010326e..6f95accd 100644 --- a/monero-adaptor/src/macros.rs +++ b/monero-adaptor/src/macros.rs @@ -1,4 +1,4 @@ -use crate::ring::Ring; +use crate::clsag::Ring; use curve25519_dalek::edwards::{CompressedEdwardsY, EdwardsPoint}; use std::borrow::Cow; diff --git a/monero-adaptor/src/ring.rs b/monero-adaptor/src/ring.rs deleted file mode 100644 index 424db196..00000000 --- a/monero-adaptor/src/ring.rs +++ /dev/null @@ -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 for Ring<'a> { - type Output = EdwardsPoint; - - fn index(&self, index: usize) -> &Self::Output { - &self.elements[index] - } -}