mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 20:29:23 +00:00
Enable no_std on transcript
Removes the Vec challenge for an associated type. Fixes the merlin feature which was horribly broken. Also adds no_std to dalek-ff-group.
This commit is contained in:
@@ -1,15 +1,22 @@
|
||||
use core::{marker::PhantomData, fmt::{Debug, Formatter}};
|
||||
use core::fmt::{Debug, Formatter};
|
||||
|
||||
use digest::Digest;
|
||||
use crate::Transcript;
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
#[derive(Clone)]
|
||||
pub struct MerlinTranscript(pub merlin::Transcript);
|
||||
// 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(()) }
|
||||
fn fmt(&self, _: &mut Formatter<'_>) -> Result<(), core::fmt::Error> { Ok(()) }
|
||||
}
|
||||
|
||||
impl Transcript for MerlinTranscript {
|
||||
// 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 should be secure with this setting
|
||||
type Challenge = [u8; 64];
|
||||
|
||||
fn domain_separate(&mut self, label: &'static [u8]) {
|
||||
self.append_message(b"dom-sep", label);
|
||||
}
|
||||
@@ -18,21 +25,15 @@ impl Transcript for MerlinTranscript {
|
||||
self.0.append_message(label, message);
|
||||
}
|
||||
|
||||
fn challenge(&mut self, label: &'static [u8]) -> Vec<u8> {
|
||||
let mut challenge = vec![];
|
||||
// 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);
|
||||
fn challenge(&mut self, label: &'static [u8]) -> Self::Challenge {
|
||||
let mut challenge = [0; 64];
|
||||
self.0.challenge_bytes(label, &mut challenge);
|
||||
challenge
|
||||
}
|
||||
|
||||
fn rng_seed(&mut self, label: &'static [u8]) -> [u8; 32] {
|
||||
let mut seed = [0; 32];
|
||||
transcript.challenge_bytes(label, &mut seed);
|
||||
seed.copy_from_slice(&self.challenge(label)[.. 32]);
|
||||
seed
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user