Skip to content

Commit 26119c2

Browse files
authored
elliptic-curve: require From<NonIdentity> for Projective/AffinePoint (#1849)
Equivalent of #1847 for `Projective/AffinePoint`. Companion PR to RustCrypto/elliptic-curves#1190.
1 parent ae58a77 commit 26119c2

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

elliptic-curve/src/arithmetic.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use crate::{
44
Curve, FieldBytes, PrimeCurve, ScalarPrimitive,
55
ops::{Invert, LinearCombination, Reduce, ShrAssign},
6-
point::AffineCoordinates,
6+
point::{AffineCoordinates, NonIdentity},
77
scalar::{FromUintUnchecked, IsHigh},
88
};
99
use core::fmt::Debug;
@@ -22,6 +22,7 @@ pub trait CurveArithmetic: Curve {
2222
+ Default
2323
+ DefaultIsZeroes
2424
+ Eq
25+
+ From<NonIdentity<Self::AffinePoint>>
2526
+ PartialEq
2627
+ Sized
2728
+ Send
@@ -43,6 +44,7 @@ pub trait CurveArithmetic: Curve {
4344
+ Default
4445
+ DefaultIsZeroes
4546
+ From<Self::AffinePoint>
47+
+ From<NonIdentity<Self::ProjectivePoint>>
4648
+ Into<Self::AffinePoint>
4749
+ LinearCombination<[(Self::ProjectivePoint, Self::Scalar)]>
4850
+ LinearCombination<[(Self::ProjectivePoint, Self::Scalar); 2]>

elliptic-curve/src/dev.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::{
99
bigint::{Limb, U256},
1010
error::{Error, Result},
1111
ops::{Invert, LinearCombination, Reduce, ShrAssign},
12-
point::AffineCoordinates,
12+
point::{AffineCoordinates, NonIdentity},
1313
rand_core::TryRngCore,
1414
scalar::{FromUintUnchecked, IsHigh},
1515
sec1::{CompressedPoint, FromEncodedPoint, ToEncodedPoint},
@@ -460,6 +460,12 @@ impl Default for AffinePoint {
460460

461461
impl DefaultIsZeroes for AffinePoint {}
462462

463+
impl From<NonIdentity<AffinePoint>> for AffinePoint {
464+
fn from(affine: NonIdentity<AffinePoint>) -> Self {
465+
affine.to_point()
466+
}
467+
}
468+
463469
impl FromEncodedPoint<MockCurve> for AffinePoint {
464470
fn from_encoded_point(encoded_point: &EncodedPoint) -> CtOption<Self> {
465471
let point = if encoded_point.is_identity() {
@@ -554,6 +560,12 @@ impl From<AffinePoint> for ProjectivePoint {
554560
}
555561
}
556562

563+
impl From<NonIdentity<ProjectivePoint>> for ProjectivePoint {
564+
fn from(point: NonIdentity<ProjectivePoint>) -> Self {
565+
point.to_point()
566+
}
567+
}
568+
557569
impl From<ProjectivePoint> for AffinePoint {
558570
fn from(point: ProjectivePoint) -> AffinePoint {
559571
group::Curve::to_affine(&point)

0 commit comments

Comments
 (0)