From 0a4db20d82a90f0ee39252ee093ccb95b743538f Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Mon, 1 Mar 2021 20:27:34 +0000 Subject: [PATCH] impl group::cofactor::CofactorGroup for Pallas and Vesta Prime-order groups can be treated as a group with a cofactor of 1, allowing them to be used in cofactor-aware protocols like RedDSA. --- src/pasta/curves.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/pasta/curves.rs b/src/pasta/curves.rs index 006d693..fa06c2d 100644 --- a/src/pasta/curves.rs +++ b/src/pasta/curves.rs @@ -7,6 +7,7 @@ use core::iter::Sum; use core::ops::{Add, Mul, Neg, Sub}; use ff::Field; use group::{ + cofactor::CofactorGroup, prime::{PrimeCurve, PrimeCurveAffine, PrimeGroup}, Curve as _, Group as _, GroupEncoding, }; @@ -186,6 +187,25 @@ macro_rules! new_curve_impl { impl PrimeGroup for $name {} + impl CofactorGroup for $name { + type Subgroup = $name; + + fn clear_cofactor(&self) -> Self { + // This is a prime-order group, with a cofactor of 1. + *self + } + + fn into_subgroup(self) -> CtOption { + // Nothing to do here. + CtOption::new(self, 1.into()) + } + + fn is_torsion_free(&self) -> Choice { + // Shortcut: all points in a prime-order group are torsion free. + 1.into() + } + } + impl PrimeCurve for $name { type Affine = $name_affine; }