Skip to content

Commit

Permalink
[WIP] elliptic-curve: migrate to hybrid-array; MSRV 1.71
Browse files Browse the repository at this point in the history
  • Loading branch information
tarcieri committed Jan 9, 2024
1 parent fd48936 commit a9ab8b6
Show file tree
Hide file tree
Showing 18 changed files with 186 additions and 86 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/elliptic-curve.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
strategy:
matrix:
rust:
- 1.65.0 # MSRV
- 1.71.0 # MSRV
- stable
target:
- thumbv7em-none-eabi
Expand Down Expand Up @@ -74,7 +74,7 @@ jobs:
strategy:
matrix:
rust:
- 1.65.0 # MSRV
- 1.71.0 # MSRV
- stable
- nightly
steps:
Expand Down
130 changes: 116 additions & 14 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ members = [
"signature_derive",
"universal-hash",
]

[patch.crates-io]
hkdf = { git = "https://github.com/RustCrypto/KDFs.git", branch = "hkdf/hmac-v0.13.0-pre" }
hmac = { git = "https://github.com/RustCrypto/MACs.git", branch = "hmac/digest-v0.11.0-pre.3" }
2 changes: 1 addition & 1 deletion crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ crypto-common = { version = "0.1", default-features = false }
aead = { version = "0.5", optional = true }
cipher = { version = "0.4", optional = true }
digest = { version = "0.10", optional = true, features = ["mac"] }
elliptic-curve = { version = "0.13", optional = true, path = "../elliptic-curve" }
elliptic-curve = { version = "0.13", optional = true }
password-hash = { version = "0.5", optional = true }
signature = { version = "2", optional = true, default-features = false }
universal-hash = { version = "0.5", optional = true }
Expand Down
22 changes: 11 additions & 11 deletions elliptic-curve/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "elliptic-curve"
version = "0.13.8"
version = "0.14.0-pre"
description = """
General purpose Elliptic Curve Cryptography (ECC) support, including types
and traits for representing various elliptic curve forms, scalars, points,
Expand All @@ -13,34 +13,34 @@ readme = "README.md"
categories = ["cryptography", "no-std"]
keywords = ["crypto", "ecc", "elliptic", "weierstrass"]
edition = "2021"
rust-version = "1.65"
rust-version = "1.71"

[dependencies]
base16ct = "0.2"
crypto-bigint = { version = "0.5", default-features = false, features = ["rand_core", "generic-array", "zeroize"] }
generic-array = { version = "0.14.6", default-features = false, features = ["zeroize"] }
hybrid-array = { version = "=0.2.0-pre.8", default-features = false, features = ["zeroize"] }
rand_core = { version = "0.6.4", default-features = false }
subtle = { version = "2", default-features = false }
zeroize = { version = "1.7", default-features = false }

# optional dependencies
base64ct = { version = "1", optional = true, default-features = false, features = ["alloc"] }
digest = { version = "0.10", optional = true }
digest = { version = "=0.11.0-pre.3", optional = true }
ff = { version = "0.13", optional = true, default-features = false }
group = { version = "0.13", optional = true, default-features = false }
hkdf = { version = "0.12.4", optional = true, default-features = false }
hkdf = { version = "=0.13.0-pre", optional = true, default-features = false }
hex-literal = { version = "0.4", optional = true }
pem-rfc7468 = { version = "0.7", optional = true, features = ["alloc"] }
pkcs8 = { version = "0.10.2", optional = true, default-features = false }
sec1 = { version = "0.7.1", optional = true, features = ["subtle", "zeroize"] }
serdect = { version = "0.2", optional = true, default-features = false, features = ["alloc"] }
pem-rfc7468 = { version = "=1.0.0-pre.0", optional = true, features = ["alloc"] }
pkcs8 = { version = "=0.11.0-pre.0", optional = true, default-features = false }
sec1 = { version = "=0.8.0-pre.0", optional = true, features = ["subtle", "zeroize"] }
serdect = { version = "=0.3.0-pre.0", optional = true, default-features = false, features = ["alloc"] }
serde_json = { version = "1.0.47", optional = true, default-features = false, features = ["alloc"] }
tap = { version = "1.0.1", optional = true, default-features = false } # hack for minimal-versions support for `bits`

[dev-dependencies]
hex-literal = "0.4"
sha2 = "0.10"
sha3 = "0.10"
sha2 = "=0.11.0-pre.0"
sha3 = "=0.11.0-pre.0"

[features]
default = ["arithmetic"]
Expand Down
4 changes: 2 additions & 2 deletions elliptic-curve/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ and public/secret keys composed thereof.

## Minimum Supported Rust Version

Requires Rust **1.65** or higher.
Requires Rust **1.71** or higher.

Minimum supported Rust version can be changed in the future, but it will be
done with a minor version bump.
Expand Down Expand Up @@ -49,6 +49,6 @@ dual licensed as above, without any additional terms or conditions.
[build-image]: https://github.com/RustCrypto/traits/actions/workflows/elliptic-curve.yml/badge.svg
[build-link]: https://github.com/RustCrypto/traits/actions/workflows/elliptic-curve.yml
[license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg
[rustc-image]: https://img.shields.io/badge/rustc-1.65+-blue.svg
[rustc-image]: https://img.shields.io/badge/rustc-1.71+-blue.svg
[chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg
[chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260040-elliptic-curves
2 changes: 1 addition & 1 deletion elliptic-curve/src/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use crate::{
bigint::{Limb, U256},
error::{Error, Result},
generic_array::typenum::U32,
hybrid_array::typenum::U32,
ops::{Invert, LinearCombination, MulByGenerator, Reduce, ShrAssign},
pkcs8,
point::AffineCoordinates,
Expand Down
4 changes: 2 additions & 2 deletions elliptic-curve/src/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ use crate::{
bigint::{ArrayEncoding, ByteArray, Integer},
Curve,
};
use generic_array::{typenum::Unsigned, GenericArray};
use hybrid_array::{typenum::Unsigned, Array};

/// Size of serialized field elements of this elliptic curve.
pub type FieldBytesSize<C> = <C as Curve>::FieldBytesSize;

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

/// Trait for decoding/encoding `Curve::Uint` from/to [`FieldBytes`] using
/// curve-specific rules.
Expand Down
8 changes: 4 additions & 4 deletions elliptic-curve/src/hash2curve/hash2field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ mod expand_msg;
pub use expand_msg::{xmd::*, xof::*, *};

use crate::{Error, Result};
use generic_array::{typenum::Unsigned, ArrayLength, GenericArray};
use hybrid_array::{typenum::Unsigned, Array, ArraySize};

/// The trait for helping to convert to a field element.
pub trait FromOkm {
/// The number of bytes needed to convert to a field element.
type Length: ArrayLength<u8>;
type Length: ArraySize;

/// Convert a byte sequence into a field element.
fn from_okm(data: &GenericArray<u8, Self::Length>) -> Self;
fn from_okm(data: &Array<u8, Self::Length>) -> Self;
}

/// Convert an arbitrary byte sequence into a field element.
Expand All @@ -38,7 +38,7 @@ where
T: FromOkm + Default,
{
let len_in_bytes = T::Length::to_usize().checked_mul(out.len()).ok_or(Error)?;
let mut tmp = GenericArray::<u8, <T as FromOkm>::Length>::default();
let mut tmp = Array::<u8, <T as FromOkm>::Length>::default();
let mut expander = E::expand_message(data, domain, len_in_bytes)?;
for o in out.iter_mut() {
expander.fill_bytes(&mut tmp);
Expand Down
Loading

0 comments on commit a9ab8b6

Please sign in to comment.