use elliptic_curve::{
array::{Array, typenum::U28},
bigint::{Odd, U256},
};
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, PartialOrd, Ord)]
pub struct BrainpoolP224r1;
const MODULUS_HEX: &str = "00000000d7c134aa264366862a18302575d1d787b09f075797da89f57ec8c0ff";
const ORDER_HEX: &str = "00000000d7c134aa264366862a18302575d0fb98d116bc4b6ddebca3a5a7939f";
const ORDER: Odd<U256> = Odd::<U256>::from_be_hex(ORDER_HEX);
pub type FieldBytes = Array<u8, U28>;
#[expect(deprecated)]
mod field {
use super::{MODULUS_HEX, U256};
use elliptic_curve::{
ff::PrimeField,
ops::BatchInvert,
subtle::{Choice, ConstantTimeEq, CtOption},
};
primefield::monty_field_params! {
name: FieldParams,
modulus: MODULUS_HEX,
uint: U256,
byte_order: primefield::ByteOrder::BigEndian,
multiplicative_generator: 3,
doc: "Montgomery parameters for brainpoolP224r1's field modulus"
}
primefield::monty_field_element! {
name: FieldElement,
params: FieldParams,
uint: U256,
doc: "Element of the brainpoolP224r1 base field, modulo p"
}
primefield::monty_field_arithmetic! {
name: FieldElement,
params: FieldParams,
uint: U256
}
impl BatchInvert for FieldElement {}
#[cfg(test)]
mod tests {
use super::{FieldElement, U256};
primefield::test_primefield!(FieldElement, U256);
}
}
#[expect(deprecated)]
mod scalar {
use super::{BrainpoolP224r1, ORDER, ORDER_HEX, U256};
use elliptic_curve::{
ff::PrimeField,
ops::BatchInvert,
scalar::{FromUintUnchecked, IsHigh},
subtle::{Choice, ConstantTimeEq, ConstantTimeGreater as _, CtOption},
};
primefield::monty_field_params! {
name: ScalarParams,
modulus: ORDER_HEX,
uint: U256,
byte_order: primefield::ByteOrder::BigEndian,
multiplicative_generator: 3,
doc: "Montgomery parameters for brainpoolP224r1's scalar modulus"
}
primefield::monty_field_element! {
name: Scalar,
params: ScalarParams,
uint: U256,
doc: "Element of the brainpoolP224r1 scalar field, modulo q"
}
primefield::monty_field_arithmetic! {
name: Scalar,
params: ScalarParams,
uint: U256
}
impl primefield::bigint::Reduce<U256> for Scalar {
fn reduce(w: &U256) -> Self {
Self(primefield::MontyFieldElement::<ScalarParams, { U256::LIMBS }>::reduce(w))
}
}
impl primefield::bigint::Reduce<primefield::array::Array<u8, elliptic_curve::consts::U28>>
for Scalar
{
fn reduce(bytes: &primefield::array::Array<u8, elliptic_curve::consts::U28>) -> Self {
let mut wide = [0u8; 32];
wide[4..].copy_from_slice(bytes.as_slice());
<Self as primefield::bigint::Reduce<U256>>::reduce(&U256::from_be_slice(&wide))
}
}
elliptic_curve::scalar_impls!(BrainpoolP224r1, Scalar);
primeorder::wnaf::impl_wnaf_size_for_scalar!(Scalar);
impl AsRef<Scalar> for Scalar {
fn as_ref(&self) -> &Scalar {
self
}
}
impl FromUintUnchecked for Scalar {
type Uint = U256;
fn from_uint_unchecked(uint: Self::Uint) -> Self {
Self::from_uint_unchecked(uint)
}
}
impl IsHigh for Scalar {
fn is_high(&self) -> Choice {
const MODULUS_SHR1: U256 = ORDER.as_ref().shr_vartime(1);
self.to_canonical().ct_gt(&MODULUS_SHR1)
}
}
impl BatchInvert for Scalar {}
#[cfg(test)]
mod tests {
use super::{Scalar, U256};
primefield::test_primefield!(Scalar, U256);
}
}
pub use self::{field::FieldElement, scalar::Scalar};
impl elliptic_curve::Curve for BrainpoolP224r1 {
type FieldBytesSize = U28;
type Uint = U256;
const ORDER: Odd<U256> = ORDER;
}
impl elliptic_curve::PrimeCurve for BrainpoolP224r1 {}
impl elliptic_curve::point::PointCompression for BrainpoolP224r1 {
const COMPRESS_POINTS: bool = false;
}
pub type AffinePoint = primeorder::AffinePoint<BrainpoolP224r1>;
pub type ProjectivePoint = primeorder::ProjectivePoint<BrainpoolP224r1>;
impl elliptic_curve::CurveArithmetic for BrainpoolP224r1 {
type AffinePoint = AffinePoint;
type ProjectivePoint = ProjectivePoint;
type Scalar = Scalar;
}
impl elliptic_curve::hazmat::FieldArithmetic for BrainpoolP224r1 {
type FieldElement = FieldElement;
}
impl elliptic_curve::PrimeCurveArithmetic for BrainpoolP224r1 {
type CurveGroup = ProjectivePoint;
}
impl primeorder::PrimeCurveParams for BrainpoolP224r1 {
type PointArithmetic = primeorder::point_arithmetic::EquationAIsGeneric;
type Backend = primeorder::mul_backend::VariableOnly;
const EQUATION_A: FieldElement =
FieldElement::from_hex_vartime("68a5e62ca9ce6c1c299803a6c1530b514e182ad8b0042a59cad29f43");
const EQUATION_B: FieldElement =
FieldElement::from_hex_vartime("2580f63ccfe44138870713b1a92369e33e2135d266dbb372386c400b");
const GENERATOR: (FieldElement, FieldElement) = (
FieldElement::from_hex_vartime("0d9029ad2c7e5cf4340823b2a87dc68c9e4ce3174c1e6efdee12c07d"),
FieldElement::from_hex_vartime("58aa56f772c0726f24c6b89e4ecdac24354b9e99caa3f6d3761402cd"),
);
}
impl ecdsa::EcdsaCurve for BrainpoolP224r1 {
const NORMALIZE_S: bool = false;
}
impl ecdsa::DigestAlgorithm for BrainpoolP224r1 {
type Digest = sha2::Sha256;
}