Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump elliptic-curve crate to v0.14.0-pre.2 #1011

Merged
merged 8 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
229 changes: 124 additions & 105 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ members = [

[profile.dev]
opt-level = 2

[patch.crates-io.ecdsa]
#git = "https://github.com/RustCrypto/signatures.git"
path = "../signatures/ecdsa"
17 changes: 8 additions & 9 deletions bign256/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bign256"
version = "0.13.1"
version = "0.14.0-pre"
description = """
Pure Rust implementation of the Bign P-256 (a.k.a. bign-curve256v1)
elliptic curve as defined in STB 34.101.45-2013, with
Expand All @@ -14,17 +14,16 @@ readme = "README.md"
categories = ["cryptography", "no-std"]
keywords = ["crypto", "ecc", "stb", "bign-curve256v1", "bignp256"]
edition = "2021"
rust-version = "1.65"
rust-version = "1.73"

[dependencies]
elliptic-curve = { version = "0.13.8", features = ["hazmat", "sec1"] }
elliptic-curve = { version = "=0.14.0-pre.1", features = ["hazmat", "sec1"] }

# optional dependencies
primeorder = { version = "0.13.5", optional = true, path = "../primeorder" }
signature = { version = "2", optional = true }
belt-hash = { version = "0.1.0", optional = true, default-features = false }
crypto-bigint = { version = "0.5.5", optional = true }
rfc6979 = { version = "0.4", optional = true }
primeorder = { version = "=0.14.0-pre", optional = true, path = "../primeorder" }
signature = { version = "=2.3.0-pre.1", optional = true }
belt-hash = { version = "=0.2.0-pre.1", optional = true, default-features = false }
rfc6979 = { version = "=0.5.0-pre.1", optional = true }

[dev-dependencies]
criterion = "0.5"
Expand All @@ -38,7 +37,7 @@ default = ["arithmetic", "pkcs8", "std", "dsa"]
alloc = ["elliptic-curve/alloc", "primeorder?/alloc"]
std = ["alloc", "elliptic-curve/std", "signature?/std"]

dsa = ["arithmetic", "dep:rfc6979", "dep:signature", "dep:belt-hash", "dep:crypto-bigint"]
dsa = ["arithmetic", "dep:rfc6979", "dep:signature", "dep:belt-hash"]
arithmetic = ["dep:primeorder", "elliptic-curve/arithmetic"]
pkcs8 = ["elliptic-curve/pkcs8"]

Expand Down
10 changes: 5 additions & 5 deletions bign256/src/arithmetic/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ impl Scalar {
/// Right shifts the scalar.
///
/// Note: not constant-time with respect to the `shift` parameter.
pub const fn shr_vartime(&self, shift: usize) -> Scalar {
Self(self.0.shr_vartime(shift))
pub const fn shr_vartime(&self, shift: u32) -> Scalar {
Self(self.0.wrapping_shr_vartime(shift))
}
}

Expand Down Expand Up @@ -154,7 +154,7 @@ impl Invert for Scalar {

impl IsHigh for Scalar {
fn is_high(&self) -> Choice {
const MODULUS_SHR1: U256 = BignP256::ORDER.shr_vartime(1);
const MODULUS_SHR1: U256 = BignP256::ORDER.wrapping_shr_vartime(1);
tarcieri marked this conversation as resolved.
Show resolved Hide resolved
self.to_canonical().ct_gt(&MODULUS_SHR1)
}
}
Expand All @@ -163,15 +163,15 @@ impl Shr<usize> for Scalar {
type Output = Self;

fn shr(self, rhs: usize) -> Self::Output {
self.shr_vartime(rhs)
self.shr_vartime(rhs as u32)
}
}

impl Shr<usize> for &Scalar {
type Output = Scalar;

fn shr(self, rhs: usize) -> Self::Output {
self.shr_vartime(rhs)
self.shr_vartime(rhs as u32)
}
}

Expand Down
8 changes: 4 additions & 4 deletions bign256/src/dsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ pub use self::{signing::SigningKey, verifying::VerifyingKey};

use crate::{BignP256, FieldBytes, NonZeroScalar, Scalar};
use core::fmt::{self, Debug};
use crypto_bigint::{
use elliptic_curve::{
array::Array,
consts::{U32, U48},
generic_array::GenericArray,
};
use signature::{Error, Result, SignatureEncoding};

Expand Down Expand Up @@ -76,7 +76,7 @@ impl Signature {
/// Parse an BignP256 signature from a byte array.
pub fn from_bytes(bytes: &SignatureBytes) -> Result<Self> {
let (s0, s1) = bytes.split_at(Self::BYTE_SIZE / 3);
let mut s0_bytes: GenericArray<u8, U32> = Default::default();
let mut s0_bytes: Array<u8, U32> = Default::default();
s0_bytes[..16].copy_from_slice(s0);

let s0 = ScalarPrimitive::from_slice(&s0_bytes).map_err(|_| Error::new())?;
Expand Down Expand Up @@ -106,7 +106,7 @@ impl Signature {
s0.reverse();
s1.reverse();

let mut s: GenericArray<u8, U48> = Default::default();
let mut s: Array<u8, U48> = Default::default();
s[..Self::BYTE_SIZE / 3].copy_from_slice(s0);
s[Self::BYTE_SIZE / 3..Self::BYTE_SIZE].copy_from_slice(&s1);

Expand Down
10 changes: 4 additions & 6 deletions bign256/src/dsa/signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,17 @@

use super::{Signature, VerifyingKey, BELT_OID};
use crate::{BignP256, FieldBytes, NonZeroScalar, ProjectivePoint, PublicKey, Scalar, SecretKey};
use belt_hash::{BeltHash, Digest};
use core::fmt::{self, Debug};
use elliptic_curve::{
generic_array::typenum::Unsigned,
array::{consts::U32, typenum::Unsigned, Array},
ops::{MulByGenerator, Reduce},
point::AffineCoordinates,
subtle::{Choice, ConstantTimeEq},
Curve, Field, FieldBytesEncoding, PrimeField,
};
use signature::{hazmat::PrehashSigner, Error, KeypairRef, Result, Signer};

use belt_hash::{BeltHash, Digest};
use crypto_bigint::{consts::U32, generic_array::GenericArray};

/// BignP256 secret key used for signing messages and producing signatures.
///
/// ## Usage
Expand Down Expand Up @@ -107,7 +105,7 @@ impl PrehashSigner<Signature> for SigningKey {
if prehash.len() != <BignP256 as Curve>::FieldBytesSize::USIZE {
return Err(Error::new());
}
let mut h_word: GenericArray<u8, U32> = GenericArray::clone_from_slice(prehash);
let mut h_word: Array<u8, U32> = Array::clone_from_slice(prehash);
h_word.reverse();

let h = Scalar::reduce_bytes(&h_word);
Expand All @@ -122,7 +120,7 @@ impl PrehashSigner<Signature> for SigningKey {
.unwrap();

// 3. Set 𝑅 ← 𝑘𝐺.
let mut R: GenericArray<u8, _> = ProjectivePoint::mul_by_generator(&k).to_affine().x();
let mut R: Array<u8, _> = ProjectivePoint::mul_by_generator(&k).to_affine().x();
R.reverse();

// 4. Set 𝑆0 ← ⟨︀belt-hash(OID(ℎ) ‖ ⟨𝑅⟩2𝑙 ‖ 𝐻)⟩︀_𝑙.
Expand Down
5 changes: 2 additions & 3 deletions bign256/src/dsa/verifying.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ use belt_hash::{
digest::{Digest, FixedOutput},
BeltHash,
};
use crypto_bigint::{consts::U32, generic_array::GenericArray};
use elliptic_curve::{
generic_array::typenum::Unsigned,
array::{consts::U32, typenum::Unsigned, Array},
group::GroupEncoding,
ops::{LinearCombination, Reduce},
sec1::ToEncodedPoint,
Expand Down Expand Up @@ -122,7 +121,7 @@ impl PrehashVerifier<Signature> for VerifyingKey {
// 3. If 𝑆1 ⩾ 𝑞, return NO.
let s1 = signature.s1();

let mut hash: GenericArray<u8, U32> = GenericArray::clone_from_slice(prehash);
let mut hash: Array<u8, U32> = Array::clone_from_slice(prehash);
hash.reverse();

let hw = Scalar::reduce_bytes(FieldBytes::from_slice(&hash));
Expand Down
4 changes: 2 additions & 2 deletions bign256/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ pub use arithmetic::{scalar::Scalar, AffinePoint, ProjectivePoint};
pub use elliptic_curve::pkcs8;

use elliptic_curve::{
array::Array,
bigint::ArrayEncoding,
consts::{U32, U33},
generic_array::GenericArray,
FieldBytesEncoding,
};

Expand Down Expand Up @@ -107,7 +107,7 @@ impl pkcs8::AssociatedOid for BignP256 {
}

/// Compressed SEC1-encoded BIGN P256 curve point.
pub type CompressedPoint = GenericArray<u8, U33>;
pub type CompressedPoint = Array<u8, U33>;

/// BIGN P-256 field element serialized as bytes.
///
Expand Down
12 changes: 6 additions & 6 deletions bp256/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bp256"
version = "0.6.1"
version = "0.7.0-pre"
description = "Brainpool P-256 (brainpoolP256r1 and brainpoolP256t1) elliptic curves"
authors = ["RustCrypto Developers"]
license = "Apache-2.0 OR MIT"
Expand All @@ -10,15 +10,15 @@ readme = "README.md"
categories = ["cryptography", "no-std"]
keywords = ["brainpool", "crypto", "ecc"]
edition = "2021"
rust-version = "1.65"
rust-version = "1.73"

[dependencies]
elliptic-curve = { version = "0.13", default-features = false, features = ["hazmat", "sec1"] }
elliptic-curve = { version = "=0.14.0-pre.1", default-features = false, features = ["hazmat", "sec1"] }

# optional dependencies
ecdsa = { version = "0.16", optional = true, default-features = false, features = ["der"] }
primeorder = { version = "0.13.5", optional = true, path = "../primeorder" }
sha2 = { version = "0.10", optional = true, default-features = false }
ecdsa = { version = "=0.17.0-pre.1", optional = true, default-features = false, features = ["der"] }
primeorder = { version = "=0.14.0-pre", optional = true, path = "../primeorder" }
sha2 = { version = "=0.11.0-pre.1", optional = true, default-features = false }

[features]
default = ["pkcs8", "std"]
Expand Down
10 changes: 5 additions & 5 deletions bp256/src/arithmetic/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ impl Scalar {
/// Right shifts the scalar.
///
/// Note: not constant-time with respect to the `shift` parameter.
pub const fn shr_vartime(&self, shift: usize) -> Scalar {
Self(self.0.shr_vartime(shift))
pub const fn shr_vartime(&self, shift: u32) -> Scalar {
Self(self.0.wrapping_shr_vartime(shift))
}

/// Compute modular square.
Expand Down Expand Up @@ -296,7 +296,7 @@ impl Invert for Scalar {

impl IsHigh for Scalar {
fn is_high(&self) -> Choice {
const MODULUS_SHR1: U256 = ORDER.shr_vartime(1);
const MODULUS_SHR1: U256 = ORDER.wrapping_shr_vartime(1);
self.to_canonical().ct_gt(&MODULUS_SHR1)
}
}
Expand All @@ -305,15 +305,15 @@ impl Shr<usize> for Scalar {
type Output = Self;

fn shr(self, rhs: usize) -> Self::Output {
self.shr_vartime(rhs)
self.shr_vartime(rhs as u32)
}
}

impl Shr<usize> for &Scalar {
type Output = Scalar;

fn shr(self, rhs: usize) -> Self::Output {
self.shr_vartime(rhs)
self.shr_vartime(rhs as u32)
}
}

Expand Down
4 changes: 2 additions & 2 deletions bp256/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ pub use crate::arithmetic::scalar::Scalar;
#[cfg(feature = "pkcs8")]
pub use elliptic_curve::pkcs8;

use elliptic_curve::generic_array::{typenum::U32, GenericArray};
use elliptic_curve::array::{typenum::U32, Array};

#[cfg(feature = "wip-arithmetic-do-not-use")]
pub(crate) use crate::arithmetic::field::FieldElement;

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

const ORDER_HEX: &str = "a9fb57dba1eea9bc3e660a909d838d718c397aa3b561a6f7901e0e82974856a7";
const ORDER: U256 = U256::from_be_hex(ORDER_HEX);
12 changes: 6 additions & 6 deletions bp384/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bp384"
version = "0.6.1"
version = "0.7.0-pre"
description = "Brainpool P-384 (brainpoolP384r1 and brainpoolP384t1) elliptic curves"
authors = ["RustCrypto Developers"]
license = "Apache-2.0 OR MIT"
Expand All @@ -10,15 +10,15 @@ readme = "README.md"
categories = ["cryptography", "no-std"]
keywords = ["brainpool", "crypto", "ecc"]
edition = "2021"
rust-version = "1.65"
rust-version = "1.73"

[dependencies]
elliptic-curve = { version = "0.13", default-features = false, features = ["hazmat", "sec1"] }
elliptic-curve = { version = "=0.14.0-pre.1", default-features = false, features = ["hazmat", "sec1"] }

# optional dependencies
ecdsa = { version = "0.16", optional = true, default-features = false, features = ["der"] }
primeorder = { version = "0.13.5", optional = true, path = "../primeorder" }
sha2 = { version = "0.10", optional = true, default-features = false }
ecdsa = { version = "=0.17.0-pre.1", optional = true, default-features = false, features = ["der"] }
primeorder = { version = "=0.14.0-pre", optional = true, path = "../primeorder" }
sha2 = { version = "=0.11.0-pre.1", optional = true, default-features = false }

[features]
default = ["pkcs8", "std"]
Expand Down
10 changes: 5 additions & 5 deletions bp384/src/arithmetic/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ impl Scalar {
/// Right shifts the scalar.
///
/// Note: not constant-time with respect to the `shift` parameter.
pub const fn shr_vartime(&self, shift: usize) -> Scalar {
Self(self.0.shr_vartime(shift))
pub const fn shr_vartime(&self, shift: u32) -> Scalar {
Self(self.0.wrapping_shr_vartime(shift))
}

/// Compute modular square.
Expand Down Expand Up @@ -303,7 +303,7 @@ impl Invert for Scalar {

impl IsHigh for Scalar {
fn is_high(&self) -> Choice {
const MODULUS_SHR1: U384 = ORDER.shr_vartime(1);
const MODULUS_SHR1: U384 = ORDER.wrapping_shr_vartime(1);
self.to_canonical().ct_gt(&MODULUS_SHR1)
}
}
Expand All @@ -312,15 +312,15 @@ impl Shr<usize> for Scalar {
type Output = Self;

fn shr(self, rhs: usize) -> Self::Output {
self.shr_vartime(rhs)
self.shr_vartime(rhs as u32)
}
}

impl Shr<usize> for &Scalar {
type Output = Scalar;

fn shr(self, rhs: usize) -> Self::Output {
self.shr_vartime(rhs)
self.shr_vartime(rhs as u32)
}
}

Expand Down
4 changes: 2 additions & 2 deletions bp384/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ pub use crate::arithmetic::scalar::Scalar;
#[cfg(feature = "pkcs8")]
pub use elliptic_curve::pkcs8;

use elliptic_curve::generic_array::{typenum::U48, GenericArray};
use elliptic_curve::array::{typenum::U48, Array};

#[cfg(feature = "wip-arithmetic-do-not-use")]
pub(crate) use crate::arithmetic::field::FieldElement;

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

const ORDER_HEX: &str = "8cb91e82a3386d280f5d6f7e50e641df152f7109ed5456b31f166e6cac0425a7cf3ab6af6b7fc3103b883202e9046565";
const ORDER: U384 = U384::from_be_hex(ORDER_HEX);
Loading
Loading