Replace modular_frost::Curve::hash_to_vec with just hash

There's no reason to copy it to a heap allocated value. The Output implements
AsRef<[u8]> and all uses are satisfied by that.
This commit is contained in:
Luke Parker 2022-12-13 19:32:46 -05:00
parent 783a445a3e
commit 2b042015b5
No known key found for this signature in database

View file

@ -6,7 +6,7 @@ use rand::{RngCore, CryptoRng};
use zeroize::{Zeroize, Zeroizing};
use subtle::ConstantTimeEq;
use digest::Digest;
use digest::{Digest, Output};
use group::{
ff::{Field, PrimeField},
@ -41,8 +41,8 @@ pub trait Curve: Ciphersuite {
const CONTEXT: &'static [u8];
/// Hash the given dst and data to a byte vector. Used to instantiate H4 and H5.
fn hash_to_vec(dst: &[u8], data: &[u8]) -> Vec<u8> {
Self::H::digest([Self::CONTEXT, dst, data].concat()).as_ref().to_vec()
fn hash(dst: &[u8], data: &[u8]) -> Output<Self::H> {
Self::H::digest([Self::CONTEXT, dst, data].concat())
}
/// Field element from hash. Used during key gen and by other crates under Serai as a general
@ -53,13 +53,13 @@ pub trait Curve: Ciphersuite {
}
/// Hash the message for the binding factor. H4 from the IETF draft.
fn hash_msg(msg: &[u8]) -> Vec<u8> {
Self::hash_to_vec(b"msg", msg)
fn hash_msg(msg: &[u8]) -> Output<Self::H> {
Self::hash(b"msg", msg)
}
/// Hash the commitments for the binding factor. H5 from the IETF draft.
fn hash_commitments(commitments: &[u8]) -> Vec<u8> {
Self::hash_to_vec(b"com", commitments)
fn hash_commitments(commitments: &[u8]) -> Output<Self::H> {
Self::hash(b"com", commitments)
}
/// Hash the commitments and message to calculate the binding factor. H1 from the IETF draft.