diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e6e082c0..05a9ffd4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -48,6 +48,22 @@ jobs: - run: cargo install cargo-all-features - run: cargo build-all-features + build_no_std: + name: build with no_std + runs-on: ubuntu-latest + # Skip ed448 which does not support it. + strategy: + matrix: + crate: [ristretto255, ed25519, p256, secp256k1, rerandomized] + steps: + - uses: actions/checkout@v4.1.1 + - uses: dtolnay/rust-toolchain@master + with: + toolchain: stable + targets: thumbv6m-none-eabi + - run: cargo build -p frost-${{ matrix.crate }} --no-default-features --target thumbv6m-none-eabi + - run: cargo build -p frost-${{ matrix.crate }} --no-default-features --features serialization --target thumbv6m-none-eabi + test_beta: name: test on beta runs-on: ubuntu-latest diff --git a/frost-core/CHANGELOG.md b/frost-core/CHANGELOG.md index 08196012..97b0927c 100644 --- a/frost-core/CHANGELOG.md +++ b/frost-core/CHANGELOG.md @@ -24,6 +24,14 @@ Entries are listed in reverse chronological order. will result in a coherence error in future Rust versions (see #625). In the unlikely case you're using this, you can replace e.g. `scalar *= identifier` with `scalar = identifier * scalar`. +* Add no-std support to all crates except frost-ed448. To use, do not enable the + `std` feature that is enabled by default (i.e. use `default-features = + false`); Note that it always links to an external `alloc` crate (i.e. there is + no `alloc` feature). When disabling `std`, the only impact in the API is that + `Error` will no longer implement the `std::error::Error` trait. This is a + breaking change if you are disabling default features but rely on `Error` + implementing `std::error::Error`. In that case, simply enable the `std` + feature. ## 1.0.1 @@ -31,8 +39,6 @@ Entries are listed in reverse chronological order. * Fixed some feature handling that would include unneeded dependencies in some cases. -## Released - ## 1.0.0 * Exposed the `SigningKey::from_scalar()` and `to_scalar()` methods. This diff --git a/frost-core/Cargo.toml b/frost-core/Cargo.toml index 2a029825..51125140 100644 --- a/frost-core/Cargo.toml +++ b/frost-core/Cargo.toml @@ -22,20 +22,21 @@ features = ["serde"] rustdoc-args = ["--cfg", "docsrs"] [dependencies] -byteorder = "1.4" -const-crc32 = "1.2.0" +byteorder = { version = "1.4", default-features = false } +const-crc32 = { version = "1.2.0", package = "const-crc32-nostd" } document-features = "0.2.7" debugless-unwrap = "0.0.4" derive-getters = "0.4.0" -hex = "0.4.3" -postcard = { version = "1.0.0", features = ["use-std"], optional = true } -rand_core = "0.6" -serde = { version = "1.0.160", features = ["derive"], optional = true } +hex = { version = "0.4.3", default-features = false, features = ["alloc"] } +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 = "1.0.29" +thiserror-nostd-notrait = { version = "1.0.29", default-features = false } +thiserror = { version = "1.0.29", default-features = false, optional = true } visibility = "0.1.0" zeroize = { version = "1.5.4", default-features = false, features = ["derive"] } -itertools = "0.13.0" +itertools = { version = "0.13.0", default-features = false } # Test dependencies used with the test-impl feature proptest = { version = "1.0", optional = true } @@ -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/batch.rs b/frost-core/src/batch.rs index 9aa81999..3aa1e806 100644 --- a/frost-core/src/batch.rs +++ b/frost-core/src/batch.rs @@ -7,8 +7,6 @@ //! of caller code (which must assemble a batch of signatures across //! work-items), and loss of the ability to easily pinpoint failing signatures. -use std::iter::once; - use rand_core::{CryptoRng, RngCore}; use crate::{scalar_mul::VartimeMultiscalarMul, Ciphersuite, Element, *}; @@ -136,7 +134,7 @@ where VKs.push(item.vk.to_element()); } - let scalars = once(&P_coeff_acc) + let scalars = core::iter::once(&P_coeff_acc) .chain(VK_coeffs.iter()) .chain(R_coeffs.iter()); @@ -159,6 +157,8 @@ where C: Ciphersuite, { fn default() -> Self { - Self { signatures: vec![] } + Self { + signatures: Vec::new(), + } } } diff --git a/frost-core/src/benches.rs b/frost-core/src/benches.rs index 16810cc4..f89ce4af 100644 --- a/frost-core/src/benches.rs +++ b/frost-core/src/benches.rs @@ -1,11 +1,13 @@ //! Ciphersuite-generic benchmark functions. #![allow(clippy::unwrap_used)] -use std::collections::BTreeMap; +use core::iter; -use criterion::{BenchmarkId, Criterion, Throughput}; +use alloc::{collections::BTreeMap, format, vec::Vec}; use rand_core::{CryptoRng, RngCore}; +use criterion::{BenchmarkId, Criterion, Throughput}; + use crate as frost; use crate::{batch, Ciphersuite, Signature, SigningKey, VerifyingKey}; @@ -18,7 +20,7 @@ fn sigs_with_distinct_keys( rng: &mut R, ) -> impl Iterator> { let mut rng = rng.clone(); - std::iter::repeat_with(move || { + iter::repeat_with(move || { let msg = b"Bench"; let sk = SigningKey::new(&mut rng); let vk = VerifyingKey::from(&sk); 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/identifier.rs b/frost-core/src/identifier.rs index edb64cff..956d1692 100644 --- a/frost-core/src/identifier.rs +++ b/frost-core/src/identifier.rs @@ -1,6 +1,6 @@ //! FROST participant identifiers -use std::{ +use core::{ fmt::{self, Debug}, hash::{Hash, Hasher}, }; @@ -117,7 +117,7 @@ impl Ord for Identifier where C: Ciphersuite, { - fn cmp(&self, other: &Self) -> std::cmp::Ordering { + fn cmp(&self, other: &Self) -> core::cmp::Ordering { let serialized_self = <::Field>::little_endian_serialize(&self.0); let serialized_other = <::Field>::little_endian_serialize(&other.0); // The default cmp uses lexicographic order; so we need the elements in big endian @@ -133,12 +133,12 @@ impl PartialOrd for Identifier where C: Ciphersuite, { - fn partial_cmp(&self, other: &Self) -> Option { + fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } } -impl std::ops::Mul> for Identifier +impl core::ops::Mul> for Identifier where C: Ciphersuite, { @@ -149,7 +149,7 @@ where } } -impl std::ops::Sub for Identifier +impl core::ops::Sub for Identifier where C: Ciphersuite, { diff --git a/frost-core/src/keys.rs b/frost-core/src/keys.rs index 38adfe86..99e017d6 100644 --- a/frost-core/src/keys.rs +++ b/frost-core/src/keys.rs @@ -1,12 +1,13 @@ //! FROST keys, keygen, key shares #![allow(clippy::type_complexity)] -use std::{ - collections::{BTreeMap, BTreeSet, HashSet}, - convert::TryFrom, - default::Default, +use core::iter; + +use alloc::{ + collections::{BTreeMap, BTreeSet}, fmt::{self, Debug}, - iter, + string::ToString, + vec::Vec, }; use derive_getters::Getters; @@ -128,7 +129,7 @@ impl Debug for SigningShare where C: Ciphersuite, { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> core::fmt::Result { f.debug_tuple("SigningShare").field(&"").finish() } } @@ -310,7 +311,7 @@ impl Debug for CoefficientCommitment where C: Ciphersuite, { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> core::fmt::Result { f.debug_tuple("CoefficientCommitment") .field( &self @@ -874,7 +875,7 @@ pub(crate) fn generate_secret_shares( let (coefficients, commitment) = generate_secret_polynomial(secret, max_signers, min_signers, coefficients)?; - let identifiers_set: HashSet<_> = identifiers.iter().collect(); + let identifiers_set: BTreeSet<_> = identifiers.iter().collect(); if identifiers_set.len() != identifiers.len() { return Err(Error::DuplicatedIdentifier); } diff --git a/frost-core/src/keys/dkg.rs b/frost-core/src/keys/dkg.rs index dd09bda5..483da98d 100644 --- a/frost-core/src/keys/dkg.rs +++ b/frost-core/src/keys/dkg.rs @@ -30,7 +30,9 @@ //! [Feldman's VSS]: https://www.cs.umd.edu/~gasarch/TOPICS/secretsharing/feldmanVSS.pdf //! [secure broadcast channel]: https://frost.zfnd.org/terminology.html#broadcast-channel -use std::{collections::BTreeMap, iter}; +use core::iter; + +use alloc::collections::BTreeMap; use rand_core::{CryptoRng, RngCore}; @@ -39,6 +41,9 @@ use crate::{ SigningKey, VerifyingKey, }; +#[cfg(feature = "serialization")] +use crate::serialization::{Deserialize, Serialize}; + use super::{ evaluate_polynomial, generate_coefficients, generate_secret_polynomial, validate_num_of_signers, KeyPackage, PublicKeyPackage, SecretShare, SigningShare, @@ -47,14 +52,15 @@ use super::{ /// DKG Round 1 structures. pub mod round1 { + use alloc::vec::Vec; use derive_getters::Getters; use zeroize::Zeroize; + use super::*; + #[cfg(feature = "serialization")] use crate::serialization::{Deserialize, Serialize}; - use super::*; - /// The package that must be broadcast by each participant to all other participants /// between the first and second parts of the DKG protocol (round 1). #[derive(Clone, Debug, PartialEq, Eq, Getters)] @@ -136,11 +142,11 @@ pub mod round1 { } } - impl std::fmt::Debug for SecretPackage + impl core::fmt::Debug for SecretPackage where C: Ciphersuite, { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.debug_struct("SecretPackage") .field("identifier", &self.identifier) .field("coefficients", &"") @@ -169,7 +175,7 @@ pub mod round2 { use zeroize::Zeroize; #[cfg(feature = "serialization")] - use crate::serialization::{Deserialize, Serialize}; + use alloc::vec::Vec; use super::*; @@ -241,11 +247,11 @@ pub mod round2 { pub(crate) max_signers: u16, } - impl std::fmt::Debug for SecretPackage + impl core::fmt::Debug for SecretPackage where C: Ciphersuite, { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.debug_struct("SecretPackage") .field("identifier", &self.identifier) .field("commitment", &self.commitment) diff --git a/frost-core/src/keys/repairable.rs b/frost-core/src/keys/repairable.rs index 169e0ab8..5297d8b7 100644 --- a/frost-core/src/keys/repairable.rs +++ b/frost-core/src/keys/repairable.rs @@ -4,7 +4,9 @@ //! The RTS is used to help a signer (participant) repair their lost share. This is achieved //! using a subset of the other signers know here as `helpers`. -use std::collections::{BTreeMap, BTreeSet}; +use alloc::collections::{BTreeMap, BTreeSet}; + +use alloc::vec::Vec; use crate::{ compute_lagrange_coefficient, Ciphersuite, CryptoRng, Error, Field, Group, Header, Identifier, diff --git a/frost-core/src/lib.rs b/frost-core/src/lib.rs index 3f6655bc..63d06ad3 100644 --- a/frost-core/src/lib.rs +++ b/frost-core/src/lib.rs @@ -1,3 +1,4 @@ +#![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)] @@ -10,11 +11,15 @@ #![doc = include_str!("../README.md")] #![doc = document_features::document_features!()] -use std::{ +#[macro_use] +extern crate alloc; + +use core::marker::PhantomData; + +use alloc::{ collections::{BTreeMap, BTreeSet}, - default::Default, fmt::{self, Debug}, - marker::PhantomData, + vec::Vec, }; use derive_getters::Getters; @@ -87,7 +92,7 @@ impl Debug for Challenge where C: Ciphersuite, { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.debug_tuple("Secret") .field(&hex::encode(<::Field>::serialize( &self.0, @@ -115,7 +120,7 @@ fn challenge( where C: Ciphersuite, { - let mut preimage = vec![]; + let mut preimage = Vec::new(); preimage.extend_from_slice(::serialize(R)?.as_ref()); preimage.extend_from_slice(::serialize(&verifying_key.to_element())?.as_ref()); @@ -409,7 +414,7 @@ where verifying_key: &VerifyingKey, additional_prefix: &[u8], ) -> Result, Vec)>, Error> { - let mut binding_factor_input_prefix = vec![]; + let mut binding_factor_input_prefix = Vec::new(); // The length of a serialized verifying key of the same cipersuite does // not change between runs of the protocol, so we don't need to hash to @@ -429,7 +434,7 @@ where .signing_commitments() .keys() .map(|identifier| { - let mut binding_factor_input = vec![]; + let mut binding_factor_input = Vec::new(); binding_factor_input.extend_from_slice(&binding_factor_input_prefix); binding_factor_input.extend_from_slice(identifier.serialize().as_ref()); diff --git a/frost-core/src/round1.rs b/frost-core/src/round1.rs index bfc11c1b..08414133 100644 --- a/frost-core/src/round1.rs +++ b/frost-core/src/round1.rs @@ -1,8 +1,10 @@ //! FROST Round 1 functionality and types -use std::{ +use alloc::{ collections::BTreeMap, fmt::{self, Debug}, + string::ToString, + vec::Vec, }; use derive_getters::Getters; @@ -286,7 +288,7 @@ impl Debug for SigningNonces where C: Ciphersuite, { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("SigningNonces") .field("hiding", &"") .field("binding", &"") @@ -344,7 +346,7 @@ where /// Computes the [signature commitment share] from these round one signing commitments. /// /// [signature commitment share]: https://www.ietf.org/archive/id/draft-irtf-cfrg-frost-14.html#name-signature-share-verificatio - #[cfg(any(feature = "cheater-detection", feature = "internals"))] + #[cfg(any(feature = "internals", feature = "cheater-detection"))] #[cfg_attr(feature = "internals", visibility::make(pub))] #[cfg_attr(docsrs, doc(cfg(feature = "internals")))] pub(super) fn to_group_commitment_share( diff --git a/frost-core/src/round2.rs b/frost-core/src/round2.rs index f71bddef..25e03a85 100644 --- a/frost-core/src/round2.rs +++ b/frost-core/src/round2.rs @@ -1,6 +1,6 @@ //! FROST Round 2 functionality and types, for signature share generation -use std::fmt::{self, Debug}; +use core::fmt::{self, Debug}; use crate as frost; use crate::{ diff --git a/frost-core/src/scalar_mul.rs b/frost-core/src/scalar_mul.rs index ea441ab1..7e6fb3fa 100644 --- a/frost-core/src/scalar_mul.rs +++ b/frost-core/src/scalar_mul.rs @@ -4,12 +4,14 @@ // constraints. #![allow(clippy::indexing_slicing)] -use std::{ +use core::{ borrow::Borrow, fmt::{Debug, Result}, marker::PhantomData, }; +use alloc::vec::Vec; + use crate::{Ciphersuite, Element, Field, Group, Scalar}; /// Calculates the quotient of `self` and `rhs`, rounding the result towards positive infinity. @@ -243,7 +245,7 @@ impl LookupTable5 { } impl Debug for LookupTable5 { - fn fmt(&self, f: &mut std::fmt::Formatter) -> Result { + fn fmt(&self, f: &mut core::fmt::Formatter) -> Result { write!(f, "LookupTable5({:?})", self.bytes) } } diff --git a/frost-core/src/serialization.rs b/frost-core/src/serialization.rs index eda0bdec..59ae6f6a 100644 --- a/frost-core/src/serialization.rs +++ b/frost-core/src/serialization.rs @@ -1,5 +1,8 @@ //! Serialization support. +#[cfg(feature = "serialization")] +use alloc::vec::Vec; + use crate::Ciphersuite; #[cfg(feature = "serde")] @@ -134,7 +137,7 @@ where C: Ciphersuite, { if deserializer.is_human_readable() { - let s: String = serde::de::Deserialize::deserialize(deserializer)?; + let s: alloc::string::String = serde::de::Deserialize::deserialize(deserializer)?; if s != C::ID { Err(serde::de::Error::custom("wrong ciphersuite")) } else { @@ -186,13 +189,13 @@ pub(crate) trait Deserialize { /// Deserialize the struct from a slice of bytes. fn deserialize(bytes: &[u8]) -> Result> where - Self: std::marker::Sized; + Self: core::marker::Sized; } #[cfg(feature = "serialization")] impl Serialize for T { fn serialize(&self) -> Result, Error> { - postcard::to_stdvec(self).map_err(|_| Error::SerializationError) + postcard::to_allocvec(self).map_err(|_| Error::SerializationError) } } diff --git a/frost-core/src/signature.rs b/frost-core/src/signature.rs index a55b0db2..3da178ce 100644 --- a/frost-core/src/signature.rs +++ b/frost-core/src/signature.rs @@ -1,5 +1,7 @@ //! Schnorr signatures over prime order groups (or subgroups) +use alloc::{string::ToString, vec::Vec}; + use debugless_unwrap::DebuglessUnwrap; use crate::{Ciphersuite, Element, Error, Field, Group, Scalar}; @@ -72,7 +74,7 @@ where /// Converts this signature to its [`Ciphersuite::SignatureSerialization`] in bytes. pub fn serialize(&self) -> Result> { - let mut bytes = vec![]; + let mut bytes = Vec::::new(); bytes.extend(::serialize(&self.R)?.as_ref()); bytes.extend(<::Field>::serialize(&self.z).as_ref()); @@ -123,8 +125,8 @@ where } } -impl std::fmt::Debug for Signature { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl core::fmt::Debug for Signature { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { f.debug_struct("Signature") .field( "R", diff --git a/frost-core/src/signing_key.rs b/frost-core/src/signing_key.rs index 03e13156..a92e7fcf 100644 --- a/frost-core/src/signing_key.rs +++ b/frost-core/src/signing_key.rs @@ -69,11 +69,11 @@ where } } -impl std::fmt::Debug for SigningKey +impl core::fmt::Debug for SigningKey where C: Ciphersuite, { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.debug_tuple("SigningKey").field(&"").finish() } } diff --git a/frost-core/src/tests/ciphersuite_generic.rs b/frost-core/src/tests/ciphersuite_generic.rs index 5fdba722..76ecf240 100644 --- a/frost-core/src/tests/ciphersuite_generic.rs +++ b/frost-core/src/tests/ciphersuite_generic.rs @@ -1,12 +1,14 @@ //! Ciphersuite-generic test functions. #![allow(clippy::type_complexity)] -use std::{collections::BTreeMap, convert::TryFrom}; +use alloc::collections::BTreeMap; use crate as frost; use crate::{ keys::PublicKeyPackage, Error, Field, Group, Identifier, Signature, SigningKey, VerifyingKey, }; +use alloc::borrow::ToOwned; +use alloc::vec::Vec; use rand_core::{CryptoRng, RngCore}; use crate::Ciphersuite; @@ -366,7 +368,7 @@ pub fn check_sign_with_dkg( mut rng: R, ) -> (Vec, Signature, VerifyingKey) where - C::Group: std::cmp::PartialEq, + C::Group: core::cmp::PartialEq, { //////////////////////////////////////////////////////////////////////////// // Key generation, Round 1 diff --git a/frost-core/src/tests/coefficient_commitment.rs b/frost-core/src/tests/coefficient_commitment.rs index 6218d167..094b47a7 100644 --- a/frost-core/src/tests/coefficient_commitment.rs +++ b/frost-core/src/tests/coefficient_commitment.rs @@ -1,7 +1,5 @@ //! CoefficientCommitment functions -use std::convert::TryFrom; - use crate as frost; use crate::{keys::CoefficientCommitment, tests::helpers::generate_element, Group}; use debugless_unwrap::DebuglessUnwrap; diff --git a/frost-core/src/tests/repairable.rs b/frost-core/src/tests/repairable.rs index 8c187a85..ed4f2875 100644 --- a/frost-core/src/tests/repairable.rs +++ b/frost-core/src/tests/repairable.rs @@ -1,6 +1,6 @@ //! Test for Repairable Threshold Scheme -use std::collections::BTreeMap; +use alloc::collections::BTreeMap; use debugless_unwrap::DebuglessUnwrap; use rand_core::{CryptoRng, RngCore}; diff --git a/frost-core/src/tests/vectors.rs b/frost-core/src/tests/vectors.rs index 837e8929..144827a4 100644 --- a/frost-core/src/tests/vectors.rs +++ b/frost-core/src/tests/vectors.rs @@ -1,5 +1,5 @@ //! Helper function for testing with test vectors. -use std::collections::BTreeMap; +use alloc::collections::BTreeMap; use debugless_unwrap::DebuglessUnwrap; use hex::{self, FromHex}; diff --git a/frost-core/src/tests/vectors_dkg.rs b/frost-core/src/tests/vectors_dkg.rs index 1b06a21a..6619c8b5 100644 --- a/frost-core/src/tests/vectors_dkg.rs +++ b/frost-core/src/tests/vectors_dkg.rs @@ -1,5 +1,5 @@ //! Helper function for testing with test vectors. -use std::collections::BTreeMap; +use alloc::{collections::BTreeMap, string::ToString}; use debugless_unwrap::DebuglessUnwrap; use hex::{self}; diff --git a/frost-core/src/tests/vss_commitment.rs b/frost-core/src/tests/vss_commitment.rs index 31b5d4cb..91a341f0 100644 --- a/frost-core/src/tests/vss_commitment.rs +++ b/frost-core/src/tests/vss_commitment.rs @@ -1,7 +1,5 @@ //! VerifiableSecretSharingCommitment functions -use std::convert::TryFrom; - use crate::{ keys::{CoefficientCommitment, VerifiableSecretSharingCommitment}, tests::helpers::generate_element, diff --git a/frost-core/src/traits.rs b/frost-core/src/traits.rs index 4221d96b..b96f27b0 100644 --- a/frost-core/src/traits.rs +++ b/frost-core/src/traits.rs @@ -1,10 +1,11 @@ //! Traits used to abstract Ciphersuites. -use std::{ +use core::{ fmt::Debug, ops::{Add, Mul, Sub}, }; +use alloc::vec::Vec; use rand_core::{CryptoRng, RngCore}; use crate::{Error, FieldError, GroupError, Signature, VerifyingKey}; diff --git a/frost-core/src/verifying_key.rs b/frost-core/src/verifying_key.rs index 2effd05e..8ea63025 100644 --- a/frost-core/src/verifying_key.rs +++ b/frost-core/src/verifying_key.rs @@ -1,4 +1,9 @@ -use std::fmt::{self, Debug}; +use core::fmt::{self, Debug}; + +use alloc::string::ToString; + +#[cfg(any(test, feature = "test-impl"))] +use alloc::vec::Vec; #[cfg(any(test, feature = "test-impl"))] use hex::FromHex; diff --git a/frost-ed25519/Cargo.toml b/frost-ed25519/Cargo.toml index 41276cb7..c90007bb 100644 --- a/frost-ed25519/Cargo.toml +++ b/frost-ed25519/Cargo.toml @@ -25,10 +25,10 @@ rustdoc-args = ["--cfg", "docsrs"] [dependencies] curve25519-dalek = { version = "=4.1.3", 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 = "0.10.2" +sha2 = { version = "0.10.2", default-features = false } [dev-dependencies] criterion = "0.5" @@ -36,7 +36,7 @@ frost-core = { path = "../frost-core", version = "1.0.0", features = ["test-impl frost-rerandomized = { path = "../frost-rerandomized", version = "1.0.0", features = ["test-impl"] } ed25519-dalek = "2.0.0" insta = { version = "1.31.0", features = ["yaml"] } -hex = "0.4.3" +hex = { version = "0.4.3", default-features = false, features = ["alloc"] } lazy_static = "1.4" proptest = "1.0" rand = "0.8" @@ -45,16 +45,18 @@ serde_json = "1.0" [features] nightly = [] -default = ["serialization", "cheater-detection"] +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 cheater detection -cheater-detection = ["frost-core/cheater-detection", "frost-rerandomized/cheater-detection"] ## Enable a default serialization format. Enables `serde`. serialization = ["serde", "frost-core/serialization", "frost-rerandomized/serialization"] +## Enable 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/keys/repairable.rs b/frost-ed25519/src/keys/repairable.rs index deb5a833..5e875a76 100644 --- a/frost-ed25519/src/keys/repairable.rs +++ b/frost-ed25519/src/keys/repairable.rs @@ -4,7 +4,7 @@ //! The RTS is used to help a signer (participant) repair their lost share. This is achieved //! using a subset of the other signers know here as `helpers`. -use std::collections::BTreeMap; +use alloc::collections::BTreeMap; // This is imported separately to make `gencode` work. // (if it were below, the position of the import would vary between ciphersuites diff --git a/frost-ed25519/src/lib.rs b/frost-ed25519/src/lib.rs index c7644edb..355e37a0 100644 --- a/frost-ed25519/src/lib.rs +++ b/frost-ed25519/src/lib.rs @@ -1,3 +1,4 @@ +#![cfg_attr(not(feature = "std"), no_std)] #![allow(non_snake_case)] #![deny(missing_docs)] #![cfg_attr(docsrs, feature(doc_auto_cfg))] @@ -5,7 +6,9 @@ #![doc = include_str!("../README.md")] #![doc = document_features::document_features!()] -use std::collections::BTreeMap; +extern crate alloc; + +use alloc::collections::BTreeMap; use curve25519_dalek::{ constants::ED25519_BASEPOINT_POINT, @@ -23,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. @@ -230,8 +235,6 @@ pub type Identifier = frost::Identifier; /// FROST(Ed25519, SHA-512) keys, key generation, key shares. pub mod keys { - use std::collections::BTreeMap; - use super::*; /// The identifier list to use when generating key shares. diff --git a/frost-ed448/Cargo.toml b/frost-ed448/Cargo.toml index ad8f3cd6..1ee169b3 100644 --- a/frost-ed448/Cargo.toml +++ b/frost-ed448/Cargo.toml @@ -24,10 +24,10 @@ 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 = "0.10.6" +sha3 = { version = "0.10.6", default-features = false } [dev-dependencies] criterion = "0.5" @@ -35,7 +35,7 @@ frost-core = { path = "../frost-core", version = "1.0.0", features = ["test-impl frost-rerandomized = { path = "../frost-rerandomized", version = "1.0.0", features = ["test-impl"] } lazy_static = "1.4" insta = { version = "1.31.0", features = ["yaml"] } -hex = "0.4.3" +hex = { version = "0.4.3", default-features = false, features = ["alloc"] } proptest = "1.0" rand = "0.8" rand_chacha = "0.3" @@ -43,16 +43,18 @@ serde_json = "1.0" [features] nightly = [] -default = ["serialization", "cheater-detection"] +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 cheater detection -cheater-detection = ["frost-core/cheater-detection", "frost-rerandomized/cheater-detection"] ## Enable a default serialization format. Enables `serde`. serialization = ["serde", "frost-core/serialization", "frost-rerandomized/serialization"] +## Enable 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/keys/repairable.rs b/frost-ed448/src/keys/repairable.rs index b44709fc..97771f3c 100644 --- a/frost-ed448/src/keys/repairable.rs +++ b/frost-ed448/src/keys/repairable.rs @@ -4,7 +4,7 @@ //! The RTS is used to help a signer (participant) repair their lost share. This is achieved //! using a subset of the other signers know here as `helpers`. -use std::collections::BTreeMap; +use alloc::collections::BTreeMap; // This is imported separately to make `gencode` work. // (if it were below, the position of the import would vary between ciphersuites diff --git a/frost-ed448/src/lib.rs b/frost-ed448/src/lib.rs index 74a6f10d..f867c494 100644 --- a/frost-ed448/src/lib.rs +++ b/frost-ed448/src/lib.rs @@ -5,6 +5,8 @@ #![doc = include_str!("../README.md")] #![doc = document_features::document_features!()] +extern crate alloc; + use std::collections::BTreeMap; use ed448_goldilocks::{ @@ -24,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 65c3e976..4124d5cd 100644 --- a/frost-p256/Cargo.toml +++ b/frost-p256/Cargo.toml @@ -24,18 +24,18 @@ rustdoc-args = ["--cfg", "docsrs"] [dependencies] document-features = "0.2.7" -p256 = { version = "0.13.0", features = ["hash2curve"] } -frost-core = { path = "../frost-core", version = "1.0.0" } -frost-rerandomized = { path = "../frost-rerandomized", version = "1.0.0" } +p256 = { version = "0.13.0", features = ["hash2curve"], default-features = false } +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 = "0.10.2" +sha2 = { version = "0.10.2", default-features = false } [dev-dependencies] criterion = "0.5" frost-core = { path = "../frost-core", version = "1.0.0", features = ["test-impl"] } frost-rerandomized = { path = "../frost-rerandomized", version = "1.0.0", features = ["test-impl"] } insta = { version = "1.31.0", features = ["yaml"] } -hex = "0.4.3" +hex = { version = "0.4.3", default-features = false, features = ["alloc"] } lazy_static = "1.4" proptest = "1.0" rand = "0.8" @@ -44,16 +44,18 @@ serde_json = "1.0" [features] nightly = [] -default = ["serialization", "cheater-detection"] +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 cheater detection -cheater-detection = ["frost-core/cheater-detection", "frost-rerandomized/cheater-detection"] ## Enable a default serialization format. Enables `serde`. serialization = ["serde", "frost-core/serialization", "frost-rerandomized/serialization"] +## Enable 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/keys/repairable.rs b/frost-p256/src/keys/repairable.rs index 310a26f7..23375745 100644 --- a/frost-p256/src/keys/repairable.rs +++ b/frost-p256/src/keys/repairable.rs @@ -4,7 +4,7 @@ //! The RTS is used to help a signer (participant) repair their lost share. This is achieved //! using a subset of the other signers know here as `helpers`. -use std::collections::BTreeMap; +use alloc::collections::BTreeMap; // This is imported separately to make `gencode` work. // (if it were below, the position of the import would vary between ciphersuites diff --git a/frost-p256/src/lib.rs b/frost-p256/src/lib.rs index cfbf880d..2c54b10f 100644 --- a/frost-p256/src/lib.rs +++ b/frost-p256/src/lib.rs @@ -1,3 +1,4 @@ +#![cfg_attr(not(feature = "std"), no_std)] #![allow(non_snake_case)] #![deny(missing_docs)] #![cfg_attr(docsrs, feature(doc_auto_cfg))] @@ -5,7 +6,10 @@ #![doc = include_str!("../README.md")] #![doc = document_features::document_features!()] -use std::collections::BTreeMap; +extern crate alloc; + +use alloc::borrow::ToOwned; +use alloc::collections::BTreeMap; use frost_rerandomized::RandomizedCiphersuite; use p256::{ @@ -25,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. @@ -246,8 +252,6 @@ type P = P256Sha256; pub type Identifier = frost::Identifier

