Skip to content

Commit

Permalink
propagate mc-crypto-dalek backends, serde + prost feature flags (mobi…
Browse files Browse the repository at this point in the history
…lecoinfoundation#2785)

* continued propagatation of feature flags for no_std build support

relates to mc-crypto-dalek (backends), serde, prost.

* Apply (first portion of) suggestions from code review

Co-authored-by: Remoun Metyas <[email protected]>

* reorder dependencies

* apply cargo fmt

* drop superflous backend flag from x25519-dalek

Co-authored-by: Remoun Metyas <[email protected]>
  • Loading branch information
ryankurte and remoun authored Nov 8, 2022
1 parent f1ac658 commit d91aceb
Show file tree
Hide file tree
Showing 39 changed files with 412 additions and 210 deletions.
31 changes: 31 additions & 0 deletions Cargo.lock

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

32 changes: 17 additions & 15 deletions account-keys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,33 @@ authors = ["MobileCoin"]
edition = "2021"
readme = "README.md"

[features]
std = ["mc-util-repr-bytes/alloc"]
prost = ["dep:prost", "mc-util-repr-bytes/prost", "mc-crypto-keys/prost"]
serde = ["mc-crypto-keys/serde"]
default = ["std", "prost", "serde", "mc-util-serial", "mc-crypto-digestible/default", "mc-crypto-hashes/default", "mc-crypto-keys/default"]

[dependencies]

curve25519-dalek = { version = "4.0.0-pre.2", default-features = false, features = ["nightly"] }
# External dependencies
displaydoc = { version = "0.2", default-features = false }
hkdf = "0.12.3"
prost = { version = "0.11", default-features = false, features = ["prost-derive"] }
rand_core = { version = "0.6", default-features = false }
subtle = { version = "2", default-features = false }
zeroize = { version = "1", default-features = false }

# MobileCoin dependencies
mc-account-keys-types = { path = "types" }
mc-core = { path = "../core", default_features = false }
mc-crypto-digestible = { path = "../crypto/digestible" }
mc-crypto-hashes = { path = "../crypto/hashes" }
mc-crypto-keys = { path = "../crypto/keys", default-features = false, features = ["prost"] }
mc-crypto-digestible = { path = "../crypto/digestible", default_features = false }
mc-crypto-hashes = { path = "../crypto/hashes", default_features = false }
mc-crypto-keys = { path = "../crypto/keys", default-features = false }
mc-fog-sig-authority = { path = "../fog/sig/authority" }
mc-util-from-random = { path = "../util/from-random" }
mc-util-repr-bytes = { path = "../util/repr-bytes", default-features = false, features = ["alloc", "prost"] }
mc-util-serial = { path = "../util/serial" }

[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"] }

[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"] }
mc-util-repr-bytes = { path = "../util/repr-bytes", default-features = false }
mc-util-serial = { path = "../util/serial", optional = true }
prost = { version = "0.11", optional = true, default-features = false, features = ["prost-derive"] }
rand_core = { version = "0.6", default-features = false }
subtle = { version = "2", default-features = false }
zeroize = { version = "1", default-features = false }

[dev-dependencies]
criterion = "0.4"
Expand Down
35 changes: 20 additions & 15 deletions account-keys/src/account_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use mc_crypto_digestible::Digestible;
use mc_crypto_keys::{RistrettoPrivate, RistrettoPublic};
use mc_fog_sig_authority::{Signer as AuthoritySigner, Verifier as AuthorityVerifier};
use mc_util_from_random::FromRandom;
#[cfg(feature = "prost")]
use prost::Message;
use rand_core::{CryptoRng, RngCore};
use zeroize::Zeroize;
Expand All @@ -43,28 +44,29 @@ pub use mc_core::consts::{
INVALID_SUBADDRESS_INDEX,
};
/// A MobileCoin user's public subaddress.
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Message, Clone, Digestible)]
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Digestible)]
#[cfg_attr(feature = "prost", derive(Message))]
pub struct PublicAddress {
/// The user's public subaddress view key 'C'.
#[prost(message, required, tag = "1")]
#[cfg_attr(feature = "prost", prost(message, required, tag = "1"))]
view_public_key: RistrettoPublic,

/// The user's public subaddress spend key `D`.
#[prost(message, required, tag = "2")]
#[cfg_attr(feature = "prost", prost(message, required, tag = "2"))]
spend_public_key: RistrettoPublic,

/// This is the URL to talk to the fog report server.
/// Empty if no fog for this public address, should be parseable as
/// mc_util_uri::FogUri.
#[prost(string, tag = "3")]
#[cfg_attr(feature = "prost", prost(string, tag = "3"))]
#[digestible(never_omit)]
fog_report_url: String,

/// The fog report server potentially returns multiple reports when queried.
/// This id string indicates which of the reports to use.
///
/// Empty if no fog for this public address.
#[prost(string, tag = "4")]
#[cfg_attr(feature = "prost", prost(string, tag = "4"))]
#[digestible(never_omit)]
fog_report_id: String,

Expand All @@ -73,7 +75,7 @@ pub struct PublicAddress {
///
/// Empty if no fog for this public address, must be parseable as a
/// [`SchnorrkelSignature`].
#[prost(bytes, tag = "5")]
#[cfg_attr(feature = "prost", prost(bytes, tag = "5"))]
#[digestible(never_omit)]
fog_authority_sig: Vec<u8>,
}
Expand Down Expand Up @@ -224,29 +226,31 @@ impl FromRandom for PublicAddress {
/// Complete AccountKey, containing the pair of secret keys, which can be used
/// for spending, and optionally some fog-related info,
/// can be used for spending. This should only ever be present in client code.
#[derive(Clone, Message, Zeroize)]
#[derive(Clone, Zeroize)]
#[cfg_attr(feature = "prost", derive(Message))]
#[cfg_attr(not(feature = "prost"), derive(Debug))]
#[zeroize(drop)]
pub struct AccountKey {
/// Private key 'a' used for view-key matching.
#[prost(message, required, tag = "1")]
#[cfg_attr(feature = "prost", prost(message, required, tag = "1"))]
view_private_key: RistrettoPrivate,

/// Private key `b` used for spending.
#[prost(message, required, tag = "2")]
#[cfg_attr(feature = "prost", prost(message, required, tag = "2"))]
spend_private_key: RistrettoPrivate,

/// Fog Report server url (if user has Fog service), empty string otherwise
#[prost(string, tag = "3")]
#[cfg_attr(feature = "prost", prost(string, tag = "3"))]
fog_report_url: String,

/// Fog Report Key (if user has Fog service), empty otherwise
/// The key labelling the report to use, from among the several reports
/// which might be served by the fog report server.
#[prost(string, tag = "4")]
#[cfg_attr(feature = "prost", prost(string, tag = "4"))]
fog_report_id: String,

/// Fog Authority Key Fingerprint (if user has Fog service), empty otherwise
#[prost(bytes, tag = "5")]
#[cfg_attr(feature = "prost", prost(bytes, tag = "5"))]
fog_authority_spki: Vec<u8>,
}

Expand Down Expand Up @@ -520,15 +524,16 @@ impl AccountKey {
}

/// View AccountKey, containing the view private key and the spend public key.
#[derive(Clone, Message, Zeroize)]
#[derive(Clone, Zeroize)]
#[cfg_attr(feature = "prost", derive(Message))]
#[zeroize(drop)]
pub struct ViewAccountKey {
/// Private key 'a' used for view-key matching.
#[prost(message, required, tag = "1")]
#[cfg_attr(feature = "prost", prost(message, required, tag = "1"))]
view_private_key: RistrettoPrivate,

/// Public key `B` used for generating Public Addresses.
#[prost(message, required, tag = "2")]
#[cfg_attr(feature = "prost", prost(message, required, tag = "2"))]
spend_public_key: RistrettoPublic,
}

Expand Down
24 changes: 16 additions & 8 deletions account-keys/src/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@ use hkdf::SimpleHkdf;
use mc_crypto_hashes::Blake2b256;
use mc_crypto_keys::RistrettoPrivate;
use mc_util_from_random::FromRandom;
#[cfg(feature = "prost")]
use mc_util_repr_bytes::derive_prost_message_from_repr_bytes;
use mc_util_repr_bytes::{
derive_debug_and_display_hex_from_as_ref, derive_prost_message_from_repr_bytes,
derive_repr_bytes_from_as_ref_and_try_from, typenum::U32, LengthMismatch,
derive_debug_and_display_hex_from_as_ref, derive_repr_bytes_from_as_ref_and_try_from,
typenum::U32, LengthMismatch,
};

#[cfg(feature = "prost")]
use prost::Message;

use rand_core::{CryptoRng, RngCore};
use zeroize::Zeroize;

Expand Down Expand Up @@ -75,24 +80,27 @@ impl FromRandom for RootEntropy {
}

derive_repr_bytes_from_as_ref_and_try_from!(RootEntropy, U32);
derive_prost_message_from_repr_bytes!(RootEntropy);
derive_debug_and_display_hex_from_as_ref!(RootEntropy);

#[cfg(feature = "prost")]
derive_prost_message_from_repr_bytes!(RootEntropy);

/// A RootIdentity contains 32 bytes of root entropy (for deriving private keys
/// using a KDF), together with any fog data for the account.
#[derive(Clone, PartialEq, Eq, Hash, Message)]
#[derive(Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "prost", derive(Message))]
pub struct RootIdentity {
/// Root entropy used to derive a user's private keys.
#[prost(message, required, tag = 1)]
#[cfg_attr(feature = "prost", prost(message, required, tag = 1))]
pub root_entropy: RootEntropy,
/// Fog report url
#[prost(string, tag = 2)]
#[cfg_attr(feature = "prost", prost(string, tag = 2))]
pub fog_report_url: String,
/// Fog report id
#[prost(string, tag = 3)]
#[cfg_attr(feature = "prost", prost(string, tag = 3))]
pub fog_report_id: String,
/// Fog authority subjectPublicKeyInfo
#[prost(bytes, tag = 4)]
#[cfg_attr(feature = "prost", prost(bytes, tag = 4))]
pub fog_authority_spki: Vec<u8>,
}

Expand Down
7 changes: 2 additions & 5 deletions api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ mc-account-keys = { path = "../account-keys" }
mc-attest-verifier-types = { path = "../attest/verifier/types" }
mc-blockchain-types = { path = "../blockchain/types" }
mc-common = { path = "../common", default-features = false }
mc-crypto-dalek = { path = "../crypto/dalek" }
mc-crypto-keys = { path = "../crypto/keys" }
mc-crypto-multisig = { path = "../crypto/multisig" }
mc-crypto-ring-signature-signer = { path = "../crypto/ring-signature/signer" }
Expand All @@ -25,11 +26,7 @@ crc = "3.0.0"
displaydoc = { version = "0.2", default-features = false }
protobuf = "2.27.1"

[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"] }

[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"] }
curve25519-dalek = { version = "4.0.0-pre.2", default-features = false, features = ["nightly"] }

[build-dependencies]
mc-util-build-grpc = { path = "../util/build/grpc" }
Expand Down
7 changes: 5 additions & 2 deletions common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ authors = ["MobileCoin"]
edition = "2021"

[features]
default = []
default = [
"mc-crypto-dalek/default"
]
std = [
"displaydoc/std",
"mc-util-serial/std",
Expand Down Expand Up @@ -36,8 +38,9 @@ loggers = [
]

[dependencies]
mc-crypto-dalek = { path = "../crypto/dalek", default_features = false, features = [ "serde", "alloc" ] }
mc-crypto-digestible = { path = "../crypto/digestible" }
mc-crypto-keys = { path = "../crypto/keys", default-features = false }
mc-crypto-keys = { path = "../crypto/keys", default-features = false, features = [ "serde", "alloc", "prost" ] }
mc-crypto-rand = { path = "../crypto/rand" }
# loggers-only dependencies
mc-util-build-info = { path = "../util/build/info", optional = true }
Expand Down
Loading

0 comments on commit d91aceb

Please sign in to comment.