2022-05-03 07:20:24 -04:00
|
|
|
use core::{marker::PhantomData, fmt::{Debug, Formatter}};
|
|
|
|
|
|
|
|
|
|
use digest::Digest;
|
|
|
|
|
|
2022-05-25 00:21:01 -04:00
|
|
|
#[derive(Clone, PartialEq)]
|
2022-05-06 07:33:08 -04:00
|
|
|
pub struct MerlinTranscript(pub merlin::Transcript);
|
2022-05-03 07:20:24 -04:00
|
|
|
// Merlin doesn't implement Debug so provide a stub which won't panic
|
|
|
|
|
impl Debug for MerlinTranscript {
|
|
|
|
|
fn fmt(&self, _: &mut Formatter<'_>) -> Result<(), std::fmt::Error> { Ok(()) }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Transcript for MerlinTranscript {
|
2022-06-03 01:37:12 -04:00
|
|
|
fn domain_separate(&mut self, label: &'static [u8]) {
|
2022-05-06 07:33:08 -04:00
|
|
|
self.append_message(b"dom-sep", label);
|
2022-05-03 07:20:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn append_message(&mut self, label: &'static [u8], message: &[u8]) {
|
|
|
|
|
self.0.append_message(label, message);
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-06 07:33:08 -04:00
|
|
|
fn challenge(&mut self, label: &'static [u8]) -> Vec<u8> {
|
2022-05-03 07:20:24 -04:00
|
|
|
let mut challenge = vec![];
|
2022-05-06 07:33:08 -04:00
|
|
|
// Uses a challenge length of 64 bytes to support wide reduction on generated scalars
|
|
|
|
|
// From a security level standpoint, this should just be 32 bytes
|
|
|
|
|
// From a Merlin standpoint, this should be variable per call
|
|
|
|
|
// From a practical standpoint, this is a demo file not planned to be used and anything using
|
|
|
|
|
// this wrapper is fine without any settings it uses
|
|
|
|
|
challenge.resize(64, 0);
|
2022-05-03 07:20:24 -04:00
|
|
|
self.0.challenge_bytes(label, &mut challenge);
|
|
|
|
|
challenge
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-31 02:12:14 -04:00
|
|
|
fn rng_seed(&mut self, label: &'static [u8]) -> [u8; 32] {
|
2022-05-03 07:20:24 -04:00
|
|
|
let mut seed = [0; 32];
|
|
|
|
|
transcript.challenge_bytes(label, &mut seed);
|
2022-05-06 07:33:08 -04:00
|
|
|
seed
|
2022-05-03 07:20:24 -04:00
|
|
|
}
|
|
|
|
|
}
|