pub(crate) mod field;
pub(crate) mod scalar;
#[cfg(feature = "precomputed-tables")]
mod tables;
pub use self::scalar::Scalar;
use self::field::FieldElement;
use crate::Sm2;
use elliptic_curve::{CurveArithmetic, PrimeCurveArithmetic};
use primeorder::{PrimeCurveParams, point_arithmetic};
pub type AffinePoint = primeorder::AffinePoint<Sm2>;
pub type ProjectivePoint = primeorder::ProjectivePoint<Sm2>;
impl CurveArithmetic for Sm2 {
type AffinePoint = AffinePoint;
type ProjectivePoint = ProjectivePoint;
type Scalar = Scalar;
}
impl PrimeCurveArithmetic for Sm2 {
type CurveGroup = ProjectivePoint;
}
impl PrimeCurveParams for Sm2 {
type FieldElement = FieldElement;
type PointArithmetic = point_arithmetic::EquationAIsMinusThree;
const EQUATION_A: FieldElement = FieldElement::from_u64(3).neg();
const EQUATION_B: FieldElement = FieldElement::from_hex_vartime(
"28E9FA9E9D9F5E344D5A9E4BCF6509A7F39789F515AB8F92DDBCBD414D940E93",
);
const GENERATOR: (FieldElement, FieldElement) = (
FieldElement::from_hex_vartime(
"32C4AE2C1F1981195F9904466A39C9948FE30BBFF2660BE1715A4589334C74C7",
),
FieldElement::from_hex_vartime(
"BC3736A2F4F6779C59BDCEE36B692153D0A9877CC62A474002DF32E52139F0A0",
),
);
#[cfg(all(feature = "alloc", feature = "precomputed-tables"))]
fn mul_by_generator_vartime(k: &Scalar) -> ProjectivePoint {
tables::BASEPOINT_TABLE_VARTIME.mul(k)
}
}