2022-10-29 03:54:42 -05:00
|
|
|
use zeroize::Zeroize;
|
|
|
|
|
|
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 sha2::Sha512;
|
2022-10-29 03:54:42 -05:00
|
|
|
|
2025-08-29 06:14:25 -04:00
|
|
|
use ciphersuite::{group::Group, Ciphersuite};
|
2022-10-29 03:54:42 -05:00
|
|
|
|
2025-08-29 06:14:25 -04:00
|
|
|
use crate::Scalar;
|
2022-10-29 03:54:42 -05:00
|
|
|
|
|
|
|
|
macro_rules! dalek_curve {
|
|
|
|
|
(
|
|
|
|
|
$feature: literal,
|
|
|
|
|
|
|
|
|
|
$Ciphersuite: ident,
|
|
|
|
|
$Point: ident,
|
|
|
|
|
$ID: literal
|
|
|
|
|
) => {
|
2025-08-20 04:50:37 -04:00
|
|
|
use crate::$Point;
|
2022-10-29 03:54:42 -05:00
|
|
|
|
|
|
|
|
impl Ciphersuite for $Ciphersuite {
|
|
|
|
|
type F = Scalar;
|
|
|
|
|
type G = $Point;
|
|
|
|
|
type H = Sha512;
|
|
|
|
|
|
|
|
|
|
const ID: &'static [u8] = $ID;
|
|
|
|
|
|
|
|
|
|
fn generator() -> Self::G {
|
|
|
|
|
$Point::generator()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-23 01:03:53 -05:00
|
|
|
/// Ciphersuite for Ristretto.
|
|
|
|
|
#[derive(Clone, Copy, PartialEq, Eq, Debug, Zeroize)]
|
|
|
|
|
pub struct Ristretto;
|
2022-10-29 03:54:42 -05:00
|
|
|
dalek_curve!("ristretto", Ristretto, RistrettoPoint, b"ristretto");
|
2022-12-24 17:08:22 -05:00
|
|
|
#[test]
|
|
|
|
|
fn test_ristretto() {
|
2023-02-24 06:03:56 -05:00
|
|
|
ff_group_tests::group::test_prime_group_bits::<_, RistrettoPoint>(&mut rand_core::OsRng);
|
2022-12-24 17:08:22 -05:00
|
|
|
}
|
2022-10-29 03:54:42 -05:00
|
|
|
|
2023-03-20 20:10:00 -04:00
|
|
|
/// Ciphersuite for Ed25519, inspired by RFC-8032.
|
2023-02-23 01:03:53 -05:00
|
|
|
#[derive(Clone, Copy, PartialEq, Eq, Debug, Zeroize)]
|
|
|
|
|
pub struct Ed25519;
|
2022-10-29 03:54:42 -05:00
|
|
|
dalek_curve!("ed25519", Ed25519, EdwardsPoint, b"edwards25519");
|
2022-12-24 17:08:22 -05:00
|
|
|
#[test]
|
|
|
|
|
fn test_ed25519() {
|
2023-02-24 06:03:56 -05:00
|
|
|
ff_group_tests::group::test_prime_group_bits::<_, EdwardsPoint>(&mut rand_core::OsRng);
|
2022-12-24 17:08:22 -05:00
|
|
|
}
|