Add common_scalar method to Transcript.

This commit is contained in:
Sean Bowe 2021-02-12 09:08:56 -07:00
parent 7ac44e8d53
commit d3cd39fc6d
No known key found for this signature in database
GPG Key ID: 95684257D8F8B031
1 changed files with 18 additions and 2 deletions

View File

@ -19,6 +19,10 @@ pub trait Transcript<C: CurveAffine> {
/// Writing the point to the transcript without writing it to the proof, /// Writing the point to the transcript without writing it to the proof,
/// treating it as a common input. /// treating it as a common input.
fn common_point(&mut self, point: C) -> io::Result<()>; fn common_point(&mut self, point: C) -> io::Result<()>;
/// Writing the scalar to the transcript without writing it to the proof,
/// treating it as a common input.
fn common_scalar(&mut self, scalar: C::Scalar) -> io::Result<()>;
} }
/// Transcript view from the perspective of a verifier that has access to an /// Transcript view from the perspective of a verifier that has access to an
@ -84,7 +88,7 @@ impl<R: Read, C: CurveAffine> TranscriptRead<C> for Blake2bRead<R, C> {
"invalid field element encoding in proof", "invalid field element encoding in proof",
) )
})?; })?;
self.state.update(&scalar.to_bytes()); self.common_scalar(scalar)?;
Ok(scalar) Ok(scalar)
} }
@ -104,6 +108,12 @@ impl<R: Read, C: CurveAffine> Transcript<C> for Blake2bRead<R, C> {
Ok(()) Ok(())
} }
fn common_scalar(&mut self, scalar: C::Scalar) -> io::Result<()> {
self.state.update(&scalar.to_bytes());
Ok(())
}
fn squeeze_challenge(&mut self) -> C::Base { fn squeeze_challenge(&mut self) -> C::Base {
let hasher = self.state.clone(); let hasher = self.state.clone();
let result: [u8; 64] = hasher.finalize().as_bytes().try_into().unwrap(); let result: [u8; 64] = hasher.finalize().as_bytes().try_into().unwrap();
@ -147,7 +157,7 @@ impl<W: Write, C: CurveAffine> TranscriptWrite<C> for Blake2bWrite<W, C> {
self.writer.write_all(&compressed[..]) self.writer.write_all(&compressed[..])
} }
fn write_scalar(&mut self, scalar: C::Scalar) -> io::Result<()> { fn write_scalar(&mut self, scalar: C::Scalar) -> io::Result<()> {
self.state.update(&scalar.to_bytes()); self.common_scalar(scalar)?;
let data = scalar.to_bytes(); let data = scalar.to_bytes();
self.writer.write_all(&data[..]) self.writer.write_all(&data[..])
} }
@ -167,6 +177,12 @@ impl<W: Write, C: CurveAffine> Transcript<C> for Blake2bWrite<W, C> {
Ok(()) Ok(())
} }
fn common_scalar(&mut self, scalar: C::Scalar) -> io::Result<()> {
self.state.update(&scalar.to_bytes());
Ok(())
}
fn squeeze_challenge(&mut self) -> C::Base { fn squeeze_challenge(&mut self) -> C::Base {
let hasher = self.state.clone(); let hasher = self.state.clone();
let result: [u8; 64] = hasher.finalize().as_bytes().try_into().unwrap(); let result: [u8; 64] = hasher.finalize().as_bytes().try_into().unwrap();