diff --git a/.github/workflows/no-std.yml b/.github/workflows/no-std.yml index fa39690a..a21f8e80 100644 --- a/.github/workflows/no-std.yml +++ b/.github/workflows/no-std.yml @@ -32,4 +32,6 @@ jobs: run: sudo apt update && sudo apt install -y gcc-riscv64-unknown-elf gcc-multilib && rustup target add riscv32imac-unknown-none-elf - name: Verify no-std builds - run: CFLAGS=-I/usr/include cargo build --target riscv32imac-unknown-none-elf -p serai-no-std-tests + run: | + CFLAGS=-I/usr/include cargo +nightly build --target riscv32imac-unknown-none-elf -Z build-std=core -p serai-no-std-tests + CFLAGS=-I/usr/include cargo +nightly build --target riscv32imac-unknown-none-elf -Z build-std=core,alloc -p serai-no-std-tests --features "alloc" diff --git a/Cargo.lock b/Cargo.lock index 02cae007..e8e1ecdb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3280,7 +3280,6 @@ dependencies = [ "digest 0.10.7", "merlin", "sha2 0.10.9", - "std-shims", "zeroize", ] diff --git a/crypto/ciphersuite/Cargo.toml b/crypto/ciphersuite/Cargo.toml index 39217a49..dad7350c 100644 --- a/crypto/ciphersuite/Cargo.toml +++ b/crypto/ciphersuite/Cargo.toml @@ -7,7 +7,7 @@ repository = "https://github.com/serai-dex/serai/tree/develop/crypto/ciphersuite authors = ["Luke Parker "] keywords = ["ciphersuite", "ff", "group"] edition = "2021" -rust-version = "1.66" +rust-version = "1.73" [package.metadata.docs.rs] all-features = true diff --git a/crypto/dalek-ff-group/Cargo.toml b/crypto/dalek-ff-group/Cargo.toml index 953cb5fc..0b35bcfb 100644 --- a/crypto/dalek-ff-group/Cargo.toml +++ b/crypto/dalek-ff-group/Cargo.toml @@ -7,7 +7,7 @@ repository = "https://github.com/serai-dex/serai/tree/develop/crypto/dalek-ff-gr authors = ["Luke Parker "] keywords = ["curve25519", "ed25519", "ristretto", "dalek", "group"] edition = "2021" -rust-version = "1.66" +rust-version = "1.73" [package.metadata.docs.rs] all-features = true @@ -33,7 +33,7 @@ ciphersuite = { path = "../ciphersuite", default-features = false } crypto-bigint = { version = "0.5", default-features = false, features = ["zeroize"] } -curve25519-dalek = { version = ">= 4.0, < 4.2", default-features = false, features = ["alloc", "zeroize", "digest", "group", "precomputed-tables"] } +curve25519-dalek = { version = ">= 4.0, < 4.2", default-features = false, features = ["zeroize", "digest", "group", "precomputed-tables"] } [dev-dependencies] hex = "0.4" @@ -41,6 +41,6 @@ rand_core = { version = "0.6", default-features = false, features = ["std"] } ff-group-tests = { path = "../ff-group-tests" } [features] -alloc = ["zeroize/alloc", "ciphersuite/alloc"] +alloc = ["zeroize/alloc", "ciphersuite/alloc", "curve25519-dalek/alloc"] std = ["alloc", "zeroize/std", "subtle/std", "rand_core/std", "digest/std", "sha2/std", "ciphersuite/std"] default = ["std"] diff --git a/crypto/dalek-ff-group/src/ciphersuite.rs b/crypto/dalek-ff-group/src/ciphersuite.rs index 4d585423..f552d305 100644 --- a/crypto/dalek-ff-group/src/ciphersuite.rs +++ b/crypto/dalek-ff-group/src/ciphersuite.rs @@ -29,7 +29,10 @@ macro_rules! dalek_curve { } fn hash_to_F(dst: &[u8], data: &[u8]) -> Self::F { - Scalar::from_hash(Sha512::new_with_prefix(&[dst, data].concat())) + let mut digest = Sha512::new(); + digest.update(dst); + digest.update(data); + Scalar::from_hash(digest) } } }; diff --git a/crypto/dkg/Cargo.toml b/crypto/dkg/Cargo.toml index 80b89ca9..87f1e1b4 100644 --- a/crypto/dkg/Cargo.toml +++ b/crypto/dkg/Cargo.toml @@ -7,7 +7,7 @@ repository = "https://github.com/serai-dex/serai/tree/develop/crypto/dkg" authors = ["Luke Parker "] keywords = ["dkg", "multisig", "threshold", "ff", "group"] edition = "2021" -rust-version = "1.66" +rust-version = "1.73" [package.metadata.docs.rs] all-features = true diff --git a/crypto/dkg/dealer/Cargo.toml b/crypto/dkg/dealer/Cargo.toml index 0b1b81bf..78b37167 100644 --- a/crypto/dkg/dealer/Cargo.toml +++ b/crypto/dkg/dealer/Cargo.toml @@ -7,7 +7,7 @@ repository = "https://github.com/serai-dex/serai/tree/develop/crypto/dkg/dealer" authors = ["Luke Parker "] keywords = ["dkg", "multisig", "threshold", "ff", "group"] edition = "2021" -rust-version = "1.66" +rust-version = "1.73" [package.metadata.docs.rs] all-features = true diff --git a/crypto/dkg/recovery/Cargo.toml b/crypto/dkg/recovery/Cargo.toml index db09125b..9c85d701 100644 --- a/crypto/dkg/recovery/Cargo.toml +++ b/crypto/dkg/recovery/Cargo.toml @@ -7,7 +7,7 @@ repository = "https://github.com/serai-dex/serai/tree/develop/crypto/dkg/recover authors = ["Luke Parker "] keywords = ["dkg", "multisig", "threshold", "ff", "group"] edition = "2021" -rust-version = "1.66" +rust-version = "1.73" [package.metadata.docs.rs] all-features = true diff --git a/crypto/ed448/src/ciphersuite.rs b/crypto/ed448/src/ciphersuite.rs index 6b930ee3..1ffcd0f7 100644 --- a/crypto/ed448/src/ciphersuite.rs +++ b/crypto/ed448/src/ciphersuite.rs @@ -71,7 +71,11 @@ impl Ciphersuite for Ed448 { } fn hash_to_F(dst: &[u8], data: &[u8]) -> Self::F { - let digest = Self::H::digest([dst, data].concat()); + let mut digest = Self::H::new(); + Update::update(&mut digest, dst); + Update::update(&mut digest, data); + let digest = digest.finalize(); + let mut wide_scalar = [0; 114]; wide_scalar.copy_from_slice(digest.as_ref()); Scalar::from_uniform_bytes(&wide_scalar) diff --git a/crypto/embedwards25519/src/lib.rs b/crypto/embedwards25519/src/lib.rs index 70162c38..c5811e2f 100644 --- a/crypto/embedwards25519/src/lib.rs +++ b/crypto/embedwards25519/src/lib.rs @@ -94,9 +94,10 @@ impl ciphersuite::Ciphersuite for Embedwards25519 { /// substrings of each other. fn hash_to_F(dst: &[u8], data: &[u8]) -> Self::F { use blake2::Digest; - >::from_uniform_bytes( - &Self::H::digest([dst, data].concat()).into(), - ) + let mut digest = Self::H::new(); + digest.update(dst); + digest.update(data); + >::from_uniform_bytes(&digest.finalize().into()) } // We override the provided impl, which compares against the reserialization, because diff --git a/crypto/secq256k1/src/lib.rs b/crypto/secq256k1/src/lib.rs index 1f62dedb..2f0a49ff 100644 --- a/crypto/secq256k1/src/lib.rs +++ b/crypto/secq256k1/src/lib.rs @@ -127,9 +127,10 @@ impl ciphersuite::Ciphersuite for Secq256k1 { /// substrings of each other. fn hash_to_F(dst: &[u8], data: &[u8]) -> Self::F { use blake2::Digest; - >::from_uniform_bytes( - &Self::H::digest([dst, data].concat()).into(), - ) + let mut digest = Self::H::new(); + digest.update(dst); + digest.update(data); + >::from_uniform_bytes(&digest.finalize().into()) } // We override the provided impl, which compares against the reserialization, because diff --git a/crypto/transcript/Cargo.toml b/crypto/transcript/Cargo.toml index dc8b340d..11daed9e 100644 --- a/crypto/transcript/Cargo.toml +++ b/crypto/transcript/Cargo.toml @@ -7,7 +7,7 @@ repository = "https://github.com/serai-dex/serai/tree/develop/crypto/transcript" authors = ["Luke Parker "] keywords = ["transcript"] edition = "2021" -rust-version = "1.66" +rust-version = "1.73" [package.metadata.docs.rs] all-features = true @@ -17,8 +17,6 @@ rustdoc-args = ["--cfg", "docsrs"] workspace = true [dependencies] -std-shims = { path = "../../common/std-shims", version = "0.1.4", default-features = false } - zeroize = { version = "^1.5", default-features = false } digest = { version = "0.10", default-features = false, features = ["core-api"] } @@ -31,7 +29,7 @@ sha2 = { version = "0.10", default-features = false } blake2 = { version = "0.10", default-features = false } [features] -std = ["std-shims/std", "zeroize/std", "digest/std", "blake2?/std", "merlin?/std"] +std = ["zeroize/std", "digest/std", "blake2?/std", "merlin?/std"] recommended = ["blake2"] tests = [] default = ["std"] diff --git a/crypto/transcript/src/lib.rs b/crypto/transcript/src/lib.rs index 988ab039..4dc8ad1b 100644 --- a/crypto/transcript/src/lib.rs +++ b/crypto/transcript/src/lib.rs @@ -2,9 +2,6 @@ #![doc = include_str!("../README.md")] #![no_std] -#[allow(unused_imports)] -use std_shims::prelude::*; - use zeroize::Zeroize; use digest::{ diff --git a/processor/monero/Cargo.toml b/processor/monero/Cargo.toml index d2be0ae8..49b79814 100644 --- a/processor/monero/Cargo.toml +++ b/processor/monero/Cargo.toml @@ -8,7 +8,6 @@ authors = ["Luke Parker "] keywords = [] edition = "2021" publish = false -rust-version = "1.56" [package.metadata.docs.rs] all-features = true diff --git a/processor/view-keys/Cargo.toml b/processor/view-keys/Cargo.toml index a1147e27..7af10d99 100644 --- a/processor/view-keys/Cargo.toml +++ b/processor/view-keys/Cargo.toml @@ -7,7 +7,7 @@ repository = "https://github.com/serai-dex/serai/tree/develop/processor/view-key authors = ["Luke Parker "] keywords = [] edition = "2021" -rust-version = "1.66" +rust-version = "1.73" [package.metadata.docs.rs] all-features = true diff --git a/tests/no-std/Cargo.toml b/tests/no-std/Cargo.toml index 00fe08d8..1988cdcc 100644 --- a/tests/no-std/Cargo.toml +++ b/tests/no-std/Cargo.toml @@ -19,23 +19,45 @@ workspace = true [dependencies] flexible-transcript = { path = "../../crypto/transcript", default-features = false, features = ["recommended", "merlin"] } +multiexp = { path = "../../crypto/multiexp", default-features = false, features = ["batch"], optional = true } + dalek-ff-group = { path = "../../crypto/dalek-ff-group", default-features = false } minimal-ed448 = { path = "../../crypto/ed448", default-features = false } -ciphersuite = { path = "../../crypto/ciphersuite", default-features = false, features = ["alloc"] } +ciphersuite = { path = "../../crypto/ciphersuite", default-features = false } -multiexp = { path = "../../crypto/multiexp", default-features = false, features = ["batch"] } +schnorr-signatures = { path = "../../crypto/schnorr", default-features = false, optional = true } -schnorr-signatures = { path = "../../crypto/schnorr", default-features = false } - -prime-field = { path = "../../crypto/prime-field", default-features = false, features = ["alloc"] } -short-weierstrass = { path = "../../crypto/short-weierstrass", default-features = false, features = ["alloc"] } +prime-field = { path = "../../crypto/prime-field", default-features = false } +short-weierstrass = { path = "../../crypto/short-weierstrass", default-features = false } secq256k1 = { path = "../../crypto/secq256k1", default-features = false } embedwards25519 = { path = "../../crypto/embedwards25519", default-features = false } -dkg = { path = "../../crypto/dkg", default-features = false } -dkg-evrf = { path = "../../crypto/dkg/evrf", default-features = false } +dkg = { path = "../../crypto/dkg", default-features = false, optional = true } +dkg-evrf = { path = "../../crypto/dkg/evrf", default-features = false, features = ["secp256k1", "ed25519", "ristretto"], optional = true } # modular-frost = { path = "../../crypto/frost", default-features = false } # frost-schnorrkel = { path = "../../crypto/schnorrkel", default-features = false } -bitcoin-serai = { path = "../../networks/bitcoin", default-features = false, features = ["hazmat"] } +bitcoin-serai = { path = "../../networks/bitcoin", default-features = false, features = ["hazmat"], optional = true } + +[features] +alloc = [ + "multiexp", + + "dalek-ff-group/alloc", + "minimal-ed448/alloc", + + "ciphersuite/alloc", + + "schnorr-signatures", + + "prime-field/alloc", + "short-weierstrass/alloc", + "secq256k1/alloc", + "embedwards25519/alloc", + + "dkg", + "dkg-evrf", + + "bitcoin-serai", +] diff --git a/tests/no-std/src/lib.rs b/tests/no-std/src/lib.rs index b567f019..805f52a4 100644 --- a/tests/no-std/src/lib.rs +++ b/tests/no-std/src/lib.rs @@ -7,20 +7,22 @@ pub use minimal_ed448; pub use ciphersuite; -pub use multiexp; - -pub use schnorr_signatures; - pub use prime_field; pub use short_weierstrass; pub use secq256k1; pub use embedwards25519; - -pub use dkg; -pub use dkg_evrf; /* pub use modular_frost; pub use frost_schnorrkel; */ -pub use bitcoin_serai; +#[cfg(feature = "alloc")] +pub mod alloc { + pub use multiexp; + pub use schnorr_signatures; + + pub use dkg; + pub use dkg_evrf; + + pub use bitcoin_serai; +}