Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
zudo committed Jun 13, 2023
1 parent 12c5cea commit f28d1f9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
18 changes: 9 additions & 9 deletions src/blsag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use serde::Serialize;
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub struct BLSAG {
pub challenge: [u8; 32],
pub responses: Vec<[u8; 32]>,
pub response: Vec<[u8; 32]>,
pub ring: Vec<[u8; 32]>,
pub image: [u8; 32],
}
Expand Down Expand Up @@ -50,20 +50,20 @@ impl BLSAG {
);
let mut challenges = vec![scalar::zero(); ring_size];
challenges[current_index] = scalar::from_hash(hashes[current_index].clone());
let mut responses = Response::random(rng, ring_size);
let mut response = Response::random(rng, ring_size);
loop {
let next_index = (current_index + 1) % ring_size;
hashes[next_index].update(
RistrettoPoint::multiscalar_mul(
&[responses.0[current_index], challenges[current_index]],
&[response.0[current_index], challenges[current_index]],
&[constants::RISTRETTO_BASEPOINT_POINT, ring.0[current_index]],
)
.compress()
.as_bytes(),
);
hashes[next_index].update(
RistrettoPoint::multiscalar_mul(
&[responses.0[current_index], challenges[current_index]],
&[response.0[current_index], challenges[current_index]],
&[point::hash::<Hash>(ring.0[current_index]), image.0],
)
.compress()
Expand All @@ -77,10 +77,10 @@ impl BLSAG {
}
current_index = next_index;
}
responses.0[secret_index] = secret_scalar_1 - (challenges[secret_index] * secret.0);
response.0[secret_index] = secret_scalar_1 - (challenges[secret_index] * secret.0);
Some(BLSAG {
challenge: challenges[0].to_bytes(),
responses: responses.to_bytes(),
response: response.to_bytes(),
ring: ring.compress(),
image: image.compress(),
})
Expand All @@ -90,22 +90,22 @@ impl BLSAG {
let hash = Hash::new().chain_update(data);
let challenge_0 = scalar::from_canonical(self.challenge)?;
let mut challenge_1 = challenge_0;
let responses = Response::from_canonical(&self.responses)?;
let response = Response::from_canonical(&self.response)?;
let ring = Ring::decompress(&self.ring)?;
let image = Image::decompress(&self.image)?;
for i in 0..self.ring.len() {
let mut hash = hash.clone();
hash.update(
RistrettoPoint::multiscalar_mul(
&[responses.0[i], challenge_1],
&[response.0[i], challenge_1],
&[constants::RISTRETTO_BASEPOINT_POINT, ring.0[i]],
)
.compress()
.as_bytes(),
);
hash.update(
RistrettoPoint::multiscalar_mul(
&[responses.0[i], challenge_1],
&[response.0[i], challenge_1],
&[
point::from_hash(Hash::new().chain_update(self.ring[i])),
image.0,
Expand Down
18 changes: 9 additions & 9 deletions src/clsag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use serde::Serialize;
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub struct CLSAG {
pub challenge: [u8; 32],
pub responses: Vec<[u8; 32]>,
pub response: Vec<[u8; 32]>,
pub rings: Vec<Vec<[u8; 32]>>,
pub images: Vec<[u8; 32]>,
}
Expand Down Expand Up @@ -69,13 +69,13 @@ impl CLSAG {
hashes[current_index].update((secret_scalar * base_point).compress().as_bytes());
let mut challenges = vec![scalar::zero(); ring_size];
challenges[current_index] = scalar::from_hash(hashes[current_index].clone());
let mut responses = Response::random(rng, ring_size);
let mut response = Response::random(rng, ring_size);
loop {
let next_index = (current_index + 1) % ring_size;
hashes[next_index].update(
RistrettoPoint::multiscalar_mul(
&[
responses.0[current_index % ring_size],
response.0[current_index % ring_size],
challenges[current_index % ring_size],
],
&[
Expand All @@ -89,7 +89,7 @@ impl CLSAG {
hashes[next_index].update(
RistrettoPoint::multiscalar_mul(
&[
responses.0[current_index % ring_size],
response.0[current_index % ring_size],
challenges[current_index % ring_size],
],
&[
Expand All @@ -108,11 +108,11 @@ impl CLSAG {
}
current_index = next_index;
}
responses.0[secret_index] =
response.0[secret_index] =
secret_scalar - (challenges[secret_index] * aggregate_private_key);
Some(CLSAG {
challenge: challenges[0].to_bytes(),
responses: responses.to_bytes(),
response: response.to_bytes(),
rings: rings.compress(),
images: images.compress(),
})
Expand All @@ -123,7 +123,7 @@ impl CLSAG {
let ring_layers = self.rings[0].len();
let rings = Rings::decompress(&self.rings)?;
let images = Images::decompress(&self.images)?;
let responses = Response::from_canonical(&self.responses)?;
let response = Response::from_canonical(&self.response)?;
let challenge_0 = scalar::from_canonical(self.challenge)?;
let mut challenge_1 = challenge_0;
let prefixed_hashes_with_images =
Expand All @@ -143,7 +143,7 @@ impl CLSAG {
hash.update(&data);
hash.update(
RistrettoPoint::multiscalar_mul(
&[responses.0[i], challenge_1],
&[response.0[i], challenge_1],
&[
constants::RISTRETTO_BASEPOINT_POINT,
aggregate_public_keys[i],
Expand All @@ -154,7 +154,7 @@ impl CLSAG {
);
hash.update(
RistrettoPoint::multiscalar_mul(
&[responses.0[i], challenge_1],
&[response.0[i], challenge_1],
&[point::hash::<Hash>(rings.0[i][0]), aggregate_image],
)
.compress()
Expand Down
14 changes: 7 additions & 7 deletions src/sag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use serde::Serialize;
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub struct SAG {
pub challenge: [u8; 32],
pub responses: Vec<[u8; 32]>,
pub response: Vec<[u8; 32]>,
pub ring: Vec<[u8; 32]>,
}
impl SAG {
Expand All @@ -41,12 +41,12 @@ impl SAG {
);
let mut challenges = vec![scalar::zero(); ring_size];
challenges[current_index] = scalar::from_hash(hashes[current_index].clone());
let mut responses = Response::random(rng, ring_size);
let mut response = Response::random(rng, ring_size);
loop {
let next_index = (current_index + 1) % ring_size;
hashes[next_index].update(
RistrettoPoint::multiscalar_mul(
&[responses.0[current_index], challenges[current_index]],
&[response.0[current_index], challenges[current_index]],
&[constants::RISTRETTO_BASEPOINT_POINT, ring.0[current_index]],
)
.compress()
Expand All @@ -60,10 +60,10 @@ impl SAG {
}
current_index = next_index;
}
responses.0[secret_index] = secret_scalar_1 - (challenges[secret_index] * secret.0);
response.0[secret_index] = secret_scalar_1 - (challenges[secret_index] * secret.0);
Some(SAG {
challenge: challenges[0].to_bytes(),
responses: responses.to_bytes(),
response: response.to_bytes(),
ring: ring.compress(),
})
}
Expand All @@ -72,13 +72,13 @@ impl SAG {
let hash = Hash::new().chain_update(data);
let challenge_0 = scalar::from_canonical(self.challenge)?;
let mut challenge_1 = challenge_0;
let responses = Response::from_canonical(&self.responses)?;
let response = Response::from_canonical(&self.response)?;
let ring = Ring::decompress(&self.ring)?;
for i in 0..self.ring.len() {
let mut hash = hash.clone();
hash.update(
RistrettoPoint::multiscalar_mul(
&[responses.0[i], challenge_1],
&[response.0[i], challenge_1],
&[constants::RISTRETTO_BASEPOINT_POINT, ring.0[i]],
)
.compress()
Expand Down

0 comments on commit f28d1f9

Please sign in to comment.