Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions elliptic-curve/src/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use crate::{
BatchNormalize, Curve, CurveArithmetic, CurveGroup, FieldBytesEncoding, PrimeCurve,
array::typenum::U32,
bigint::{Limb, NonZero, U256},
bigint::{Limb, Odd, U256},
error::{Error, Result},
ops::{Invert, LinearCombination, Reduce, ShrAssign},
point::{AffineCoordinates, NonIdentity},
Expand Down Expand Up @@ -70,7 +70,7 @@ impl Curve for MockCurve {
type FieldBytesSize = U32;
type Uint = U256;

const ORDER: NonZero<U256> = NonZero::<U256>::from_be_hex(
const ORDER: Odd<U256> = Odd::<U256>::from_be_hex(
"ffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551",
);
}
Expand Down
9 changes: 3 additions & 6 deletions elliptic-curve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ pub use {
#[cfg(feature = "pkcs8")]
pub use pkcs8;

use bigint::NonZero;
use bigint::Odd;
use core::{
fmt::Debug,
ops::{Add, ShrAssign},
Expand Down Expand Up @@ -174,11 +174,8 @@ pub trait Curve: 'static + Copy + Clone + Debug + Default + Eq + Ord + Send + Sy
+ FieldBytesEncoding<Self>
+ ShrAssign<usize>;

/// Order of this elliptic curve, i.e. number of elements in the scalar
/// field.
// TODO(tarcieri): make `Odd`? the prime order subgroup should always have an odd number of
// elements, even if there is a cofactor
const ORDER: NonZero<Self::Uint>;
/// Order of this curve's prime order subgroup, i.e. number of elements in the scalar field.
const ORDER: Odd<Self::Uint>;
}

/// Marker trait for elliptic curves with prime order.
Expand Down
12 changes: 6 additions & 6 deletions elliptic-curve/src/scalar/primitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use crate::{
Curve, Error, FieldBytes, FieldBytesEncoding, Result,
array::Array,
bigint::{Limb, NonZero, prelude::*},
bigint::{Limb, Odd, prelude::*},
scalar::FromUintUnchecked,
scalar::IsHigh,
};
Expand Down Expand Up @@ -62,12 +62,12 @@ where
};

/// Scalar modulus.
pub const MODULUS: NonZero<C::Uint> = C::ORDER;
pub const MODULUS: Odd<C::Uint> = C::ORDER;

/// Generate a random [`ScalarPrimitive`].
pub fn random<R: CryptoRng + ?Sized>(rng: &mut R) -> Self {
Self {
inner: C::Uint::random_mod(rng, &Self::MODULUS),
inner: C::Uint::random_mod(rng, Self::MODULUS.as_nz_ref()),
}
}

Expand Down Expand Up @@ -254,7 +254,7 @@ where

fn add(self, other: &Self) -> Self {
Self {
inner: self.inner.add_mod(&other.inner, &Self::MODULUS),
inner: self.inner.add_mod(&other.inner, Self::MODULUS.as_nz_ref()),
}
}
}
Expand Down Expand Up @@ -296,7 +296,7 @@ where

fn sub(self, other: &Self) -> Self {
Self {
inner: self.inner.sub_mod(&other.inner, &Self::MODULUS),
inner: self.inner.sub_mod(&other.inner, Self::MODULUS.as_nz_ref()),
}
}
}
Expand Down Expand Up @@ -327,7 +327,7 @@ where

fn neg(self) -> Self {
Self {
inner: self.inner.neg_mod(&Self::MODULUS),
inner: self.inner.neg_mod(Self::MODULUS.as_nz_ref()),
}
}
}
Expand Down