use elliptic_curve::{
array::{Array, typenum::U64},
bigint::{Odd, U512},
};
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, PartialOrd, Ord)]
pub struct BrainpoolP512r1;
const MODULUS_HEX: &str = "aadd9db8dbe9c48b3fd4e6ae33c9fc07cb308db3b3c9d20ed6639cca7033087\
17d4d9b009bc66842aecda12ae6a380e62881ff2f2d82c68528aa6056583a48f3";
const ORDER_HEX: &str = "aadd9db8dbe9c48b3fd4e6ae33c9fc07cb308db3b3c9d20ed6639cca7033087\
0553e5c414ca92619418661197fac10471db1d381085ddaddb58796829ca90069";
const ORDER: Odd<U512> = Odd::<U512>::from_be_hex(ORDER_HEX);
pub type FieldBytes = Array<u8, U64>;
#[allow(deprecated)]
mod field {
use super::{MODULUS_HEX, U512};
use elliptic_curve::{
ff::PrimeField,
ops::BatchInvert,
subtle::{Choice, ConstantTimeEq, CtOption},
};
primefield::monty_field_params! {
name: FieldParams,
modulus: MODULUS_HEX,
uint: U512,
byte_order: primefield::ByteOrder::BigEndian,
multiplicative_generator: 2,
doc: "Montgomery parameters for brainpoolP512r1's field modulus"
}
primefield::monty_field_element! {
name: FieldElement,
params: FieldParams,
uint: U512,
doc: "Element of the brainpoolP512r1 base field, modulo p"
}
primefield::monty_field_arithmetic! {
name: FieldElement,
params: FieldParams,
uint: U512
}
impl BatchInvert for FieldElement {}
#[cfg(test)]
mod tests {
use super::{FieldElement, U512};
primefield::test_primefield!(FieldElement, U512);
}
}
#[allow(deprecated)]
mod scalar {
use super::{BrainpoolP512r1, ORDER, ORDER_HEX, U512};
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: U512,
byte_order: primefield::ByteOrder::BigEndian,
multiplicative_generator: 7,
doc: "Montgomery parameters for brainpoolP512r1's scalar modulus"
}
primefield::monty_field_element! {
name: Scalar,
params: ScalarParams,
uint: U512,
doc: "Element of the brainpoolP512r1 scalar field, modulo q"
}
primefield::monty_field_arithmetic! {
name: Scalar,
params: ScalarParams,
uint: U512
}
primefield::monty_field_reduce! {
name: Scalar,
params: ScalarParams,
uint: U512,
}
elliptic_curve::scalar_impls!(BrainpoolP512r1, 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 = U512;
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: U512 = ORDER.as_ref().shr_vartime(1);
self.to_canonical().ct_gt(&MODULUS_SHR1)
}
}
impl BatchInvert for Scalar {}
#[cfg(test)]
mod tests {
use super::{Scalar, U512};
primefield::test_primefield!(Scalar, U512);
}
}
pub use self::{field::FieldElement, scalar::Scalar};
impl elliptic_curve::Curve for BrainpoolP512r1 {
type FieldBytesSize = U64;
type Uint = U512;
const ORDER: Odd<U512> = ORDER;
}
impl elliptic_curve::PrimeCurve for BrainpoolP512r1 {}
impl elliptic_curve::point::PointCompression for BrainpoolP512r1 {
const COMPRESS_POINTS: bool = false;
}
pub type AffinePoint = primeorder::AffinePoint<BrainpoolP512r1>;
pub type ProjectivePoint = primeorder::ProjectivePoint<BrainpoolP512r1>;
impl elliptic_curve::CurveArithmetic for BrainpoolP512r1 {
type AffinePoint = AffinePoint;
type ProjectivePoint = ProjectivePoint;
type Scalar = Scalar;
}
impl elliptic_curve::hazmat::FieldArithmetic for BrainpoolP512r1 {
type FieldElement = FieldElement;
}
impl elliptic_curve::PrimeCurveArithmetic for BrainpoolP512r1 {
type CurveGroup = ProjectivePoint;
}
impl primeorder::PrimeCurveParams for BrainpoolP512r1 {
type PointArithmetic = primeorder::point_arithmetic::EquationAIsGeneric;
type Backend = primeorder::mul_backend::VariableOnly;
const EQUATION_A: FieldElement = FieldElement::from_hex_vartime(
"7830a3318b603b89e2327145ac234cc594cbdd8d3df91610a83441caea9863bc\
2ded5d5aa8253aa10a2ef1c98b9ac8b57f1117a72bf2c7b9e7c1ac4d77fc94ca",
);
const EQUATION_B: FieldElement = FieldElement::from_hex_vartime(
"3df91610a83441caea9863bc2ded5d5aa8253aa10a2ef1c98b9ac8b57f1117a7\
2bf2c7b9e7c1ac4d77fc94cadc083e67984050b75ebae5dd2809bd638016f723",
);
const GENERATOR: (FieldElement, FieldElement) = (
FieldElement::from_hex_vartime(
"81aee4bdd82ed9645a21322e9c4c6a9385ed9f70b5d916c1b43b62eef4d0098e\
ff3b1f78e2d0d48d50d1687b93b97d5f7c6d5047406a5e688b352209bcb9f822",
),
FieldElement::from_hex_vartime(
"7dde385d566332ecc0eabfa9cf7822fdf209f70024a57b1aa000c55b881f8111\
b2dcde494a5f485e5bca4bd88a2763aed1ca2b2fa8f0540678cd1e0f3ad80892",
),
);
}
impl ecdsa::EcdsaCurve for BrainpoolP512r1 {
const NORMALIZE_S: bool = false;
}
impl ecdsa::DigestAlgorithm for BrainpoolP512r1 {
type Digest = sha2::Sha512;
}