Make Ring an implementation detail of clsag

This commit is contained in:
Thomas Eizinger 2021-05-11 14:52:53 +10:00
parent c6b36449dc
commit 5342eb5564
No known key found for this signature in database
GPG Key ID: 651AC83A6C6C8B96
4 changed files with 37 additions and 41 deletions

View File

@ -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::*;

View File

@ -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

View File

@ -1,4 +1,4 @@
use crate::ring::Ring;
use crate::clsag::Ring;
use curve25519_dalek::edwards::{CompressedEdwardsY, EdwardsPoint};
use std::borrow::Cow;

View File

@ -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]
}
}