2022-10-29 03:54:42 -05:00
|
|
|
use zeroize::Zeroize;
|
|
|
|
|
|
2025-08-20 04:50:37 -04:00
|
|
|
use sha3::{
|
|
|
|
|
digest::{
|
|
|
|
|
typenum::U114, core_api::BlockSizeUser, Update, Output, OutputSizeUser, FixedOutput,
|
Replace `Ciphersuite::hash_to_F`
The prior-present `Ciphersuite::hash_to_F` was a sin. Implementations took a
DST, yet were not require to securely handle it. It was also biased towards the
requirements of `modular-frost` as `ciphersuite` was originally written all
those years ago, when `modular-frost` had needs exceeding what `ff`, `group`
satisfied.
Now, the hash is bound to produce an output which can be converted to a scalar
with `ff::FromUniformBytes`. A new `hash_to_F`, which accepts a single argument
of the value to hash (removing the potential to insecurely handle the DST by
removing the DST entirely). Due to `digest` yielding a `GenericArray`, yet
`FromUniformBytes` taking a `const usize`, the `ciphersuite` crate now defines
a `FromUniformBytes` trait taking an array (then implemented for all satisfiers
of `ff::FromUniformBytes`). In order to get the array type from the
`GenericArray`, the output of the hash, `digest` is updated to the `0.11`
release candidate which moves to `flexible-array` which solves that problem.
The existing, specific `hash_to_F` functions have been moved to `modular-frost`
as necessary.
`flexible-array` itself is patched to a fork due to
https://github.com/RustCrypto/hybrid-array/issues/131.
2025-08-29 05:04:03 -04:00
|
|
|
ExtendableOutput, XofReader, HashMarker,
|
2025-08-20 04:50:37 -04:00
|
|
|
},
|
|
|
|
|
Shake256,
|
2022-10-29 03:54:42 -05:00
|
|
|
};
|
|
|
|
|
|
Replace `Ciphersuite::hash_to_F`
The prior-present `Ciphersuite::hash_to_F` was a sin. Implementations took a
DST, yet were not require to securely handle it. It was also biased towards the
requirements of `modular-frost` as `ciphersuite` was originally written all
those years ago, when `modular-frost` had needs exceeding what `ff`, `group`
satisfied.
Now, the hash is bound to produce an output which can be converted to a scalar
with `ff::FromUniformBytes`. A new `hash_to_F`, which accepts a single argument
of the value to hash (removing the potential to insecurely handle the DST by
removing the DST entirely). Due to `digest` yielding a `GenericArray`, yet
`FromUniformBytes` taking a `const usize`, the `ciphersuite` crate now defines
a `FromUniformBytes` trait taking an array (then implemented for all satisfiers
of `ff::FromUniformBytes`). In order to get the array type from the
`GenericArray`, the output of the hash, `digest` is updated to the `0.11`
release candidate which moves to `flexible-array` which solves that problem.
The existing, specific `hash_to_F` functions have been moved to `modular-frost`
as necessary.
`flexible-array` itself is patched to a fork due to
https://github.com/RustCrypto/hybrid-array/issues/131.
2025-08-29 05:04:03 -04:00
|
|
|
use ciphersuite::{group::Group, Ciphersuite};
|
2022-10-29 03:54:42 -05:00
|
|
|
|
2025-08-28 03:36:15 -04:00
|
|
|
use crate::{Scalar, Point};
|
2022-10-29 03:54:42 -05:00
|
|
|
|
2023-02-23 01:03:53 -05:00
|
|
|
/// Shake256, fixed to a 114-byte output, as used by Ed448.
|
2022-10-29 03:54:42 -05:00
|
|
|
#[derive(Clone, Default)]
|
|
|
|
|
pub struct Shake256_114(Shake256);
|
|
|
|
|
impl BlockSizeUser for Shake256_114 {
|
|
|
|
|
type BlockSize = <Shake256 as BlockSizeUser>::BlockSize;
|
|
|
|
|
fn block_size() -> usize {
|
|
|
|
|
Shake256::block_size()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
impl OutputSizeUser for Shake256_114 {
|
|
|
|
|
type OutputSize = U114;
|
|
|
|
|
fn output_size() -> usize {
|
|
|
|
|
114
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
impl Update for Shake256_114 {
|
|
|
|
|
fn update(&mut self, data: &[u8]) {
|
|
|
|
|
self.0.update(data);
|
|
|
|
|
}
|
|
|
|
|
fn chain(mut self, data: impl AsRef<[u8]>) -> Self {
|
|
|
|
|
Update::update(&mut self, data.as_ref());
|
|
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
impl FixedOutput for Shake256_114 {
|
|
|
|
|
fn finalize_fixed(self) -> Output<Self> {
|
|
|
|
|
let mut res = Default::default();
|
|
|
|
|
FixedOutput::finalize_into(self, &mut res);
|
|
|
|
|
res
|
|
|
|
|
}
|
|
|
|
|
fn finalize_into(self, out: &mut Output<Self>) {
|
|
|
|
|
let mut reader = self.0.finalize_xof();
|
|
|
|
|
reader.read(out);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
impl HashMarker for Shake256_114 {}
|
|
|
|
|
|
|
|
|
|
#[derive(Clone, Copy, PartialEq, Eq, Debug, Zeroize)]
|
|
|
|
|
pub struct Ed448;
|
|
|
|
|
impl Ciphersuite for Ed448 {
|
|
|
|
|
type F = Scalar;
|
|
|
|
|
type G = Point;
|
|
|
|
|
type H = Shake256_114;
|
|
|
|
|
|
|
|
|
|
const ID: &'static [u8] = b"ed448";
|
|
|
|
|
|
|
|
|
|
fn generator() -> Self::G {
|
|
|
|
|
Point::generator()
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-12-24 17:08:22 -05:00
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_ed448() {
|
2023-04-22 04:38:47 -04:00
|
|
|
ff_group_tests::group::test_prime_group_bits::<_, Point>(&mut rand_core::OsRng);
|
2022-12-24 17:08:22 -05:00
|
|
|
}
|