|
@ -1,7 +1,8 @@ |
|
|
use super::group::{GroupElement, VartimeMultiscalarMul, GROUP_BASEPOINT_COMPRESSED};
|
|
|
use super::group::{GroupElement, VartimeMultiscalarMul, GROUP_BASEPOINT_COMPRESSED};
|
|
|
use super::scalar::Scalar;
|
|
|
use super::scalar::Scalar;
|
|
|
use digest::{ExtendableOutput, Input, XofReader};
|
|
|
|
|
|
|
|
|
use digest::{ExtendableOutput, Input};
|
|
|
use sha3::Shake256;
|
|
|
use sha3::Shake256;
|
|
|
|
|
|
use std::io::Read;
|
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
#[derive(Debug)]
|
|
|
pub struct MultiCommitGens {
|
|
|
pub struct MultiCommitGens {
|
|
@ -20,7 +21,7 @@ impl MultiCommitGens { |
|
|
let mut gens: Vec<GroupElement> = Vec::new();
|
|
|
let mut gens: Vec<GroupElement> = Vec::new();
|
|
|
let mut uniform_bytes = [0u8; 64];
|
|
|
let mut uniform_bytes = [0u8; 64];
|
|
|
for _ in 0..n + 1 {
|
|
|
for _ in 0..n + 1 {
|
|
|
reader.read(&mut uniform_bytes);
|
|
|
|
|
|
|
|
|
reader.read_exact(&mut uniform_bytes).unwrap();
|
|
|
gens.push(GroupElement::from_uniform_bytes(&uniform_bytes));
|
|
|
gens.push(GroupElement::from_uniform_bytes(&uniform_bytes));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
@ -39,8 +40,8 @@ impl MultiCommitGens { |
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
pub fn split_at_mut(&mut self, mid: usize) -> (MultiCommitGens, MultiCommitGens) {
|
|
|
|
|
|
let (G1, G2) = self.G.split_at_mut(mid);
|
|
|
|
|
|
|
|
|
pub fn split_at(&self, mid: usize) -> (MultiCommitGens, MultiCommitGens) {
|
|
|
|
|
|
let (G1, G2) = self.G.split_at(mid);
|
|
|
|
|
|
|
|
|
(
|
|
|
(
|
|
|
MultiCommitGens {
|
|
|
MultiCommitGens {
|
|
@ -63,14 +64,14 @@ pub trait Commitments { |
|
|
|
|
|
|
|
|
impl Commitments for Scalar {
|
|
|
impl Commitments for Scalar {
|
|
|
fn commit(&self, blind: &Scalar, gens_n: &MultiCommitGens) -> GroupElement {
|
|
|
fn commit(&self, blind: &Scalar, gens_n: &MultiCommitGens) -> GroupElement {
|
|
|
assert!(gens_n.n == 1);
|
|
|
|
|
|
|
|
|
assert_eq!(gens_n.n, 1);
|
|
|
GroupElement::vartime_multiscalar_mul(&[*self, *blind], &[gens_n.G[0], gens_n.h])
|
|
|
GroupElement::vartime_multiscalar_mul(&[*self, *blind], &[gens_n.G[0], gens_n.h])
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
impl Commitments for Vec<Scalar> {
|
|
|
impl Commitments for Vec<Scalar> {
|
|
|
fn commit(&self, blind: &Scalar, gens_n: &MultiCommitGens) -> GroupElement {
|
|
|
fn commit(&self, blind: &Scalar, gens_n: &MultiCommitGens) -> GroupElement {
|
|
|
assert!(gens_n.n == self.len());
|
|
|
|
|
|
|
|
|
assert_eq!(gens_n.n, self.len());
|
|
|
GroupElement::vartime_multiscalar_mul(self, &gens_n.G) + blind * gens_n.h
|
|
|
GroupElement::vartime_multiscalar_mul(self, &gens_n.G) + blind * gens_n.h
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|