Skip to content

Commit 74f95a5

Browse files
authored
elliptic-curve: add Retrieve bound to scalar (#2169)
Provides a common API for retrieving the canonical representitive for a given field element
1 parent ea272ec commit 74f95a5

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

elliptic-curve/src/arithmetic.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crate::{
77
point::{AffineCoordinates, NonIdentity},
88
scalar::{FromUintUnchecked, IsHigh},
99
};
10+
use bigint::modular::Retrieve;
1011
use core::fmt::Debug;
1112
use subtle::{ConditionallySelectable, ConstantTimeEq, CtOption};
1213
use zeroize::DefaultIsZeroes;
@@ -89,6 +90,7 @@ pub trait CurveArithmetic: Curve {
8990
+ PartialOrd
9091
+ Reduce<Self::Uint>
9192
+ Reduce<FieldBytes<Self>>
93+
+ Retrieve<Output = Self::Uint>
9294
+ TryInto<NonZeroScalar<Self>, Error = Error>
9395
+ ff::Field
9496
+ ff::PrimeField<Repr = FieldBytes<Self>>;

elliptic-curve/src/dev.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use crate::{
77
BatchNormalize, Curve, CurveArithmetic, CurveGroup, FieldBytesEncoding, PrimeCurve,
88
array::typenum::U32,
9-
bigint::{Limb, Odd, U256},
9+
bigint::{Limb, Odd, U256, modular::Retrieve},
1010
ctutils,
1111
error::{Error, Result},
1212
ops::{Invert, LinearCombination, Reduce, ShrAssign},
@@ -385,6 +385,14 @@ impl Reduce<FieldBytes> for Scalar {
385385
}
386386
}
387387

388+
impl Retrieve for Scalar {
389+
type Output = U256;
390+
391+
fn retrieve(&self) -> U256 {
392+
self.0.to_uint()
393+
}
394+
}
395+
388396
impl FieldBytesEncoding<MockCurve> for U256 {}
389397

390398
impl From<u64> for Scalar {

0 commit comments

Comments
 (0)