Files
serai/crypto/transcript/src/merlin.rs

59 lines
2.2 KiB
Rust
Raw Normal View History

use core::fmt::{Debug, Formatter};
use crate::Transcript;
/// A wrapper around a Merlin transcript which satisfiees the Transcript API.
///
/// Challenges are fixed to 64 bytes, despite Merlin supporting variable length challenges.
///
/// This implementation is intended to remain in the spirit of Merlin more than it's intended to be
/// in the spirit of the provided DigestTranscript. While DigestTranscript uses flags for each of
/// its different field types, the domain_separate function simply appends a message with a label
/// of "dom-sep", Merlin's preferred domain separation label. Since this could introduce transcript
/// conflicts between a domain separation and a message with a label of "dom-sep", the
/// append_message function uses an assertion to prevent such labels.
#[derive(Clone)]
pub struct MerlinTranscript(merlin::Transcript);
// Merlin doesn't implement Debug so provide a stub which won't panic
impl Debug for MerlinTranscript {
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), core::fmt::Error> {
DKG Blame (#196) * Standardize the DLEq serialization function naming They mismatched from the rest of the project. This commit is technically incomplete as it doesn't update the dkg crate. * Rewrite DKG encryption to enable per-message decryption without side effects This isn't technically true as I already know a break in this which I'll correct for shortly. Does update documentation to explain the new scheme. Required for blame. * Add a verifiable system for blame during the FROST DKG Previously, if sent an invalid key share, the participant would realize that and could accuse the sender. Without further evidence, either the accuser or the accused could be guilty. Now, the accuser has a proof the accused is in the wrong. Reworks KeyMachine to return BlameMachine. This explicitly acknowledges how locally complete keys still need group acknowledgement before the protocol can be complete and provides a way for others to verify blame, even after a locally successful run. If any blame is cast, the protocol is no longer considered complete-able (instead aborting). Further accusations of blame can still be handled however. Updates documentation on network behavior. Also starts to remove "OnDrop". We now use Zeroizing for anything which should be zeroized on drop. This is a lot more piece-meal and reduces clones. * Tweak Zeroizing and Debug impls Expands Zeroizing to be more comprehensive. Also updates Zeroizing<CachedPreprocess([u8; 32])> to CachedPreprocess(Zeroizing<[u8; 32]>) so zeroizing is the first thing done and last step before exposing the copy-able [u8; 32]. Removes private keys from Debug. * Fix a bug where adversaries could claim to be using another user's encryption keys to learn their messages Mentioned a few commits ago, now fixed. This wouldn't have affected Serai, which aborts on failure, nor any DKG currently supported. It's just about ensuring the DKG encryption is robust and proper. * Finish moving dleq from ser/deser to write/read * Add tests for dkg blame * Add a FROST test for invalid signature shares * Batch verify encrypted messages' ephemeral keys' PoP
2023-01-01 01:54:18 -05:00
fmt.debug_struct("MerlinTranscript").finish_non_exhaustive()
2022-07-15 01:26:07 -04:00
}
}
impl Transcript for MerlinTranscript {
// Uses a challenge length of 64 bytes to support wide reduction on commonly used EC scalars
// From a security level standpoint (Merlin targets 128-bits), this should just be 32 bytes
// From a Merlin standpoint, this should be variable per call
// From a practical standpoint, this should be practical
type Challenge = [u8; 64];
fn new(name: &'static [u8]) -> Self {
MerlinTranscript(merlin::Transcript::new(name))
}
fn domain_separate(&mut self, label: &'static [u8]) {
self.0.append_message(b"dom-sep", label);
}
fn append_message<M: AsRef<[u8]>>(&mut self, label: &'static [u8], message: M) {
assert!(
label != "dom-sep".as_bytes(),
"\"dom-sep\" is reserved for the domain_separate function",
);
self.0.append_message(label, message.as_ref());
}
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];
seed.copy_from_slice(&self.challenge(label)[.. 32]);
2022-05-06 07:33:08 -04:00
seed
}
}