; /// FROST(P-256, SHA-256) keys, key generation, key shares. pub mod keys { - use std::collections::BTreeMap; - use super::*; /// The identifier list to use when generating key shares. diff --git a/frost-rerandomized/Cargo.toml b/frost-rerandomized/Cargo.toml index fbccc56b..9e910903 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,8 +25,10 @@ rustdoc-args = ["--cfg", "docsrs"] [dependencies] derive-getters = "0.4.0" document-features = "0.2.7" -frost-core = { path = "../frost-core", version = "1.0.0", features = ["internals"] } -hex = "0.4.3" +frost-core = { path = "../frost-core", version = "1.0.0", features = [ + "internals", +], default-features = false } +hex = { version = "0.4.3", default-features = false, features = ["alloc"] } rand_core = "0.6" [dev-dependencies] @@ -32,6 +37,8 @@ rand_core = "0.6" nightly = [] default = ["serialization", "cheater-detection"] #! ## 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`). diff --git a/frost-rerandomized/src/lib.rs b/frost-rerandomized/src/lib.rs index 72d4f7de..174cf0bd 100644 --- a/frost-rerandomized/src/lib.rs +++ b/frost-rerandomized/src/lib.rs @@ -9,20 +9,25 @@ //! - Each participant should call [`sign`] and send the resulting //! [`frost::round2::SignatureShare`] back to the Coordinator; //! - The Coordinator should then call [`aggregate`]. +#![cfg_attr(not(feature = "std"), no_std)] #![allow(non_snake_case)] +extern crate alloc; + #[cfg(any(test, feature = "test-impl"))] pub mod tests; -use std::collections::BTreeMap; +use alloc::{collections::BTreeMap, string::ToString}; 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")] @@ -32,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, @@ -169,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, @@ -179,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, @@ -253,7 +261,7 @@ impl core::fmt::Debug for Randomizer where C: Ciphersuite, { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.debug_tuple("Randomizer") .field(&hex::encode( <::Field>::serialize(&self.0).as_ref(), @@ -279,6 +287,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, @@ -321,7 +330,7 @@ impl core::fmt::Debug for RandomizedParams where C: Ciphersuite, { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.debug_struct("RandomizedParams") .field("randomizer", &self.randomizer) .field( diff --git a/frost-rerandomized/src/tests.rs b/frost-rerandomized/src/tests.rs index 15fde19b..dc923e5c 100644 --- a/frost-rerandomized/src/tests.rs +++ b/frost-rerandomized/src/tests.rs @@ -1,6 +1,8 @@ //! Ciphersuite-generic test functions for re-randomized FROST. -use std::collections::BTreeMap; +use alloc::borrow::ToOwned; +use alloc::collections::BTreeMap; +use alloc::vec::Vec; use crate::{frost_core as frost, RandomizedCiphersuite, RandomizedParams, Randomizer}; use frost_core::{Field, Group, Signature, SigningPackage, VerifyingKey}; diff --git a/frost-ristretto255/Cargo.toml b/frost-ristretto255/Cargo.toml index 05acd6eb..95f28af9 100644 --- a/frost-ristretto255/Cargo.toml +++ b/frost-ristretto255/Cargo.toml @@ -19,19 +19,19 @@ features = ["serde"] rustdoc-args = ["--cfg", "docsrs"] [dependencies] -curve25519-dalek = { version = "=4.1.3", features = ["serde", "rand_core"] } +curve25519-dalek = { version = "=4.1.3", 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 = "0.10.2" +sha2 = { version = "0.10.2", default-features = false } [dev-dependencies] criterion = { version = "0.5", features = ["html_reports"] } frost-core = { path = "../frost-core", version = "1.0.0", features = ["test-impl"] } frost-rerandomized = { path = "../frost-rerandomized", version = "1.0.0", features = ["test-impl"] } insta = { version = "1.31.0", features = ["yaml"] } -hex = "0.4.3" +hex = { version = "0.4.3", default-features = false, features = ["alloc"] } lazy_static = "1.4" postcard = { version = "1.0.0", features = ["use-std"] } proptest = "1.0" @@ -41,16 +41,18 @@ serde_json = "1.0" [features] nightly = [] -default = ["serialization", "cheater-detection"] +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 cheater detection -cheater-detection = ["frost-core/cheater-detection", "frost-rerandomized/cheater-detection"] +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", "frost-rerandomized/cheater-detection"] [lib] # Disables non-criterion benchmark which is not used; prevents errors diff --git a/frost-ristretto255/src/keys/repairable.rs b/frost-ristretto255/src/keys/repairable.rs index a303828d..a935eb8a 100644 --- a/frost-ristretto255/src/keys/repairable.rs +++ b/frost-ristretto255/src/keys/repairable.rs @@ -4,7 +4,7 @@ //! The RTS is used to help a signer (participant) repair their lost share. This is achieved //! using a subset of the other signers know here as `helpers`. -use std::collections::BTreeMap; +use alloc::collections::BTreeMap; // This is imported separately to make `gencode` work. // (if it were below, the position of the import would vary between ciphersuites diff --git a/frost-ristretto255/src/lib.rs b/frost-ristretto255/src/lib.rs index d402c917..f6a608c4 100644 --- a/frost-ristretto255/src/lib.rs +++ b/frost-ristretto255/src/lib.rs @@ -1,8 +1,11 @@ +#![cfg_attr(not(feature = "std"), no_std)] #![allow(non_snake_case)] #![deny(missing_docs)] #![doc = include_str!("../README.md")] -use std::collections::BTreeMap; +extern crate alloc; + +use alloc::collections::BTreeMap; use curve25519_dalek::{ constants::RISTRETTO_BASEPOINT_POINT, @@ -20,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. @@ -217,7 +222,6 @@ pub type Identifier = frost::Identifier; /// FROST(ristretto255, SHA-512) keys, key generation, key shares. pub mod keys { use super::*; - use std::collections::BTreeMap; /// The identifier list to use when generating key shares. pub type IdentifierList<'a> = frost::keys::IdentifierList<'a, R>; diff --git a/frost-secp256k1/Cargo.toml b/frost-secp256k1/Cargo.toml index e19df4bf..a7bf2ebf 100644 --- a/frost-secp256k1/Cargo.toml +++ b/frost-secp256k1/Cargo.toml @@ -23,18 +23,18 @@ 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" } -k256 = { version = "0.13.0", features = ["arithmetic", "expose-field", "hash2curve"] } +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 = "0.10.2" +sha2 = { version = "0.10.2", default-features = false } [dev-dependencies] criterion = "0.5" frost-core = { path = "../frost-core", version = "1.0.0", features = ["test-impl"] } frost-rerandomized = { path = "../frost-rerandomized", version = "1.0.0", features = ["test-impl"] } insta = { version = "1.31.0", features = ["yaml"] } -hex = "0.4.3" +hex = { version = "0.4.3", default-features = false, features = ["alloc"] } lazy_static = "1.4" proptest = "1.0" rand = "0.8" @@ -43,16 +43,18 @@ serde_json = "1.0" [features] nightly = [] -default = ["serialization", "cheater-detection"] +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 cheater detection -cheater-detection = ["frost-core/cheater-detection", "frost-rerandomized/cheater-detection"] ## Enable a default serialization format. Enables `serde`. serialization = ["serde", "frost-core/serialization", "frost-rerandomized/serialization"] +## Enable 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/keys/repairable.rs b/frost-secp256k1/src/keys/repairable.rs index 01bb964d..88bce01d 100644 --- a/frost-secp256k1/src/keys/repairable.rs +++ b/frost-secp256k1/src/keys/repairable.rs @@ -4,7 +4,7 @@ //! The RTS is used to help a signer (participant) repair their lost share. This is achieved //! using a subset of the other signers know here as `helpers`. -use std::collections::BTreeMap; +use alloc::collections::BTreeMap; // This is imported separately to make `gencode` work. // (if it were below, the position of the import would vary between ciphersuites diff --git a/frost-secp256k1/src/lib.rs b/frost-secp256k1/src/lib.rs index 3ddd5ecf..1ebeaedb 100644 --- a/frost-secp256k1/src/lib.rs +++ b/frost-secp256k1/src/lib.rs @@ -1,3 +1,4 @@ +#![cfg_attr(not(feature = "std"), no_std)] #![allow(non_snake_case)] #![deny(missing_docs)] #![cfg_attr(docsrs, feature(doc_auto_cfg))] @@ -5,7 +6,10 @@ #![doc = include_str!("../README.md")] #![doc = document_features::document_features!()] -use std::collections::BTreeMap; +extern crate alloc; + +use alloc::borrow::ToOwned; +use alloc::collections::BTreeMap; use frost_rerandomized::RandomizedCiphersuite; use k256::{ @@ -26,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. @@ -247,7 +253,6 @@ pub type Identifier = frost::Identifier; /// FROST(secp256k1, SHA-256) keys, key generation, key shares. pub mod keys { use super::*; - use std::collections::BTreeMap; /// The identifier list to use when generating key shares. pub type IdentifierList<'a> = frost::keys::IdentifierList<'a, S>;