diff --git a/frost-core/Cargo.toml b/frost-core/Cargo.toml index 20ad31a9..232b0ebe 100644 --- a/frost-core/Cargo.toml +++ b/frost-core/Cargo.toml @@ -32,7 +32,8 @@ postcard = { version = "1.0.0", features = ["alloc"], optional = true } rand_core = { version = "0.6", default-features = false } serde = { version = "1.0.160", default-features = false, features = ["derive"], optional = true } serdect = { version = "0.2.0", optional = true } -thiserror = { version = "1.0", package = "thiserror-nostd-notrait", default-features = false } +thiserror-nostd-notrait = { version = "1.0", default-features = false } +thiserror = { version = "1.0", default-features = false, optional = true } visibility = "0.1.0" zeroize = { version = "1.5.4", default-features = false, features = ["derive"] } itertools = { version = "0.12.0", default-features = false } @@ -50,8 +51,10 @@ rand_chacha = "0.3" serde_json = "1.0" [features] -default = ["serialization", "cheater-detection"] +default = ["serialization", "cheater-detection", "std"] #! ## Features +## Enable standard library support. +std = ["dep:thiserror"] ## Expose internal types, which do not have SemVer guarantees. This is an advanced ## feature which can be useful if you need to build a modified version of FROST. ## The docs won't list them, you will need to check the source code. diff --git a/frost-core/src/error.rs b/frost-core/src/error.rs index 3a768bad..6fdd3606 100644 --- a/frost-core/src/error.rs +++ b/frost-core/src/error.rs @@ -1,7 +1,11 @@ //! FROST Error types +#[cfg(feature = "std")] use thiserror::Error; +#[cfg(not(feature = "std"))] +use thiserror_nostd_notrait::Error; + use crate::{Ciphersuite, Identifier}; #[derive(Error, Debug, Clone, Copy, Eq, PartialEq)] diff --git a/frost-core/src/lib.rs b/frost-core/src/lib.rs index e81c5515..acb0948e 100644 --- a/frost-core/src/lib.rs +++ b/frost-core/src/lib.rs @@ -1,4 +1,4 @@ -#![no_std] +#![cfg_attr(not(feature = "std"), no_std)] #![allow(non_snake_case)] // It's emitting false positives; see https://github.com/rust-lang/rust-clippy/issues/9413 #![allow(clippy::derive_partial_eq_without_eq)] diff --git a/frost-core/src/tests/ciphersuite_generic.rs b/frost-core/src/tests/ciphersuite_generic.rs index a33b1317..76ecf240 100644 --- a/frost-core/src/tests/ciphersuite_generic.rs +++ b/frost-core/src/tests/ciphersuite_generic.rs @@ -328,6 +328,7 @@ fn check_aggregate_errors( ); } +#[cfg(feature = "cheater-detection")] fn check_aggregate_corrupted_share( signing_package: frost::SigningPackage, mut signature_shares: BTreeMap, frost::round2::SignatureShare>, diff --git a/frost-ed25519/Cargo.toml b/frost-ed25519/Cargo.toml index e294df18..acab968f 100644 --- a/frost-ed25519/Cargo.toml +++ b/frost-ed25519/Cargo.toml @@ -25,8 +25,8 @@ rustdoc-args = ["--cfg", "docsrs"] [dependencies] curve25519-dalek = { version = "=4.1.2", features = ["rand_core"] } document-features = "0.2.7" -frost-core = { path = "../frost-core", version = "1.0.0" } -frost-rerandomized = { path = "../frost-rerandomized", version = "1.0.0" } +frost-core = { path = "../frost-core", version = "1.0.0", default-features = false } +frost-rerandomized = { path = "../frost-rerandomized", version = "1.0.0", default-features = false } rand_core = "0.6" sha2 = { version = "0.10.2", default-features = false } @@ -45,15 +45,18 @@ serde_json = "1.0" [features] nightly = [] -default = ["serialization", "cheater-detection"] -serialization = ["serde", "frost-core/serialization"] +default = ["serialization", "cheater-detection", "std"] #! ## Features +## Enable standard library support. +std = ["frost-core/std"] ## Enable `serde` support for types that need to be communicated. You ## can use `serde` to serialize structs with any encoder that supports ## `serde` (e.g. JSON with `serde_json`). serde = ["frost-core/serde"] +## Enable a default serialization format. Enables `serde`. +serialization = ["serde", "frost-core/serialization", "frost-rerandomized/serialization"] ## Enable cheater detection -cheater-detection = ["frost-core/cheater-detection"] +cheater-detection = ["frost-core/cheater-detection", "frost-rerandomized/cheater-detection"] [lib] # Disables non-criterion benchmark which is not used; prevents errors diff --git a/frost-ed25519/src/lib.rs b/frost-ed25519/src/lib.rs index 693ad739..7109a0a5 100644 --- a/frost-ed25519/src/lib.rs +++ b/frost-ed25519/src/lib.rs @@ -1,4 +1,4 @@ -#![no_std] +#![cfg_attr(not(feature = "std"), no_std)] #![allow(non_snake_case)] #![deny(missing_docs)] #![cfg_attr(docsrs, feature(doc_auto_cfg))] @@ -26,7 +26,9 @@ use frost_core as frost; mod tests; // Re-exports in our public API -pub use frost_core::{serde, Ciphersuite, Field, FieldError, Group, GroupError}; +#[cfg(feature = "serde")] +pub use frost_core::serde; +pub use frost_core::{Ciphersuite, Field, FieldError, Group, GroupError}; pub use rand_core; /// An error. diff --git a/frost-ed448/Cargo.toml b/frost-ed448/Cargo.toml index d1b37df6..703c1c58 100644 --- a/frost-ed448/Cargo.toml +++ b/frost-ed448/Cargo.toml @@ -24,8 +24,8 @@ rustdoc-args = ["--cfg", "docsrs"] [dependencies] document-features = "0.2.7" ed448-goldilocks = { version = "0.9.0" } -frost-core = { path = "../frost-core", version = "1.0.0" } -frost-rerandomized = { path = "../frost-rerandomized", version = "1.0.0" } +frost-core = { path = "../frost-core", version = "1.0.0", default-features = false } +frost-rerandomized = { path = "../frost-rerandomized", version = "1.0.0", default-features = false } rand_core = "0.6" sha3 = { version = "0.10.6", default-features = false } @@ -43,15 +43,18 @@ serde_json = "1.0" [features] nightly = [] -default = ["serialization", "cheater-detection"] -serialization = ["serde", "frost-core/serialization"] +default = ["serialization", "cheater-detection", "std"] #! ## Features +## Enable standard library support. +std = ["frost-core/std"] ## Enable `serde` support for types that need to be communicated. You ## can use `serde` to serialize structs with any encoder that supports ## `serde` (e.g. JSON with `serde_json`). serde = ["frost-core/serde"] +## Enable a default serialization format. Enables `serde`. +serialization = ["serde", "frost-core/serialization", "frost-rerandomized/serialization"] ## Enable cheater detection -cheater-detection = ["frost-core/cheater-detection"] +cheater-detection = ["frost-core/cheater-detection", "frost-rerandomized/cheater-detection"] [lib] # Disables non-criterion benchmark which is not used; prevents errors diff --git a/frost-ed448/src/lib.rs b/frost-ed448/src/lib.rs index 21e350ac..518e807f 100644 --- a/frost-ed448/src/lib.rs +++ b/frost-ed448/src/lib.rs @@ -26,7 +26,9 @@ use frost_core as frost; mod tests; // Re-exports in our public API -pub use frost_core::{serde, Ciphersuite, Field, FieldError, Group, GroupError}; +#[cfg(feature = "serde")] +pub use frost_core::serde; +pub use frost_core::{Ciphersuite, Field, FieldError, Group, GroupError}; pub use rand_core; /// An error. diff --git a/frost-p256/Cargo.toml b/frost-p256/Cargo.toml index 5fc1aa1a..27046aac 100644 --- a/frost-p256/Cargo.toml +++ b/frost-p256/Cargo.toml @@ -25,8 +25,8 @@ rustdoc-args = ["--cfg", "docsrs"] [dependencies] document-features = "0.2.7" p256 = { version = "0.13.0", features = ["hash2curve"], default-features = false } -frost-core = { path = "../frost-core", version = "1.0.0" } -frost-rerandomized = { path = "../frost-rerandomized", version = "1.0.0" } +frost-core = { path = "../frost-core", version = "1.0.0", default-features = false } +frost-rerandomized = { path = "../frost-rerandomized", version = "1.0.0", default-features = false } rand_core = "0.6" sha2 = { version = "0.10.2", default-features = false } @@ -44,15 +44,18 @@ serde_json = "1.0" [features] nightly = [] -default = ["serialization", "cheater-detection"] -serialization = ["serde", "frost-core/serialization"] +default = ["serialization", "cheater-detection", "std"] #! ## Features +## Enable standard library support. +std = ["frost-core/std"] ## Enable `serde` support for types that need to be communicated. You ## can use `serde` to serialize structs with any encoder that supports ## `serde` (e.g. JSON with `serde_json`). serde = ["frost-core/serde"] +## Enable a default serialization format. Enables `serde`. +serialization = ["serde", "frost-core/serialization", "frost-rerandomized/serialization"] ## Enable cheater detection -cheater-detection = ["frost-core/cheater-detection"] +cheater-detection = ["frost-core/cheater-detection", "frost-rerandomized/cheater-detection"] [lib] # Disables non-criterion benchmark which is not used; prevents errors diff --git a/frost-p256/src/lib.rs b/frost-p256/src/lib.rs index b88fd98a..eeb746ca 100644 --- a/frost-p256/src/lib.rs +++ b/frost-p256/src/lib.rs @@ -1,4 +1,4 @@ -#![no_std] +#![cfg_attr(not(feature = "std"), no_std)] #![allow(non_snake_case)] #![deny(missing_docs)] #![cfg_attr(docsrs, feature(doc_auto_cfg))] @@ -29,7 +29,9 @@ use frost_core as frost; mod tests; // Re-exports in our public API -pub use frost_core::{serde, Ciphersuite, Field, FieldError, Group, GroupError}; +#[cfg(feature = "serde")] +pub use frost_core::serde; +pub use frost_core::{Ciphersuite, Field, FieldError, Group, GroupError}; pub use rand_core; /// An error. diff --git a/frost-rerandomized/Cargo.toml b/frost-rerandomized/Cargo.toml index 71c37335..3504babd 100644 --- a/frost-rerandomized/Cargo.toml +++ b/frost-rerandomized/Cargo.toml @@ -6,8 +6,11 @@ edition = "2021" # - Update CHANGELOG.md # - Create git tag. version = "1.0.0" -authors = ["Deirdre Connolly ", "Chelsea Komlo ", - "Conrado Gouvea "] +authors = [ + "Deirdre Connolly ", + "Chelsea Komlo ", + "Conrado Gouvea ", +] readme = "README.md" license = "MIT OR Apache-2.0" repository = "https://github.com/ZcashFoundation/frost" @@ -22,7 +25,9 @@ rustdoc-args = ["--cfg", "docsrs"] [dependencies] derive-getters = "0.3.0" document-features = "0.2.7" -frost-core = { path = "../frost-core", version = "1.0.0", features = ["internals"] } +frost-core = { path = "../frost-core", version = "1.0.0", features = [ + "internals", +], default-features = false } rand_core = "0.6" [dev-dependencies] @@ -32,11 +37,13 @@ nightly = [] default = ["serialization", "cheater-detection"] serialization = ["serde", "frost-core/serialization"] #! ## Features +## Enable standard library support. +std = ["frost-core/std"] ## Enable `serde` support for types that need to be communicated. You ## can use `serde` to serialize structs with any encoder that supports ## `serde` (e.g. JSON with `serde_json`). serde = ["frost-core/serde"] # Exposes ciphersuite-generic tests for other crates to use -test-impl = ["frost-core/test-impl"] +test-impl = ["frost-core/test-impl", "serialization"] ## Enable cheater detection cheater-detection = ["frost-core/cheater-detection"] diff --git a/frost-rerandomized/src/lib.rs b/frost-rerandomized/src/lib.rs index 998f649a..0d43bcdc 100644 --- a/frost-rerandomized/src/lib.rs +++ b/frost-rerandomized/src/lib.rs @@ -9,7 +9,7 @@ //! - Each participant should call [`sign`] and send the resulting //! [`frost::round2::SignatureShare`] back to the Coordinator; //! - The Coordinator should then call [`aggregate`]. -#![no_std] +#![cfg_attr(not(feature = "std"), no_std)] #![allow(non_snake_case)] extern crate alloc; @@ -22,10 +22,12 @@ use alloc::collections::BTreeMap; use derive_getters::Getters; pub use frost_core; +#[cfg(feature = "serialization")] +use frost_core::SigningPackage; use frost_core::{ self as frost, keys::{KeyPackage, PublicKeyPackage, SigningShare, VerifyingShare}, - Ciphersuite, Error, Field, Group, Scalar, SigningPackage, VerifyingKey, + Ciphersuite, Error, Field, Group, Scalar, VerifyingKey, }; #[cfg(feature = "serde")] @@ -35,6 +37,7 @@ use frost_core::serialization::ScalarSerialization; // When pulled into `reddsa`, that has its own sibling `rand_core` import. // For the time being, we do not re-export this `rand_core`. +#[cfg(feature = "serialization")] use rand_core::{CryptoRng, RngCore}; /// Randomize the given key type for usage in a FROST signing with re-randomized keys, @@ -172,6 +175,7 @@ where /// The [`SigningPackage`] must be the signing package being used in the /// current FROST signing run. It is hashed into the randomizer calculation, /// which binds it to that specific package. + #[cfg(feature = "serialization")] pub fn new( mut rng: R, signing_package: &SigningPackage, @@ -182,6 +186,7 @@ where /// Create a final Randomizer from a random Randomizer and a SigningPackage. /// Function refactored out for testing, should always be private. + #[cfg(feature = "serialization")] fn from_randomizer_and_signing_package( rng_randomizer: <<::Group as Group>::Field as Field>::Scalar, signing_package: &SigningPackage, @@ -269,6 +274,7 @@ where { /// Create a new [`RandomizedParams`] for the given [`VerifyingKey`] and /// the given `participants`. + #[cfg(feature = "serialization")] pub fn new( group_verifying_key: &VerifyingKey, signing_package: &SigningPackage, diff --git a/frost-ristretto255/Cargo.toml b/frost-ristretto255/Cargo.toml index bdf99a79..ce0e1201 100644 --- a/frost-ristretto255/Cargo.toml +++ b/frost-ristretto255/Cargo.toml @@ -19,10 +19,10 @@ features = ["serde"] rustdoc-args = ["--cfg", "docsrs"] [dependencies] -curve25519-dalek = { version = "=4.1.2", features = ["serde", "rand_core"] } +curve25519-dalek = { version = "=4.1.2", features = ["rand_core"] } document-features = "0.2.7" -frost-core = { path = "../frost-core", version = "1.0.0" } -frost-rerandomized = { path = "../frost-rerandomized", version = "1.0.0" } +frost-core = { path = "../frost-core", version = "1.0.0", default-features = false } +frost-rerandomized = { path = "../frost-rerandomized", version = "1.0.0", default-features = false } rand_core = "0.6" sha2 = { version = "0.10.2", default-features = false } @@ -41,15 +41,18 @@ serde_json = "1.0" [features] nightly = [] -default = ["serialization", "cheater-detection"] -serialization = ["serde", "frost-core/serialization"] +default = ["serialization", "cheater-detection", "std"] #! ## Features +## Enable standard library support. +std = ["frost-core/std"] ## Enable `serde` support for types that need to be communicated. You ## can use `serde` to serialize structs with any encoder that supports ## `serde` (e.g. JSON with `serde_json`). -serde = ["frost-core/serde"] +serde = ["frost-core/serde", "curve25519-dalek/serde"] +## Enable a default serialization format. Enables `serde`. +serialization = ["serde", "frost-core/serialization", "frost-rerandomized/serialization"] ## Enable cheater detection -cheater-detection = ["frost-core/cheater-detection"] +cheater-detection = ["frost-core/cheater-detection", "frost-rerandomized/cheater-detection"] [lib] # Disables non-criterion benchmark which is not used; prevents errors diff --git a/frost-ristretto255/src/lib.rs b/frost-ristretto255/src/lib.rs index 5af9b9c0..2a0090ef 100644 --- a/frost-ristretto255/src/lib.rs +++ b/frost-ristretto255/src/lib.rs @@ -1,4 +1,4 @@ -#![no_std] +#![cfg_attr(not(feature = "std"), no_std)] #![allow(non_snake_case)] #![deny(missing_docs)] #![doc = include_str!("../README.md")] @@ -23,7 +23,9 @@ use frost_core as frost; mod tests; // Re-exports in our public API -pub use frost_core::{serde, Ciphersuite, Field, FieldError, Group, GroupError}; +#[cfg(feature = "serde")] +pub use frost_core::serde; +pub use frost_core::{Ciphersuite, Field, FieldError, Group, GroupError}; pub use rand_core; /// An error. diff --git a/frost-secp256k1/Cargo.toml b/frost-secp256k1/Cargo.toml index e8a300be..70fee470 100644 --- a/frost-secp256k1/Cargo.toml +++ b/frost-secp256k1/Cargo.toml @@ -23,8 +23,8 @@ rustdoc-args = ["--cfg", "docsrs"] [dependencies] document-features = "0.2.7" -frost-core = { path = "../frost-core", version = "1.0.0" } -frost-rerandomized = { path = "../frost-rerandomized", version = "1.0.0" } +frost-core = { path = "../frost-core", version = "1.0.0", default-features = false } +frost-rerandomized = { path = "../frost-rerandomized", version = "1.0.0", default-features = false } k256 = { version = "0.13.0", features = ["arithmetic", "expose-field", "hash2curve"], default-features = false } rand_core = "0.6" sha2 = { version = "0.10.2", default-features = false } @@ -43,15 +43,18 @@ serde_json = "1.0" [features] nightly = [] -default = ["serialization", "cheater-detection"] -serialization = ["serde", "frost-core/serialization"] +default = ["serialization", "cheater-detection", "std"] #! ## Features +## Enable standard library support. +std = ["frost-core/std"] ## Enable `serde` support for types that need to be communicated. You ## can use `serde` to serialize structs with any encoder that supports ## `serde` (e.g. JSON with `serde_json`). serde = ["frost-core/serde"] +## Enable a default serialization format. Enables `serde`. +serialization = ["serde", "frost-core/serialization", "frost-rerandomized/serialization"] ## Enable cheater detection -cheater-detection = ["frost-core/cheater-detection"] +cheater-detection = ["frost-core/cheater-detection", "frost-rerandomized/cheater-detection"] [lib] # Disables non-criterion benchmark which is not used; prevents errors diff --git a/frost-secp256k1/src/lib.rs b/frost-secp256k1/src/lib.rs index b0738e7c..6c50d02b 100644 --- a/frost-secp256k1/src/lib.rs +++ b/frost-secp256k1/src/lib.rs @@ -1,4 +1,4 @@ -#![no_std] +#![cfg_attr(not(feature = "std"), no_std)] #![allow(non_snake_case)] #![deny(missing_docs)] #![cfg_attr(docsrs, feature(doc_auto_cfg))] @@ -30,7 +30,9 @@ use frost_core as frost; mod tests; // Re-exports in our public API -pub use frost_core::{serde, Ciphersuite, Field, FieldError, Group, GroupError}; +#[cfg(feature = "serde")] +pub use frost_core::serde; +pub use frost_core::{Ciphersuite, Field, FieldError, Group, GroupError}; pub use rand_core; /// An error.