2022-10-29 03:54:42 -05:00
|
|
|
use group::GroupEncoding;
|
2022-06-05 16:08:51 -04:00
|
|
|
|
2022-10-29 03:54:42 -05:00
|
|
|
use ciphersuite::Ciphersuite;
|
2022-06-05 16:08:51 -04:00
|
|
|
|
2022-07-13 02:38:29 -04:00
|
|
|
use crate::{curve::Curve, algorithm::Hram};
|
2022-06-24 08:44:12 -04:00
|
|
|
|
|
|
|
|
macro_rules! kp_curve {
|
|
|
|
|
(
|
2022-09-29 06:02:43 -04:00
|
|
|
$feature: literal,
|
|
|
|
|
|
2022-06-24 08:44:12 -04:00
|
|
|
$Curve: ident,
|
|
|
|
|
$Hram: ident,
|
|
|
|
|
|
|
|
|
|
$CONTEXT: literal
|
|
|
|
|
) => {
|
2022-10-29 03:54:42 -05:00
|
|
|
pub use ciphersuite::$Curve;
|
2022-08-26 05:59:43 -04:00
|
|
|
|
2022-06-24 08:44:12 -04:00
|
|
|
impl Curve for $Curve {
|
2022-10-29 03:54:42 -05:00
|
|
|
const CONTEXT: &'static [u8] = $CONTEXT;
|
2022-06-06 02:18:25 -04:00
|
|
|
}
|
|
|
|
|
|
2022-06-24 08:44:12 -04:00
|
|
|
#[derive(Clone)]
|
|
|
|
|
pub struct $Hram;
|
|
|
|
|
impl Hram<$Curve> for $Hram {
|
|
|
|
|
#[allow(non_snake_case)]
|
2022-10-29 03:54:42 -05:00
|
|
|
fn hram(
|
|
|
|
|
R: &<$Curve as Ciphersuite>::G,
|
|
|
|
|
A: &<$Curve as Ciphersuite>::G,
|
|
|
|
|
m: &[u8],
|
|
|
|
|
) -> <$Curve as Ciphersuite>::F {
|
|
|
|
|
<$Curve as Curve>::hash_to_F(
|
|
|
|
|
b"chal",
|
|
|
|
|
&[R.to_bytes().as_ref(), A.to_bytes().as_ref(), m].concat(),
|
|
|
|
|
)
|
2022-06-24 08:44:12 -04:00
|
|
|
}
|
2022-06-05 16:08:51 -04:00
|
|
|
}
|
2022-07-15 01:26:07 -04:00
|
|
|
};
|
2022-06-05 16:08:51 -04:00
|
|
|
}
|
2022-06-06 02:18:25 -04:00
|
|
|
|
2022-06-06 04:22:49 -04:00
|
|
|
#[cfg(feature = "p256")]
|
2022-10-29 03:54:42 -05:00
|
|
|
kp_curve!("p256", P256, IetfP256Hram, b"FROST-P256-SHA256-v11");
|
2022-06-24 08:44:12 -04:00
|
|
|
|
|
|
|
|
#[cfg(feature = "secp256k1")]
|
2022-10-29 03:54:42 -05:00
|
|
|
kp_curve!("secp256k1", Secp256k1, IetfSecp256k1Hram, b"FROST-secp256k1-SHA256-v11");
|