diff --git a/Cargo.lock b/Cargo.lock index ff115de1..1e9647df 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,18 +2,6 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "ahash" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" -dependencies = [ - "cfg-if", - "once_cell", - "version_check", - "zerocopy", -] - [[package]] name = "aho-corasick" version = "1.1.3" @@ -84,12 +72,6 @@ dependencies = [ "windows-sys", ] -[[package]] -name = "anyhow" -version = "1.0.86" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" - [[package]] name = "arbitrary" version = "1.3.2" @@ -172,12 +154,12 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chia-bls" -version = "0.10.0" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "725b43b268cb81f014559eed11a74d0e5b9dd55282cae272ff509796099ab0b9" +checksum = "53dea95bd7dac1e69c59ef6839ecf30ff3fe29170c16c4aa00093be21e0d789e" dependencies = [ - "anyhow", "blst", + "chia-sha2", "chia-traits", "hex", "hkdf", @@ -186,27 +168,37 @@ dependencies = [ "thiserror", ] +[[package]] +name = "chia-sha2" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7020f53eeae8b4c24c5666165738173a167c6478e0c0a9e1c428a491a2e1383d" +dependencies = [ + "openssl", + "sha2", +] + [[package]] name = "chia-traits" -version = "0.10.0" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fb786114e5c748fe0af3ba1e95840fa1910b28f7300c05184506045aff60bb6" +checksum = "e57bbde886b38a9a5df185e751d90e295d14e99659bf43df7fa701d52d4da1ea" dependencies = [ + "chia-sha2", "chia_streamable_macro", - "sha2", "thiserror", ] [[package]] name = "chia_streamable_macro" -version = "0.10.0" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43975e01fb4293021af4950366a6f80c45d7301d499622359c7533bd7af19592" +checksum = "00e78b5981952d2383b08344fdc6e6f843e72cc9d502d46d1d2824c485b34694" dependencies = [ "proc-macro-crate 1.3.1", "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -267,7 +259,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -327,6 +319,7 @@ name = "clvmr" version = "0.10.0" dependencies = [ "chia-bls", + "chia-sha2", "criterion", "hex", "hex-literal", @@ -335,10 +328,8 @@ dependencies = [ "num-bigint", "num-integer", "num-traits", - "openssl", "p256", "rstest", - "sha2", "sha3", ] @@ -552,6 +543,12 @@ dependencies = [ "subtle", ] +[[package]] +name = "foldhash" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f81ec6369c545a7d40e4589b5597581fa1c441fe1cce96dd1de43159910a36a2" + [[package]] name = "foreign-types" version = "0.3.2" @@ -623,7 +620,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -718,9 +715,16 @@ name = "hashbrown" version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" + +[[package]] +name = "hashbrown" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a9bfc1af68b1726ea47d3d5109de126281def866b33970e10fbab11b5dafab3" dependencies = [ - "ahash", "allocator-api2", + "equivalent", + "foldhash", ] [[package]] @@ -772,7 +776,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" dependencies = [ "equivalent", - "hashbrown", + "hashbrown 0.14.5", ] [[package]] @@ -895,11 +899,11 @@ checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" [[package]] name = "lru" -version = "0.12.3" +version = "0.12.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3262e75e648fce39813cb56ac41f3c3e3f65217ebf3844d818d1f9398cfb0dc" +checksum = "234cf4f4a04dc1f57e24b96cc0cd600cf2af460d4161ac5ecdd0af8e1f3b2a38" dependencies = [ - "hashbrown", + "hashbrown 0.15.1", ] [[package]] @@ -1000,16 +1004,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", -] - -[[package]] -name = "openssl-src" -version = "300.3.1+3.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7259953d42a81bf137fbbd73bd30a8e1914d6dce43c2b90ed575783a22608b91" -dependencies = [ - "cc", + "syn 2.0.87", ] [[package]] @@ -1020,7 +1015,6 @@ checksum = "45abf306cbf99debc8195b66b7346498d7b10c210de50418b5ccd7ceba08c741" dependencies = [ "cc", "libc", - "openssl-src", "pkg-config", "vcpkg", ] @@ -1070,9 +1064,9 @@ dependencies = [ [[package]] name = "pkg-config" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" [[package]] name = "plotters" @@ -1198,7 +1192,7 @@ dependencies = [ "proc-macro2", "pyo3-macros-backend", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -1211,7 +1205,7 @@ dependencies = [ "proc-macro2", "pyo3-build-config", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -1344,7 +1338,7 @@ dependencies = [ "regex", "relative-path", "rustc_version", - "syn 2.0.85", + "syn 2.0.87", "unicode-ident", ] @@ -1415,7 +1409,7 @@ checksum = "de523f781f095e28fa605cdce0f8307e451cc0fd14e2eb4cd2e98a355b147766" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -1516,9 +1510,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.85" +version = "2.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5023162dfcd14ef8f32034d8bcd4cc5ddc61ef7a247c024a33e24e1f24d21b56" +checksum = "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d" dependencies = [ "proc-macro2", "quote", @@ -1533,22 +1527,22 @@ checksum = "4873307b7c257eddcb50c9bedf158eb669578359fb28428bef438fec8e6ba7c2" [[package]] name = "thiserror" -version = "1.0.61" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.61" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -1672,7 +1666,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", "wasm-bindgen-shared", ] @@ -1706,7 +1700,7 @@ checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -1740,7 +1734,7 @@ checksum = "4b8220be1fa9e4c889b30fd207d4906657e7e90b12e0e6b0c8b8d8709f5de021" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] [[package]] @@ -1844,26 +1838,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "zerocopy" -version = "0.7.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" -dependencies = [ - "zerocopy-derive", -] - -[[package]] -name = "zerocopy-derive" -version = "0.7.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.85", -] - [[package]] name = "zeroize" version = "1.8.1" @@ -1881,5 +1855,5 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.85", + "syn 2.0.87", ] diff --git a/Cargo.toml b/Cargo.toml index 027684c6..24d28393 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,8 +27,8 @@ counters = [] pre-eval = [] # On UNIX-based platforms, you may get a speed boost on `sha256` operations by building -# with OpenSSL.when enabled -openssl = ["dep:openssl"] +# with OpenSSL when enabled +openssl = ["chia-sha2/openssl"] [profile.release] lto = "thin" @@ -39,9 +39,8 @@ lazy_static = "1.5.0" num-bigint = "0.4.6" num-traits = "0.2.19" num-integer = "0.1.46" -chia-bls = "0.10.0" -sha2 = "0.10.8" -openssl = "0.10.68" +chia-bls = "0.15.0" +chia-sha2 = "0.15.0" hex-literal = "0.4.1" # for secp sigs k256 = "0.13.4" @@ -69,8 +68,7 @@ num-bigint = { workspace = true } num-traits = { workspace = true } num-integer = { workspace = true } chia-bls = { workspace = true } -sha2 = { workspace = true } -openssl = { workspace = true, features = ["vendored"], optional = true } +chia-sha2 = { workspace = true } hex-literal = { workspace = true } # for secp sigs k256 = { version = "0.13.4", features = ["ecdsa"] } diff --git a/benches/sha256_hash.rs b/benches/sha256_hash.rs index 25ba3a3c..68aedd76 100644 --- a/benches/sha256_hash.rs +++ b/benches/sha256_hash.rs @@ -1,6 +1,6 @@ use criterion::{criterion_group, criterion_main, Criterion}; -use clvmr::sha2::Sha256; +use chia_sha2::Sha256; const BYTE_LENGTHS: [u8; 6] = [8, 16, 32, 64, 96, 128]; const MAX_VAL: u8 = 250; diff --git a/src/lib.rs b/src/lib.rs index a57aec48..5a3aca19 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,7 +15,6 @@ pub mod run_program; pub mod runtime_dialect; pub mod secp_ops; pub mod serde; -pub mod sha2; pub mod traverse_path; pub use allocator::{Allocator, Atom, NodePtr, SExp}; diff --git a/src/more_ops.rs b/src/more_ops.rs index 7e72a6e4..b10d3e67 100644 --- a/src/more_ops.rs +++ b/src/more_ops.rs @@ -14,8 +14,8 @@ use crate::op_utils::{ new_atom_and_cost, nilp, u32_from_u8, MALLOC_COST_PER_BYTE, }; use crate::reduction::{Reduction, Response}; -use crate::sha2::Sha256; use chia_bls::G1Element; +use chia_sha2::Sha256; const ARITH_BASE_COST: Cost = 99; const ARITH_COST_PER_ARG: Cost = 320; diff --git a/src/serde/bytes32.rs b/src/serde/bytes32.rs index f6a2e593..3254cf37 100644 --- a/src/serde/bytes32.rs +++ b/src/serde/bytes32.rs @@ -1,4 +1,4 @@ -use crate::sha2::Sha256; +use chia_sha2::Sha256; pub type Bytes32 = [u8; 32]; diff --git a/src/serde/de_tree.rs b/src/serde/de_tree.rs index d645df09..be189228 100644 --- a/src/serde/de_tree.rs +++ b/src/serde/de_tree.rs @@ -1,6 +1,6 @@ use std::io::{Error, Read, Result, Write}; -use crate::sha2::Sha256; +use chia_sha2::Sha256; use super::parse_atom::decode_size_with_offset; use super::utils::{copy_exactly, skip_bytes}; diff --git a/src/serde/tools.rs b/src/serde/tools.rs index 820caf52..2df3fd15 100644 --- a/src/serde/tools.rs +++ b/src/serde/tools.rs @@ -45,7 +45,7 @@ pub fn serialized_length_from_bytes_trusted(b: &[u8]) -> io::Result { Ok(f.position()) } -use crate::sha2::Sha256; +use chia_sha2::Sha256; fn hash_atom(buf: &[u8]) -> [u8; 32] { let mut ctx = Sha256::new(); diff --git a/src/sha2.rs b/src/sha2.rs deleted file mode 100644 index 15738958..00000000 --- a/src/sha2.rs +++ /dev/null @@ -1,64 +0,0 @@ -#[cfg(feature = "openssl")] -use openssl; - -#[cfg(not(feature = "openssl"))] -use sha2::Digest; - -#[derive(Default, Clone)] -pub struct Sha256 { - #[cfg(feature = "openssl")] - ctx: openssl::sha::Sha256, - - #[cfg(not(feature = "openssl"))] - ctx: sha2::Sha256, -} - -impl Sha256 { - pub fn new() -> Self { - Self::default() - } - pub fn update(&mut self, buf: impl AsRef<[u8]>) { - self.ctx.update(buf.as_ref()); - } - pub fn finalize(self) -> [u8; 32] { - #[cfg(feature = "openssl")] - { - self.ctx.finish() - } - #[cfg(not(feature = "openssl"))] - { - self.ctx.finalize().into() - } - } -} - -#[test] -fn test_sha256() { - // https://www.di-mgt.com.au/sha_testvectors.html - - let output = &[ - 0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, 0x41, 0x41, 0x40, 0xde, 0x5d, 0xae, 0x22, - 0x23, 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, 0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, - 0x15, 0xad, - ]; - - let mut ctx = Sha256::new(); - ctx.update([0x61, 0x62, 0x63]); - assert_eq!(&ctx.finalize().as_slice(), output); - - let mut ctx = Sha256::new(); - ctx.update([0x61]); - ctx.update([0x62]); - ctx.update([0x63]); - assert_eq!(&ctx.finalize().as_slice(), output); - - let mut ctx = Sha256::new(); - ctx.update([0x61, 0x62]); - ctx.update([0x63]); - assert_eq!(&ctx.finalize().as_slice(), output); - - let mut ctx = Sha256::new(); - ctx.update([0x61]); - ctx.update([0x62, 0x63]); - assert_eq!(&ctx.finalize().as_slice(), output); -}