Skip to content

Commit

Permalink
crypto: add feature flags to support no_std (#2394)
Browse files Browse the repository at this point in the history
* crypto: add feature flags to support no_std

* Update crypto/keys/src/ed25519.rs

Co-authored-by: Chris Beck <garbageslamb@gmail.com>

* Update crypto/platform/README.md

Co-authored-by: Chris Beck <garbageslamb@gmail.com>

* Update crypto/digestible/Cargo.toml

Co-authored-by: Chris Beck <garbageslamb@gmail.com>

* update lockfiles for new packages

* remove mc-crypto-platform features

* sort deps

* cargo fmt

* Apply suggestions from code review

Co-authored-by: Remoun Metyas <remoun.metyas@gmail.com>

* changes per review

* moarrr cleanup

* swap fingerprint display to hex with colons

* rename mc-crypto-{platform,dalek}

* fix lint

* gettin in fights with clippy

Co-authored-by: Chris Beck <garbageslamb@gmail.com>
Co-authored-by: Remoun Metyas <remoun.metyas@gmail.com>
  • Loading branch information
3 people authored Sep 1, 2022
1 parent 243271d commit 744fc55
Show file tree
Hide file tree
Showing 22 changed files with 517 additions and 173 deletions.
13 changes: 13 additions & 0 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions account-keys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ curve25519-dalek = { version = "4.0.0-pre.2", default-features = false, features

[dev-dependencies]
criterion = "0.3"
rand = "0.8"
rand_hc = "0.3"
tempdir = "0.3"

mc-test-vectors-account-keys = { path = "../test-vectors/account-keys" }
mc-util-test-helper = { path = "../util/test-helper" }
mc-util-test-vector = { path = "../util/test-vector" }
mc-util-test-with-data = { path = "../util/test-with-data" }
rand = "0.8"
rand_hc = "0.3"
tempdir = "0.3"

[[bench]]
name = "account_keys_benchmarks"
Expand Down
20 changes: 20 additions & 0 deletions consensus/enclave/trusted/Cargo.lock

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

28 changes: 28 additions & 0 deletions crypto/dalek/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[package]
name = "mc-crypto-dalek"
description = "MobileCoin Dalek Crypto Configurator Package"
version = "2.0.0"
authors = ["MobileCoin"]
edition = "2021"

[features]
serde = [ "curve25519-dalek/serde", "ed25519-dalek/serde" ]


# Use simd backend for x86_64 platforms with `avx` or `avx2` support
[target.'cfg(all(any(target_feature = "avx2", target_feature = "avx"), target_arch = "x86_64"))'.dependencies]
curve25519-dalek = { version = "4.0.0-pre.2", default-features = false, features = ["simd_backend", "nightly"] }
ed25519-dalek = { version = "2.0.0-pre.1", default-features = false, features = ["nightly", "simd_backend"] }
x25519-dalek = { version = "2.0.0-pre.2", default-features = false, features = ["nightly"] }

# Use u64 backend for x86_64 platforms without avx or avx2
[target.'cfg(all(not(any(target_feature = "avx2", target_feature = "avx")), target_arch = "x86_64"))'.dependencies]
curve25519-dalek = { version = "4.0.0-pre.2", default-features = false, features = ["nightly", "u64_backend"] }
ed25519-dalek = { version = "2.0.0-pre.1", default-features = false, features = ["nightly", "u64_backend"] }
x25519-dalek = { version = "2.0.0-pre.2", default-features = false, features = ["nightly"] }

# Otherwise let the platform folks make their own choices
[target.'cfg(not(target_arch = "x86_64"))'.dependencies]
curve25519-dalek = { version = "4.0.0-pre.2", default-features = false, features = ["nightly"] }
ed25519-dalek = { version = "2.0.0-pre.1", default-features = false, features = ["nightly"] }
x25519-dalek = { version = "2.0.0-pre.2", default-features = false, features = ["nightly"] }
3 changes: 3 additions & 0 deletions crypto/dalek/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# mc-crypto-dalek

A metapackage to configure dalek features based on the target platform (and feature flags)
15 changes: 15 additions & 0 deletions crypto/dalek/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) 2018-2022 The MobileCoin Foundation

//! Meta-package to select dalek features without replicating selection logic
//! -everywhere-

#![no_std]

/// Re-export of ed25519_dalek
pub use ed25519_dalek::{self as ed25519};

/// Re-export of curve25519_dalek
pub use curve25519_dalek::{self as curve25519};

/// Re-export of x25519_dalek
pub use x25519_dalek::{self as x25519};
6 changes: 1 addition & 5 deletions crypto/digestible/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ mc-crypto-digestible-derive = { path = "./derive", optional = true }
ed25519-dalek = { version = "2.0.0-pre.1", default-features = false, features = ["rand"], optional = true }
x25519-dalek = { version = "2.0.0-pre.2", default-features = false, optional = true }

[target.'cfg(any(target_feature = "avx2", target_feature = "avx"))'.dependencies]
curve25519-dalek = { version = "4.0.0-pre.2", default-features = false, features = ["simd_backend", "nightly"], optional = true }

[target.'cfg(not(any(target_feature = "avx2", target_feature = "avx")))'.dependencies]
curve25519-dalek = { version = "4.0.0-pre.2", default-features = false, features = ["nightly", "u64_backend"], optional = true }
curve25519-dalek = { version = "4.0.0-pre.2", default-features = false, features = ["nightly"], optional = true }

[features]
default = ["alloc", "derive", "dalek"]
Expand Down
8 changes: 7 additions & 1 deletion crypto/digestible/signature/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@ edition = "2021"
description = "Digestible Signatures"
readme = "README.md"

[features]
alloc = [ "mc-crypto-digestible/alloc" ]
dalek = [ "mc-crypto-digestible/dalek" ]
derive = [ "mc-crypto-digestible/derive" ]
default = [ "alloc", "derive", "dalek" ]

[dependencies]
mc-crypto-digestible = { path = ".." }
mc-crypto-digestible = { path = "..", default_features = false }

schnorrkel-og = { version = "0.11.0-pre.0", default-features = false }
signature = { version = "1.5.0", default-features = false }
5 changes: 4 additions & 1 deletion crypto/hashes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ version = "2.0.0"
authors = ["MobileCoin"]
edition = "2021"

[features]
default = [ "mc-crypto-digestible/default" ]

[dependencies]
mc-crypto-digestible = { path = "../digestible" }
mc-crypto-digestible = { path = "../digestible", default_features = false }

digest = { version = "0.10.1", default-features = false }

Expand Down
37 changes: 20 additions & 17 deletions crypto/keys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,43 @@ edition = "2021"
description = "MobileCoin Diffie-Hellman Key Exchange and Digital Signatures"
readme = "README.md"

[features]
alloc = ["base64/alloc", "ed25519-dalek/alloc", "ed25519-dalek/alloc", "mc-crypto-digestible/alloc", "mc-crypto-digestible-signature/alloc"]
serde = ["dep:serde", "ed25519/serde", "ed25519-dalek/serde", "ed25519-dalek/serde", "mc-util-repr-bytes/serde"]
prost = []
default = ["alloc", "serde", "prost", "mc-util-repr-bytes/default"]

[dependencies]
mc-crypto-digestible = { path = "../../crypto/digestible", features = ["dalek", "derive"] }
mc-crypto-digestible-signature = { path = "../../crypto/digestible/signature" }
mc-util-from-random = { path = "../../util/from-random" }
mc-util-repr-bytes = { path = "../../util/repr-bytes" }

base64 = { version = "0.13", default-features = false, features = ["alloc"] }
base64 = { version = "0.13", default-features = false }
curve25519-dalek = { version = "4.0.0-pre.2", default-features = false }
digest = "0.10"
displaydoc = { version = "0.2", default-features = false }
ed25519 = { version = "1.5", default-features = false, features = ["serde"] }
ed25519 = { version = "1.5", default-features = false }
ed25519-dalek = { version = "2.0.0-pre.1", default-features = false }
hex = { version = "0.4", default-features = false }
hex_fmt = "0.3"

mc-crypto-dalek = { path = "../../crypto/dalek" }
mc-crypto-digestible = { path = "../../crypto/digestible", default-features = false, features = ["dalek", "derive"] }
mc-crypto-digestible-signature = { path = "../../crypto/digestible/signature", default-features = false }
mc-util-from-random = { path = "../../util/from-random" }
mc-util-repr-bytes = { path = "../../util/repr-bytes", default-features = false }
rand_core = { version = "0.6", default-features = false }
rand_hc = "0.3"
schnorrkel-og = { version = "0.11.0-pre.0", default-features = false }
serde = { version = "1.0", default-features = false, features = ["alloc", "derive"] }
serde = { version = "1.0", optional = true, default-features = false, features = ["derive"] }
sha2 = { version = "0.10", default-features = false }
signature = { version = "1.4.0", default-features = false, features = ["digest-preview"] }
static_assertions = "1.1.0"
subtle = { version = "2", default-features = false }
x25519-dalek = { version = "2.0.0-pre.2", default-features = false, features = ["nightly", "u64_backend"] }
x25519-dalek = { version = "2.0.0-pre.2", default-features = false }
zeroize = { version = "1", default-features = false }

[target.'cfg(any(target_feature = "avx2", target_feature = "avx"))'.dependencies]
curve25519-dalek = { version = "4.0.0-pre.2", default-features = false, features = ["simd_backend", "nightly"] }
ed25519-dalek = { version = "2.0.0-pre.1", default-features = false, features = ["alloc", "nightly", "serde", "simd_backend"] }

[target.'cfg(not(any(target_feature = "avx2", target_feature = "avx")))'.dependencies]
curve25519-dalek = { version = "4.0.0-pre.2", default-features = false, features = ["nightly", "u64_backend"] }
ed25519-dalek = { version = "2.0.0-pre.1", default-features = false, features = ["alloc", "nightly", "serde", "u64_backend"] }

[dev-dependencies]
mc-crypto-hashes = { path = "../hashes" }
mc-util-serial = { path = "../../util/serial", features = ["std"] }
mc-util-test-helper = { path = "../../util/test-helper" }
mc-util-test-helper = { path = "../../util/test-helper", default-features = false }

pem = "1.1"
rand_hc = "0.3"
Expand Down
Loading

0 comments on commit 744fc55

Please sign in to comment.