mirror of
https://github.com/saymrwulf/pasta_curves-source.git
synced 2026-09-05 20:10:32 +00:00
Move CURVE_ID to CurveExt.
This commit is contained in:
parent
75bb8121fb
commit
12230a49e0
2 changed files with 9 additions and 9 deletions
|
|
@ -33,6 +33,9 @@ pub trait CurveExt:
|
||||||
+ Mul<Self::ScalarExt, Output = Self>
|
+ Mul<Self::ScalarExt, Output = Self>
|
||||||
+ for<'r> Mul<Self::ScalarExt, Output = Self>;
|
+ for<'r> Mul<Self::ScalarExt, Output = Self>;
|
||||||
|
|
||||||
|
/// CURVE_ID used for hash-to-curve.
|
||||||
|
const CURVE_ID: &'static str;
|
||||||
|
|
||||||
/// Apply the curve endomorphism by multiplying the x-coordinate
|
/// Apply the curve endomorphism by multiplying the x-coordinate
|
||||||
/// by an element of multiplicative order 3.
|
/// by an element of multiplicative order 3.
|
||||||
fn endo(&self) -> Self;
|
fn endo(&self) -> Self;
|
||||||
|
|
@ -96,9 +99,6 @@ pub trait CurveAffine:
|
||||||
/// The projective form of the curve
|
/// The projective form of the curve
|
||||||
type CurveExt: CurveExt<AffineExt = Self, ScalarExt = <Self as CurveAffine>::ScalarExt>;
|
type CurveExt: CurveExt<AffineExt = Self, ScalarExt = <Self as CurveAffine>::ScalarExt>;
|
||||||
|
|
||||||
/// CURVE_ID used for hash-to-curve.
|
|
||||||
const CURVE_ID: &'static str;
|
|
||||||
|
|
||||||
/// Gets the $(x, y)$ coordinates of this point.
|
/// Gets the $(x, y)$ coordinates of this point.
|
||||||
fn get_xy(&self) -> CtOption<(Self::Base, Self::Base)>;
|
fn get_xy(&self) -> CtOption<(Self::Base, Self::Base)>;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,9 @@ macro_rules! new_curve_impl {
|
||||||
type Base = $base;
|
type Base = $base;
|
||||||
type AffineExt = $name_affine;
|
type AffineExt = $name_affine;
|
||||||
|
|
||||||
impl_projective_curve_ext!($name, $name_affine, $iso, $base, $curve_type);
|
const CURVE_ID: &'static str = $curve_id;
|
||||||
|
|
||||||
|
impl_projective_curve_ext!($name, $iso, $base, $curve_type);
|
||||||
|
|
||||||
fn a() -> Self::Base {
|
fn a() -> Self::Base {
|
||||||
$name::curve_constant_a()
|
$name::curve_constant_a()
|
||||||
|
|
@ -615,8 +617,6 @@ macro_rules! new_curve_impl {
|
||||||
type Base = $base;
|
type Base = $base;
|
||||||
type CurveExt = $name;
|
type CurveExt = $name;
|
||||||
|
|
||||||
const CURVE_ID: &'static str = $curve_id;
|
|
||||||
|
|
||||||
fn is_on_curve(&self) -> Choice {
|
fn is_on_curve(&self) -> Choice {
|
||||||
// y^2 - x^3 - ax ?= b
|
// y^2 - x^3 - ax ?= b
|
||||||
(self.y.square() - (self.x.square() + &$name::curve_constant_a()) * self.x).ct_eq(&$name::curve_constant_b())
|
(self.y.square() - (self.x.square() + &$name::curve_constant_a()) * self.x).ct_eq(&$name::curve_constant_b())
|
||||||
|
|
@ -834,13 +834,13 @@ macro_rules! impl_projective_curve_specific {
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! impl_projective_curve_ext {
|
macro_rules! impl_projective_curve_ext {
|
||||||
($name:ident, $name_affine:ident, $iso:ident, $base:ident, special_a0_b5) => {
|
($name:ident, $iso:ident, $base:ident, special_a0_b5) => {
|
||||||
fn hash_to_curve<'a>(domain_prefix: &'a str) -> Box<dyn Fn(&[u8]) -> Self + 'a> {
|
fn hash_to_curve<'a>(domain_prefix: &'a str) -> Box<dyn Fn(&[u8]) -> Self + 'a> {
|
||||||
use super::hashtocurve;
|
use super::hashtocurve;
|
||||||
|
|
||||||
Box::new(move |message| {
|
Box::new(move |message| {
|
||||||
let mut us = [Field::zero(); 2];
|
let mut us = [Field::zero(); 2];
|
||||||
hashtocurve::hash_to_field($name_affine::CURVE_ID, domain_prefix, message, &mut us);
|
hashtocurve::hash_to_field($name::CURVE_ID, domain_prefix, message, &mut us);
|
||||||
let q0 = hashtocurve::map_to_curve_simple_swu::<$base, $name, $iso>(
|
let q0 = hashtocurve::map_to_curve_simple_swu::<$base, $name, $iso>(
|
||||||
&us[0],
|
&us[0],
|
||||||
$name::THETA,
|
$name::THETA,
|
||||||
|
|
@ -867,7 +867,7 @@ macro_rules! impl_projective_curve_ext {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
($name:ident, $name_affine:ident, $iso:ident, $base:ident, general) => {
|
($name:ident, $iso:ident, $base:ident, general) => {
|
||||||
/// Unimplemented: hashing to this curve is not supported
|
/// Unimplemented: hashing to this curve is not supported
|
||||||
fn hash_to_curve<'a>(_domain_prefix: &'a str) -> Box<dyn Fn(&[u8]) -> Self + 'a> {
|
fn hash_to_curve<'a>(_domain_prefix: &'a str) -> Box<dyn Fn(&[u8]) -> Self + 'a> {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue