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
8 changes: 3 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ primefield = { path = "primefield" }
primeorder = { path = "primeorder" }
wnaf = { path = "wnaf" }

crypto-bigint = { git = "https://github.com/RustCrypto/crypto-bigint" }
ecdsa = { git = "https://github.com/RustCrypto/signatures" }
elliptic-curve = { git = "https://github.com/RustCrypto/traits" }
5 changes: 3 additions & 2 deletions bignp256/src/ecdsa/signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ use crate::{BignP256, FieldBytes, NonZeroScalar, ProjectivePoint, PublicKey, Sca
use belt_hash::{BeltHash, Digest};
use core::fmt::{self, Debug};
use elliptic_curve::{
Curve, Field, FieldBytesEncoding, Generate, Group, PrimeField,
Curve, Field, Generate, Group, PrimeField,
array::{Array, sizes::U32, typenum::Unsigned},
field,
ops::Reduce,
point::AffineCoordinates,
subtle::{Choice, ConstantTimeEq},
Expand Down Expand Up @@ -116,7 +117,7 @@ impl PrehashSigner<Signature> for SigningKey {
// 2. Generate 𝑘 ← rand(1,..,𝑞-1)
let k = Scalar::from_repr(bign_genk::generate_k::<BeltHash, belt_block::BeltBlock, _>(
&self.secret_scalar.to_bytes(),
&FieldBytesEncoding::<BignP256>::encode_field_bytes(BignP256::ORDER.as_ref()),
&field::uint_to_bytes::<BignP256>(&BignP256::ORDER),
&h.to_bytes(),
&[],
))
Expand Down
17 changes: 2 additions & 15 deletions bignp256/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@
extern crate alloc;

pub use elliptic_curve::{self, bigint::U256};
use elliptic_curve::{
Error, FieldBytesEncoding,
bigint::{ArrayEncoding, Odd},
consts::U32,
};
use elliptic_curve::{ByteOrder, Error, bigint::Odd, consts::U32};

#[cfg(feature = "arithmetic")]
pub use {
Expand Down Expand Up @@ -100,6 +96,7 @@ impl elliptic_curve::Curve for BignP256 {

/// Order of BIGN P-256's elliptic curve group (i.e. scalar modulus).
const ORDER: Odd<U256> = Odd::<U256>::from_be_hex(ORDER_HEX);
const FIELD_ENDIANNESS: ByteOrder = ByteOrder::LittleEndian;
}

impl elliptic_curve::PrimeCurve for BignP256 {}
Expand Down Expand Up @@ -128,16 +125,6 @@ pub type FieldBytes = elliptic_curve::FieldBytes<BignP256>;
/// SEC1 encoded point.
pub type Sec1Point = elliptic_curve::sec1::Sec1Point<BignP256>;

impl FieldBytesEncoding<BignP256> for U256 {
fn decode_field_bytes(field_bytes: &FieldBytes) -> Self {
U256::from_le_byte_array(*field_bytes)
}

fn encode_field_bytes(&self) -> FieldBytes {
self.to_le_byte_array()
}
}

/// Non-zero scalar field element.
#[cfg(feature = "arithmetic")]
pub type NonZeroScalar = elliptic_curve::NonZeroScalar<BignP256>;
Expand Down
10 changes: 1 addition & 9 deletions bp256/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,11 @@ pub(crate) use crate::arithmetic::field::FieldElement;

use elliptic_curve::{
array::{Array, typenum::U32},
bigint::{ArrayEncoding, Odd},
bigint::Odd,
};

/// Byte representation of a base/scalar field element of a given curve.
pub type FieldBytes = Array<u8, U32>;

const ORDER_HEX: &str = "a9fb57dba1eea9bc3e660a909d838d718c397aa3b561a6f7901e0e82974856a7";
const ORDER: Odd<U256> = Odd::<U256>::from_be_hex(ORDER_HEX);

fn decode_field_bytes(field_bytes: &FieldBytes) -> U256 {
U256::from_be_byte_array(*field_bytes)
}

fn encode_field_bytes(uint: &U256) -> FieldBytes {
uint.to_be_byte_array()
}
11 changes: 0 additions & 11 deletions bp256/src/r1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ pub use {

use crate::ORDER;
use elliptic_curve::{
FieldBytesEncoding,
bigint::{Odd, U256},
consts::U32,
};
Expand Down Expand Up @@ -57,16 +56,6 @@ pub type Sec1Point = elliptic_curve::sec1::Sec1Point<BrainpoolP256r1>;
/// Byte array containing a serialized field element value (base field or scalar).
pub type FieldBytes = elliptic_curve::FieldBytes<BrainpoolP256r1>;

impl FieldBytesEncoding<BrainpoolP256r1> for U256 {
fn decode_field_bytes(field_bytes: &FieldBytes) -> Self {
crate::decode_field_bytes(field_bytes)
}

fn encode_field_bytes(&self) -> FieldBytes {
crate::encode_field_bytes(self)
}
}

/// brainpoolP256r1 secret key.
pub type SecretKey = elliptic_curve::SecretKey<BrainpoolP256r1>;

Expand Down
11 changes: 0 additions & 11 deletions bp256/src/t1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ pub use {

use crate::ORDER;
use elliptic_curve::{
FieldBytesEncoding,
bigint::{Odd, U256},
consts::U32,
};
Expand Down Expand Up @@ -57,16 +56,6 @@ pub type Sec1Point = elliptic_curve::sec1::Sec1Point<BrainpoolP256t1>;
/// Byte array containing a serialized field element value (base field or scalar).
pub type FieldBytes = elliptic_curve::FieldBytes<BrainpoolP256t1>;

impl FieldBytesEncoding<BrainpoolP256t1> for U256 {
fn decode_field_bytes(field_bytes: &crate::r1::FieldBytes) -> Self {
crate::decode_field_bytes(field_bytes)
}

fn encode_field_bytes(&self) -> crate::r1::FieldBytes {
crate::encode_field_bytes(self)
}
}

/// brainpoolP256t1 secret key.
pub type SecretKey = elliptic_curve::SecretKey<BrainpoolP256t1>;

Expand Down
8 changes: 0 additions & 8 deletions bp384/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,3 @@ pub type FieldBytes = Array<u8, U48>;

const ORDER_HEX: &str = "8cb91e82a3386d280f5d6f7e50e641df152f7109ed5456b31f166e6cac0425a7cf3ab6af6b7fc3103b883202e9046565";
const ORDER: Odd<U384> = Odd::<U384>::from_be_hex(ORDER_HEX);

fn decode_field_bytes(field_bytes: &FieldBytes) -> U384 {
U384::from_be_byte_array(*field_bytes)
}

fn encode_field_bytes(uint: &U384) -> FieldBytes {
uint.to_be_byte_array()
}
11 changes: 0 additions & 11 deletions bp384/src/r1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ pub use {

use crate::ORDER;
use elliptic_curve::{
FieldBytesEncoding,
bigint::{Odd, U384},
consts::U48,
};
Expand Down Expand Up @@ -57,16 +56,6 @@ pub type Sec1Point = elliptic_curve::sec1::Sec1Point<BrainpoolP384r1>;
/// Byte array containing a serialized field element value (base field or scalar).
pub type FieldBytes = elliptic_curve::FieldBytes<BrainpoolP384r1>;

impl FieldBytesEncoding<BrainpoolP384r1> for U384 {
fn decode_field_bytes(field_bytes: &FieldBytes) -> Self {
crate::decode_field_bytes(field_bytes)
}

fn encode_field_bytes(&self) -> FieldBytes {
crate::encode_field_bytes(self)
}
}

/// brainpoolP384r1 secret key.
pub type SecretKey = elliptic_curve::SecretKey<BrainpoolP384r1>;

Expand Down
11 changes: 0 additions & 11 deletions bp384/src/t1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ pub use {

use crate::ORDER;
use elliptic_curve::{
FieldBytesEncoding,
bigint::{Odd, U384},
consts::U48,
};
Expand Down Expand Up @@ -57,16 +56,6 @@ pub type Sec1Point = elliptic_curve::sec1::Sec1Point<BrainpoolP384t1>;
/// Byte array containing a serialized field element value (base field or scalar).
pub type FieldBytes = elliptic_curve::FieldBytes<BrainpoolP384t1>;

impl FieldBytesEncoding<BrainpoolP384t1> for U384 {
fn decode_field_bytes(field_bytes: &FieldBytes) -> Self {
crate::decode_field_bytes(field_bytes)
}

fn encode_field_bytes(&self) -> FieldBytes {
crate::encode_field_bytes(self)
}
}

/// brainpoolP384t1 secret key.
pub type SecretKey = elliptic_curve::SecretKey<BrainpoolP384t1>;

Expand Down
27 changes: 2 additions & 25 deletions ed448-goldilocks/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub use montgomery::{MontgomeryPoint, ProjectiveMontgomeryPoint};
pub use sign::*;

use elliptic_curve::{
Curve, FieldBytesEncoding, PrimeCurve,
ByteOrder, Curve, PrimeCurve,
array::typenum::{U56, U57},
bigint::{ArrayEncoding, Odd, U448},
point::PointCompression,
Expand All @@ -105,6 +105,7 @@ impl Curve for Ed448 {
type Uint = U448;

const ORDER: Odd<U448> = ORDER;
const FIELD_ENDIANNESS: ByteOrder = ByteOrder::LittleEndian;
}

impl PrimeCurve for Ed448 {}
Expand All @@ -113,18 +114,6 @@ impl PointCompression for Ed448 {
const COMPRESS_POINTS: bool = true;
}

impl FieldBytesEncoding<Ed448> for U448 {
fn decode_field_bytes(field_bytes: &Ed448FieldBytes) -> Self {
U448::from_le_slice(field_bytes)
}

fn encode_field_bytes(&self) -> Ed448FieldBytes {
let mut data = Ed448FieldBytes::default();
data.copy_from_slice(&self.to_le_byte_array()[..]);
data
}
}

impl elliptic_curve::CurveArithmetic for Ed448 {
type AffinePoint = AffinePoint;
type ProjectivePoint = EdwardsPoint;
Expand Down Expand Up @@ -161,18 +150,6 @@ impl PointCompression for Decaf448 {
const COMPRESS_POINTS: bool = true;
}

impl FieldBytesEncoding<Decaf448> for U448 {
fn decode_field_bytes(field_bytes: &Decaf448FieldBytes) -> Self {
U448::from_le_slice(field_bytes)
}

fn encode_field_bytes(&self) -> Decaf448FieldBytes {
let mut data = Decaf448FieldBytes::default();
data.copy_from_slice(&self.to_le_byte_array()[..]);
data
}
}

impl elliptic_curve::CurveArithmetic for Decaf448 {
type AffinePoint = DecafAffinePoint;
type ProjectivePoint = DecafPoint;
Expand Down
13 changes: 1 addition & 12 deletions k256/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,8 @@ pub use elliptic_curve::pkcs8;
pub use sha2;

use elliptic_curve::{
FieldBytesEncoding,
array::Array,
bigint::{ArrayEncoding, Odd},
bigint::Odd,
consts::{U32, U33, U64},
};

Expand Down Expand Up @@ -127,16 +126,6 @@ pub type Sec1Point = elliptic_curve::sec1::Sec1Point<Secp256k1>;
/// Byte array containing a serialized field element value (base field or scalar).
pub type FieldBytes = elliptic_curve::FieldBytes<Secp256k1>;

impl FieldBytesEncoding<Secp256k1> for U256 {
fn decode_field_bytes(field_bytes: &FieldBytes) -> Self {
U256::from_be_byte_array(*field_bytes)
}

fn encode_field_bytes(&self) -> FieldBytes {
self.to_be_byte_array()
}
}

/// Bytes used by a wide reduction: twice the width of [`FieldBytes`].
pub type WideBytes = Array<u8, U64>;

Expand Down
13 changes: 1 addition & 12 deletions p192/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ pub use arithmetic::{AffinePoint, ProjectivePoint, scalar::Scalar};
pub use elliptic_curve::pkcs8;

use elliptic_curve::{
FieldBytesEncoding,
array::Array,
bigint::{ArrayEncoding, Odd, U192},
bigint::{Odd, U192},
consts::{U24, U25},
};

Expand Down Expand Up @@ -80,16 +79,6 @@ pub type Sec1Point = elliptic_curve::sec1::Sec1Point<NistP192>;
/// scalar).
pub type FieldBytes = elliptic_curve::FieldBytes<NistP192>;

impl FieldBytesEncoding<NistP192> for U192 {
fn decode_field_bytes(field_bytes: &FieldBytes) -> Self {
U192::from_be_byte_array(*field_bytes)
}

fn encode_field_bytes(&self) -> FieldBytes {
self.to_be_byte_array()
}
}

/// Non-zero NIST P-192 scalar field element.
#[cfg(feature = "arithmetic")]
pub type NonZeroScalar = elliptic_curve::NonZeroScalar<NistP192>;
Expand Down
6 changes: 3 additions & 3 deletions p224/src/arithmetic/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
//! Apache License (Version 2.0), and the BSD 1-Clause License;
//! users may pick which license to apply.

use crate::{FieldBytes, FieldBytesEncoding, NistP224, ORDER_HEX, Uint};
use crate::{FieldBytes, NistP224, ORDER_HEX, Uint};
use elliptic_curve::{
Curve as _,
bigint::{Limb, cpubits},
ff::PrimeField,
field,
ops::Reduce,
scalar::{FromUintUnchecked, IsHigh},
subtle::{Choice, ConditionallySelectable, ConstantTimeEq, ConstantTimeGreater, CtOption},
Expand Down Expand Up @@ -137,8 +138,7 @@ impl Reduce<Uint> for Scalar {
impl Reduce<FieldBytes> for Scalar {
#[inline]
fn reduce(bytes: &FieldBytes) -> Self {
let w = <Uint as FieldBytesEncoding<NistP224>>::decode_field_bytes(bytes);
Self::reduce(&w)
Self::reduce(&field::bytes_to_uint::<NistP224>(bytes))
}
}

Expand Down
3 changes: 0 additions & 3 deletions p224/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ pub use arithmetic::{AffinePoint, ProjectivePoint, scalar::Scalar};
pub use elliptic_curve::pkcs8;

use elliptic_curve::{
FieldBytesEncoding,
array::Array,
bigint::{Odd, cpubits},
consts::{U28, U29},
Expand Down Expand Up @@ -98,8 +97,6 @@ pub type Sec1Point = elliptic_curve::sec1::Sec1Point<NistP224>;
/// scalar).
pub type FieldBytes = elliptic_curve::FieldBytes<NistP224>;

impl FieldBytesEncoding<NistP224> for Uint {}

/// Non-zero NIST P-256 scalar field element.
#[cfg(feature = "arithmetic")]
pub type NonZeroScalar = elliptic_curve::NonZeroScalar<NistP224>;
Expand Down
Loading
Loading