Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade sha2/sha3/digest from 0.9 to 0.10 #130

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ csv = ">= 1.0, < 1.2" # csv 1.2 has MSRV 1.60
criterion = "0.3"
hex = "0.4"
rand_xorshift = "0.3"
sha2 = "0.9"
sha3 = "0.9"
sha2 = "0.10"
sha3 = "0.10"

[[bench]]
name = "groups"
Expand All @@ -34,7 +34,7 @@ harness = false
required-features = ["experimental"]

[dependencies.digest]
version = "0.9"
version = "0.10"
optional = true

[dependencies.ff]
Expand Down
28 changes: 14 additions & 14 deletions src/hash_to_curve/expand_msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use core::{
marker::PhantomData,
};

use digest::{BlockInput, Digest, ExtendableOutputDirty, Update, XofReader};
use digest::{core_api::BlockSizeUser, Digest, ExtendableOutput, Update, XofReader};

use crate::generic_array::{
typenum::{Unsigned, U32},
Expand Down Expand Up @@ -35,14 +35,14 @@ impl<'x, L: ArrayLength<u8>> ExpandMsgDst<'x, L> {
/// Produces a DST for use with `expand_message_xof`.
pub fn process_xof<H>(dst: &'x [u8]) -> Self
where
H: Default + Update + ExtendableOutputDirty,
H: Default + Update + ExtendableOutput,
{
if dst.len() > 255 {
let mut data = GenericArray::<u8, L>::default();
H::default()
.chain(OVERSIZE_DST_SALT)
.chain(&dst)
.finalize_xof_dirty()
.finalize_xof()
.read(&mut data);
Self::Hashed(data)
} else {
Expand All @@ -53,7 +53,7 @@ impl<'x, L: ArrayLength<u8>> ExpandMsgDst<'x, L> {
/// Produces a DST for use with `expand_message_xmd`.
pub fn process_xmd<H>(dst: &'x [u8]) -> Self
where
H: Digest<OutputSize = L>,
H: Digest<OutputSize = L> + Update,
{
if dst.len() > 255 {
Self::Hashed(H::new().chain(OVERSIZE_DST_SALT).chain(&dst).finalize())
Expand Down Expand Up @@ -124,12 +124,12 @@ pub trait ExpandMessageState<'x> {
/// with `k = 128`.
///
/// [expand_message_xof]: https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-hash-to-curve-12#section-5.4.2
pub struct ExpandMsgXof<H: ExtendableOutputDirty> {
hash: <H as ExtendableOutputDirty>::Reader,
pub struct ExpandMsgXof<H: ExtendableOutput> {
hash: <H as ExtendableOutput>::Reader,
remain: usize,
}

impl<H: ExtendableOutputDirty> Debug for ExpandMsgXof<H> {
impl<H: ExtendableOutput> Debug for ExpandMsgXof<H> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.debug_struct("ExpandMsgXof")
.field("remain", &self.remain)
Expand All @@ -139,7 +139,7 @@ impl<H: ExtendableOutputDirty> Debug for ExpandMsgXof<H> {

impl<'x, H> ExpandMessageState<'x> for ExpandMsgXof<H>
where
H: ExtendableOutputDirty,
H: ExtendableOutput,
{
fn read_into(&mut self, output: &mut [u8]) -> usize {
let len = self.remain.min(output.len());
Expand All @@ -155,7 +155,7 @@ where

impl<'x, H> InitExpandMessage<'x> for ExpandMsgXof<H>
where
H: Default + Update + ExtendableOutputDirty,
H: Default + Update + ExtendableOutput,
{
type Expander = Self;

Expand All @@ -167,7 +167,7 @@ where
.chain((len_in_bytes as u16).to_be_bytes())
.chain(dst.data())
.chain([dst.len() as u8])
.finalize_xof_dirty();
.finalize_xof();
Self {
hash,
remain: len_in_bytes,
Expand Down Expand Up @@ -209,19 +209,19 @@ impl<H: Digest> Debug for ExpandMsgXmdState<'_, H> {

impl<'x, H> InitExpandMessage<'x> for ExpandMsgXmd<H>
where
H: Digest + BlockInput,
H: Digest + Update + BlockSizeUser,
{
type Expander = ExpandMsgXmdState<'x, H>;

fn init_expand(message: &[u8], dst: &'x [u8], len_in_bytes: usize) -> Self::Expander {
let hash_size = <H as Digest>::OutputSize::to_usize();
let hash_size = <H as Digest>::output_size();
let ell = (len_in_bytes + hash_size - 1) / hash_size;
if ell > 255 {
panic!("Invalid ExpandMsgXmd usage: ell > 255");
}
let dst = ExpandMsgDst::process_xmd::<H>(dst);
let b_0 = H::new()
.chain(GenericArray::<u8, <H as BlockInput>::BlockSize>::default())
.chain(GenericArray::<u8, <H as BlockSizeUser>::BlockSize>::default())
.chain(message)
.chain((len_in_bytes as u16).to_be_bytes())
.chain([0u8])
Expand All @@ -248,7 +248,7 @@ where

impl<'x, H> ExpandMessageState<'x> for ExpandMsgXmdState<'x, H>
where
H: Digest + BlockInput,
H: Digest + Update,
{
fn read_into(&mut self, output: &mut [u8]) -> usize {
let read_len = self.remain.min(output.len());
Expand Down