Add common_scalar method to Transcript.
This commit is contained in:
parent
7ac44e8d53
commit
d3cd39fc6d
|
@ -19,6 +19,10 @@ pub trait Transcript<C: CurveAffine> {
|
|||
/// Writing the point to the transcript without writing it to the proof,
|
||||
/// treating it as a common input.
|
||||
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
|
||||
|
@ -84,7 +88,7 @@ impl<R: Read, C: CurveAffine> TranscriptRead<C> for Blake2bRead<R, C> {
|
|||
"invalid field element encoding in proof",
|
||||
)
|
||||
})?;
|
||||
self.state.update(&scalar.to_bytes());
|
||||
self.common_scalar(scalar)?;
|
||||
|
||||
Ok(scalar)
|
||||
}
|
||||
|
@ -104,6 +108,12 @@ impl<R: Read, C: CurveAffine> Transcript<C> for Blake2bRead<R, C> {
|
|||
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 {
|
||||
let hasher = self.state.clone();
|
||||
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[..])
|
||||
}
|
||||
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();
|
||||
self.writer.write_all(&data[..])
|
||||
}
|
||||
|
@ -167,6 +177,12 @@ impl<W: Write, C: CurveAffine> Transcript<C> for Blake2bWrite<W, C> {
|
|||
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 {
|
||||
let hasher = self.state.clone();
|
||||
let result: [u8; 64] = hasher.finalize().as_bytes().try_into().unwrap();
|
||||
|
|
Loading…
Reference in New Issue