From 3b4359f1418c533077e549781eecac4ef5fada05 Mon Sep 17 00:00:00 2001 From: Jonas Schneider-Bensch Date: Tue, 23 Jul 2024 15:12:37 +0200 Subject: [PATCH 1/5] Benchmark setup for HACL-rs curve25519 --- Cargo.lock | 71 +++++++++++++++++------------ libcrux-ecdh/Cargo.toml | 9 ++++ libcrux-ecdh/benches/curve25519.rs | 18 ++++++++ libcrux-ecdh/src/ecdh.rs | 2 +- libcrux-ecdh/src/hacl.rs | 2 +- libcrux-ecdh/src/hacl/curve25519.rs | 35 ++++++++++++++ 6 files changed, 107 insertions(+), 30 deletions(-) create mode 100644 libcrux-ecdh/benches/curve25519.rs diff --git a/Cargo.lock b/Cargo.lock index acfd79326..4644b7378 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -143,7 +143,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.71", + "syn 2.0.72", "which", ] @@ -191,9 +191,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.1.5" +version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "324c74f2155653c90b04f25b2a47a8a631360cb908f92a772695f430c7e31052" +checksum = "2aba8f4e9906c7ce3c73463f62a7f0c65183ada1a2d47e397cc8810827f9694f" dependencies = [ "jobserver", "libc", @@ -318,7 +318,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -482,7 +482,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -688,6 +688,14 @@ dependencies = [ "subtle", ] +[[package]] +name = "hacl-rs" +version = "0.1.0" +source = "git+https://github.com/hacl-star/hacl-star.git?branch=afromher_rs#e83275b78cb4144254b2097fe36e6d2602f87cd7" +dependencies = [ + "krml", +] + [[package]] name = "half" version = "2.4.1" @@ -701,7 +709,7 @@ dependencies = [ [[package]] name = "hax-lib" version = "0.1.0-pre.1" -source = "git+https://github.com/hacspec/hax/?branch=main#09a454ceb09d9d3eb05424830c9c6b52b475dc40" +source = "git+https://github.com/hacspec/hax/?branch=main#cd6e258cb2fbc65b97901092b07bfdee02fe4808" dependencies = [ "hax-lib-macros 0.1.0-pre.1 (git+https://github.com/hacspec/hax/?branch=main)", "num-bigint", @@ -711,7 +719,7 @@ dependencies = [ [[package]] name = "hax-lib" version = "0.1.0-pre.1" -source = "git+https://github.com/hacspec/hax/#09a454ceb09d9d3eb05424830c9c6b52b475dc40" +source = "git+https://github.com/hacspec/hax/#cd6e258cb2fbc65b97901092b07bfdee02fe4808" dependencies = [ "hax-lib-macros 0.1.0-pre.1 (git+https://github.com/hacspec/hax/)", "num-bigint", @@ -721,31 +729,31 @@ dependencies = [ [[package]] name = "hax-lib-macros" version = "0.1.0-pre.1" -source = "git+https://github.com/hacspec/hax/?branch=main#09a454ceb09d9d3eb05424830c9c6b52b475dc40" +source = "git+https://github.com/hacspec/hax/?branch=main#cd6e258cb2fbc65b97901092b07bfdee02fe4808" dependencies = [ "hax-lib-macros-types 0.1.0-pre.1 (git+https://github.com/hacspec/hax/?branch=main)", "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] name = "hax-lib-macros" version = "0.1.0-pre.1" -source = "git+https://github.com/hacspec/hax/#09a454ceb09d9d3eb05424830c9c6b52b475dc40" +source = "git+https://github.com/hacspec/hax/#cd6e258cb2fbc65b97901092b07bfdee02fe4808" dependencies = [ "hax-lib-macros-types 0.1.0-pre.1 (git+https://github.com/hacspec/hax/)", "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] name = "hax-lib-macros-types" version = "0.1.0-pre.1" -source = "git+https://github.com/hacspec/hax/?branch=main#09a454ceb09d9d3eb05424830c9c6b52b475dc40" +source = "git+https://github.com/hacspec/hax/?branch=main#cd6e258cb2fbc65b97901092b07bfdee02fe4808" dependencies = [ "proc-macro2", "quote", @@ -757,7 +765,7 @@ dependencies = [ [[package]] name = "hax-lib-macros-types" version = "0.1.0-pre.1" -source = "git+https://github.com/hacspec/hax/#09a454ceb09d9d3eb05424830c9c6b52b475dc40" +source = "git+https://github.com/hacspec/hax/#cd6e258cb2fbc65b97901092b07bfdee02fe4808" dependencies = [ "proc-macro2", "quote", @@ -897,6 +905,11 @@ dependencies = [ "cpufeatures", ] +[[package]] +name = "krml" +version = "0.1.0" +source = "git+https://github.com/hacl-star/hacl-star.git?branch=afromher_rs#e83275b78cb4144254b2097fe36e6d2602f87cd7" + [[package]] name = "lazy_static" version = "1.5.0" @@ -958,6 +971,8 @@ dependencies = [ name = "libcrux-ecdh" version = "0.0.2-alpha.3" dependencies = [ + "criterion", + "hacl-rs", "hex", "libcrux-hacl", "pretty_env_logger", @@ -1115,9 +1130,9 @@ dependencies = [ [[package]] name = "libloading" -version = "0.8.4" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e310b3a6b5907f99202fcdb4960ff45b93735d7c7d96b760fcff8db2dc0e103d" +checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" dependencies = [ "cfg-if", "windows-targets", @@ -1205,9 +1220,9 @@ checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" [[package]] name = "openssl" -version = "0.10.64" +version = "0.10.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95a0481286a310808298130d22dd1fef0fa571e05a8f44ec801801e84b216b1f" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" dependencies = [ "bitflags", "cfg-if", @@ -1226,14 +1241,14 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] name = "openssl-sys" -version = "0.9.102" +version = "0.9.103" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c597637d56fbc83893a35eb0dd04b2b8e7a50c91e64e9493e398b5df4fb45fa2" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" dependencies = [ "cc", "libc", @@ -1384,7 +1399,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5f12335488a2f3b0a83b14edad48dca9879ce89b2edd10e80237e4e852dd645e" dependencies = [ "proc-macro2", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -1650,7 +1665,7 @@ checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222" dependencies = [ "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -1748,9 +1763,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.71" +version = "2.0.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b146dcf730474b4bcd16c311627b31ede9ab149045db4d6088b3becaea046462" +checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" dependencies = [ "proc-macro2", "quote", @@ -1868,7 +1883,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", "wasm-bindgen-shared", ] @@ -1902,7 +1917,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -1935,7 +1950,7 @@ checksum = "b7f89739351a2e03cb94beb799d47fb2cac01759b40ec441f7de39b00cbf7ef0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -2083,5 +2098,5 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", ] diff --git a/libcrux-ecdh/Cargo.toml b/libcrux-ecdh/Cargo.toml index a94d69e58..724a05c50 100644 --- a/libcrux-ecdh/Cargo.toml +++ b/libcrux-ecdh/Cargo.toml @@ -15,6 +15,10 @@ path = "src/ecdh.rs" [dependencies] rand = { version = "0.8" } libcrux-hacl = { version = "=0.0.2-alpha.3", path = "../sys/hacl" } +hacl-rs = { git = "https://github.com/hacl-star/hacl-star.git", branch = "afromher_rs", optional = true } + +[features] +hacl-rs = ["dep:hacl-rs"] [dev-dependencies] rand_core = { version = "0.6" } @@ -22,3 +26,8 @@ hex = { version = "0.4.3", features = ["serde"] } serde_json = { version = "1.0" } serde = { version = "1.0", features = ["derive"] } pretty_env_logger = "0.5" +criterion = "0.5" + +[[bench]] +name = "curve25519" +harness = false diff --git a/libcrux-ecdh/benches/curve25519.rs b/libcrux-ecdh/benches/curve25519.rs new file mode 100644 index 000000000..86456d6fb --- /dev/null +++ b/libcrux-ecdh/benches/curve25519.rs @@ -0,0 +1,18 @@ +use criterion::{black_box, criterion_group, criterion_main, Criterion}; + +pub fn curve_bench(c: &mut Criterion) { + let mut rng = rand::thread_rng(); + let mut group = c.benchmark_group("Curve 25519"); + + let (sk_a, _pk_a) = libcrux_ecdh::x25519_key_gen(&mut rng).unwrap(); + let (_sk_b, pk_b) = libcrux_ecdh::x25519_key_gen(&mut rng).unwrap(); + group.bench_function("ECDH", |b| { + b.iter(|| libcrux_ecdh::hacl::curve25519::ecdh(black_box(&sk_a), black_box(&pk_b))) + }); + group.bench_function("Secret to Public", |b| { + b.iter(|| libcrux_ecdh::hacl::curve25519::secret_to_public(black_box(&sk_a))) + }); +} + +criterion_group!(benches, curve_bench); +criterion_main!(benches); diff --git a/libcrux-ecdh/src/ecdh.rs b/libcrux-ecdh/src/ecdh.rs index 3b9f11fe5..b32862e2a 100644 --- a/libcrux-ecdh/src/ecdh.rs +++ b/libcrux-ecdh/src/ecdh.rs @@ -11,7 +11,7 @@ //! ## P256 //! For P256 the portable HACL implementation is used. -mod hacl; +pub mod hacl; #[derive(Debug, PartialEq, Eq)] pub enum LowLevelError { diff --git a/libcrux-ecdh/src/hacl.rs b/libcrux-ecdh/src/hacl.rs index 77dea8434..b55b44f08 100644 --- a/libcrux-ecdh/src/hacl.rs +++ b/libcrux-ecdh/src/hacl.rs @@ -8,7 +8,7 @@ //! | simd128 | - | SSE2, SSE3, SSE4.1 | - | NEON | z14 | //! | simd256 | - | AVX, AVX2 | - | - | - | -pub(crate) mod curve25519; +pub mod curve25519; pub(crate) mod p256; /// Unified error type. diff --git a/libcrux-ecdh/src/hacl/curve25519.rs b/libcrux-ecdh/src/hacl/curve25519.rs index 8ee631669..ba1be0a14 100644 --- a/libcrux-ecdh/src/hacl/curve25519.rs +++ b/libcrux-ecdh/src/hacl/curve25519.rs @@ -1,3 +1,4 @@ +#[cfg(not(feature = "hacl-rs"))] use libcrux_hacl::{Hacl_Curve25519_51_ecdh, Hacl_Curve25519_51_secret_to_public}; #[derive(Debug, PartialEq, Eq, Clone, Copy)] @@ -8,6 +9,7 @@ pub enum Error { /// Compute the ECDH with the `private_key` and `public_key`. /// /// Returns the 32 bytes shared key. +#[cfg(not(feature = "hacl-rs"))] #[inline(always)] pub fn ecdh( private_key: impl AsRef<[u8; 32]>, @@ -28,10 +30,30 @@ pub fn ecdh( } } + +/// Compute the ECDH with the `private_key` and `public_key`. +/// +/// Returns the 32 bytes shared key. +#[cfg(feature = "hacl-rs")] +#[inline(always)] +pub fn ecdh( + private_key: impl AsRef<[u8; 32]>, + public_key: impl AsRef<[u8; 32]>, +) -> Result<[u8; 32], Error> { + let mut shared = [0u8; 32]; + let ok = hacl_rs::hacl::curve25519_51::ecdh(&mut shared, private_key.as_ref(), public_key.as_ref()); + if !ok { + Err(Error::InvalidInput) + } else { + Ok(shared) + } +} + /// Compute the public key for the provided `private_key` (scalar multiplication /// with the base point). /// /// Returns the 32 bytes shared key. +#[cfg(not(feature = "hacl-rs"))] #[must_use] #[inline(always)] pub fn secret_to_public(private_key: impl AsRef<[u8; 32]>) -> [u8; 32] { @@ -42,6 +64,19 @@ pub fn secret_to_public(private_key: impl AsRef<[u8; 32]>) -> [u8; 32] { public } +/// Compute the public key for the provided `private_key` (scalar multiplication +/// with the base point). +/// +/// Returns the 32 bytes shared key. +#[cfg(feature = "hacl-rs")] +#[must_use] +#[inline(always)] +pub fn secret_to_public(private_key: impl AsRef<[u8; 32]>) -> [u8; 32] { + let mut public = [0u8; 32]; + hacl_rs::hacl::curve25519_51::secret_to_public(&mut public, private_key.as_ref()); + public +} + #[cfg(all(bmi2, adx, target_arch = "x86_64"))] pub mod vale { use super::Error; From 54ffd8b29cdfcd929de33ccced23413bbf6b0c8d Mon Sep 17 00:00:00 2001 From: Jonas Schneider-Bensch Date: Tue, 23 Jul 2024 16:29:19 +0200 Subject: [PATCH 2/5] Add flamegraphs --- Cargo.lock | 407 ++++++++++++++- libcrux-ecdh/Cargo.toml | 1 + libcrux-ecdh/README.md | 15 + libcrux-ecdh/benches/curve25519.rs | 8 +- libcrux-ecdh/flamegraph_hacl-c_ecdh.svg | 491 ++++++++++++++++++ .../flamegraph_hacl-c_secret_to_public.svg | 491 ++++++++++++++++++ libcrux-ecdh/flamegraph_hacl-rs_ecdh.svg | 491 ++++++++++++++++++ .../flamegraph_hacl-rs_secret_to_public.svg | 491 ++++++++++++++++++ 8 files changed, 2391 insertions(+), 4 deletions(-) create mode 100644 libcrux-ecdh/README.md create mode 100644 libcrux-ecdh/flamegraph_hacl-c_ecdh.svg create mode 100644 libcrux-ecdh/flamegraph_hacl-c_secret_to_public.svg create mode 100644 libcrux-ecdh/flamegraph_hacl-rs_ecdh.svg create mode 100644 libcrux-ecdh/flamegraph_hacl-rs_secret_to_public.svg diff --git a/Cargo.lock b/Cargo.lock index 4644b7378..b3e5ca95b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,21 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "addr2line" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + [[package]] name = "aead" version = "0.5.2" @@ -12,6 +27,19 @@ dependencies = [ "generic-array", ] +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "aho-corasick" version = "1.1.3" @@ -82,12 +110,33 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7d5a26814d8dcb93b0e5a0ff3c6d80a8843bafb21b39e8e18a6f05471870e110" +[[package]] +name = "arrayvec" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" + [[package]] name = "autocfg" version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" +[[package]] +name = "backtrace" +version = "0.3.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + [[package]] name = "base16ct" version = "0.2.0" @@ -130,7 +179,7 @@ version = "0.69.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a00dc851838a2120612785d195287475a3ac45514741da670b735818822129a0" dependencies = [ - "bitflags", + "bitflags 2.6.0", "cexpr", "clang-sys", "itertools 0.12.1", @@ -147,6 +196,12 @@ dependencies = [ "which", ] +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + [[package]] name = "bitflags" version = "2.6.0" @@ -168,6 +223,12 @@ version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" +[[package]] +name = "bytemuck" +version = "1.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b236fc92302c97ed75b38da1f4917b5cdda4984745740f153a5d3059e48d725e" + [[package]] name = "byteorder" version = "1.5.0" @@ -360,6 +421,15 @@ version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" +[[package]] +name = "cpp_demangle" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e8227005286ec39567949b33df9896bcadfa6051bccca2488129f108ca23119" +dependencies = [ + "cfg-if", +] + [[package]] name = "cpufeatures" version = "0.2.12" @@ -498,6 +568,15 @@ dependencies = [ "zeroize", ] +[[package]] +name = "debugid" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef552e6f588e446098f6ba40d89ac146c8c7b64aade83c051ee00bb5d2bc18d" +dependencies = [ + "uuid", +] + [[package]] name = "der" version = "0.7.9" @@ -600,6 +679,12 @@ dependencies = [ "termcolor", ] +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + [[package]] name = "errno" version = "0.3.9" @@ -610,6 +695,12 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "fastrand" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" + [[package]] name = "ff" version = "0.13.0" @@ -626,6 +717,18 @@ version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d" +[[package]] +name = "findshlibs" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40b9e59cd0f7e0806cca4be089683ecb6434e602038df21fe6bf6711b2f07f64" +dependencies = [ + "cc", + "lazy_static", + "libc", + "winapi", +] + [[package]] name = "foreign-types" version = "0.3.2" @@ -671,6 +774,12 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "gimli" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" + [[package]] name = "glob" version = "0.3.1" @@ -706,6 +815,12 @@ dependencies = [ "crunchy", ] +[[package]] +name = "hashbrown" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" + [[package]] name = "hax-lib" version = "0.1.0-pre.1" @@ -828,6 +943,34 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" +[[package]] +name = "indexmap" +version = "2.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "inferno" +version = "0.11.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c77a3ae7d4761b9c64d2c030f70746ceb8cfba32dce0325a56792e0a4816c31" +dependencies = [ + "ahash", + "indexmap", + "is-terminal", + "itoa", + "log", + "num-format", + "once_cell", + "quick-xml", + "rgb", + "str_stack", +] + [[package]] name = "inout" version = "0.1.3" @@ -975,6 +1118,7 @@ dependencies = [ "hacl-rs", "hex", "libcrux-hacl", + "pprof", "pretty_env_logger", "rand", "rand_core", @@ -1144,6 +1288,16 @@ version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + [[package]] name = "log" version = "0.4.22" @@ -1156,12 +1310,41 @@ version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +[[package]] +name = "memmap2" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe751422e4a8caa417e13c3ea66452215d7d63e19e604f4980461212f3ae1322" +dependencies = [ + "libc", +] + [[package]] name = "minimal-lexical" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" +[[package]] +name = "miniz_oxide" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +dependencies = [ + "adler", +] + +[[package]] +name = "nix" +version = "0.26.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "598beaf3cc6fdd9a5dfb1630c2800c7acd31df7aaf0f565796fba2b53ca1af1b" +dependencies = [ + "bitflags 1.3.2", + "cfg-if", + "libc", +] + [[package]] name = "nom" version = "7.1.3" @@ -1182,6 +1365,16 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-format" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a652d9771a63711fd3c3deb670acfbe5c30a4072e664d7a3bf5a9e1056ac72c3" +dependencies = [ + "arrayvec", + "itoa", +] + [[package]] name = "num-integer" version = "0.1.46" @@ -1200,6 +1393,15 @@ dependencies = [ "autocfg", ] +[[package]] +name = "object" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "081b846d1d56ddfc18fdf1a922e4f6e07a11768ea1b92dec44e42b72712ccfce" +dependencies = [ + "memchr", +] + [[package]] name = "once_cell" version = "1.19.0" @@ -1224,7 +1426,7 @@ version = "0.10.66" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" dependencies = [ - "bitflags", + "bitflags 2.6.0", "cfg-if", "foreign-types", "libc", @@ -1268,6 +1470,29 @@ dependencies = [ "sha2", ] +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets", +] + [[package]] name = "pem-rfc7468" version = "0.7.0" @@ -1332,6 +1557,28 @@ dependencies = [ "universal-hash", ] +[[package]] +name = "pprof" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef5c97c51bd34c7e742402e216abdeb44d415fbe6ae41d56b114723e953711cb" +dependencies = [ + "backtrace", + "cfg-if", + "criterion", + "findshlibs", + "inferno", + "libc", + "log", + "nix", + "once_cell", + "parking_lot", + "smallvec", + "symbolic-demangle", + "tempfile", + "thiserror", +] + [[package]] name = "ppv-lite86" version = "0.2.17" @@ -1444,6 +1691,15 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quick-xml" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f50b1c63b38611e7d4d7f68b82d3ad0cc71a2ad2e7f61fc10f1328d917c93cd" +dependencies = [ + "memchr", +] + [[package]] name = "quickcheck" version = "1.0.3" @@ -1525,6 +1781,15 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "redox_syscall" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a908a6e00f1fdd0dfd9c0eb08ce85126f6d8bbda50017e74bc4a4b7d4a926a4" +dependencies = [ + "bitflags 2.6.0", +] + [[package]] name = "regex" version = "1.10.5" @@ -1564,6 +1829,15 @@ dependencies = [ "subtle", ] +[[package]] +name = "rgb" +version = "0.8.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade4539f42266ded9e755c605bdddf546242b2c961b03b06a7375260788a0523" +dependencies = [ + "bytemuck", +] + [[package]] name = "ring" version = "0.17.8" @@ -1579,6 +1853,12 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + [[package]] name = "rustc-hash" version = "1.1.0" @@ -1600,7 +1880,7 @@ version = "0.38.34" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" dependencies = [ - "bitflags", + "bitflags 2.6.0", "errno", "libc", "linux-raw-sys", @@ -1628,6 +1908,12 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + [[package]] name = "sec1" version = "0.7.3" @@ -1716,6 +2002,12 @@ dependencies = [ "rand_core", ] +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + [[package]] name = "spin" version = "0.9.8" @@ -1732,6 +2024,18 @@ dependencies = [ "der", ] +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "str_stack" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9091b6114800a5f2141aee1d1b9d6ca3592ac062dc5decb3764ec5895a47b4eb" + [[package]] name = "strsim" version = "0.11.1" @@ -1750,6 +2054,29 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "734676eb262c623cec13c3155096e08d1f8f29adce39ba17948b18dad1e54142" +[[package]] +name = "symbolic-common" +version = "12.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71297dc3e250f7dbdf8adb99e235da783d690f5819fdeb4cce39d9cfb0aca9f1" +dependencies = [ + "debugid", + "memmap2", + "stable_deref_trait", + "uuid", +] + +[[package]] +name = "symbolic-demangle" +version = "12.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "424fa2c9bf2c862891b9cfd354a752751a6730fd838a4691e7f6c2c7957b9daf" +dependencies = [ + "cpp_demangle", + "rustc-demangle", + "symbolic-common", +] + [[package]] name = "syn" version = "1.0.109" @@ -1772,6 +2099,18 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "tempfile" +version = "3.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" +dependencies = [ + "cfg-if", + "fastrand", + "rustix", + "windows-sys", +] + [[package]] name = "termcolor" version = "1.4.1" @@ -1781,6 +2120,26 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "thiserror" +version = "1.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.72", +] + [[package]] name = "tinytemplate" version = "1.2.1" @@ -1975,6 +2334,22 @@ dependencies = [ "rustix", ] +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + [[package]] name = "winapi-util" version = "0.1.8" @@ -1984,6 +2359,12 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + [[package]] name = "windows-sys" version = "0.52.0" @@ -2081,6 +2462,26 @@ dependencies = [ "zeroize", ] +[[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.72", +] + [[package]] name = "zeroize" version = "1.8.1" diff --git a/libcrux-ecdh/Cargo.toml b/libcrux-ecdh/Cargo.toml index 724a05c50..6945bd8df 100644 --- a/libcrux-ecdh/Cargo.toml +++ b/libcrux-ecdh/Cargo.toml @@ -27,6 +27,7 @@ serde_json = { version = "1.0" } serde = { version = "1.0", features = ["derive"] } pretty_env_logger = "0.5" criterion = "0.5" +pprof = { version = "0.13.0", features = ["flamegraph", "criterion"]} [[bench]] name = "curve25519" diff --git a/libcrux-ecdh/README.md b/libcrux-ecdh/README.md new file mode 100644 index 000000000..5fb0f089e --- /dev/null +++ b/libcrux-ecdh/README.md @@ -0,0 +1,15 @@ +# Benchmarks +To run HACL* (C) benchmarks, just run `cargo bench` in this crate. +For the HACL-rs version, run `cargo bench --features hacl-rs`. + +To get flamegraphs, run +``` +cargo bench --bench curve25519 -- --profile-time=5 +``` +or +``` +cargo bench --bench curve25519 --features hacl-rs -- --profile-time=5 +``` + +The flamegraphs can then be found in `../target/criterion/Curve\ +25519/{ECDH/Secret\ to\ Public}/profile/flamegraph.svg`. diff --git a/libcrux-ecdh/benches/curve25519.rs b/libcrux-ecdh/benches/curve25519.rs index 86456d6fb..fc23a6fc8 100644 --- a/libcrux-ecdh/benches/curve25519.rs +++ b/libcrux-ecdh/benches/curve25519.rs @@ -1,5 +1,7 @@ use criterion::{black_box, criterion_group, criterion_main, Criterion}; +use pprof::criterion::{Output, PProfProfiler}; + pub fn curve_bench(c: &mut Criterion) { let mut rng = rand::thread_rng(); let mut group = c.benchmark_group("Curve 25519"); @@ -14,5 +16,9 @@ pub fn curve_bench(c: &mut Criterion) { }); } -criterion_group!(benches, curve_bench); + +criterion_group!{name = benches; + config = Criterion::default().with_profiler(PProfProfiler::new(100, Output::Flamegraph(None))); + targets = curve_bench} + criterion_main!(benches); diff --git a/libcrux-ecdh/flamegraph_hacl-c_ecdh.svg b/libcrux-ecdh/flamegraph_hacl-c_ecdh.svg new file mode 100644 index 000000000..026903e6c --- /dev/null +++ b/libcrux-ecdh/flamegraph_hacl-c_ecdh.svg @@ -0,0 +1,491 @@ +Flame Graph Reset ZoomSearch <criterion::routine::Function<M,F,T> as criterion::routine::Routine<M,T>>::bench (311 samples, 62.32%)<criterion::routine::Function<M,F,T> as criterion::routine::Routine<M,T>>::benchcriterion::bencher::Bencher<M>::iter (311 samples, 62.32%)criterion::bencher::Bencher<M>::iterHacl_Curve25519_51_ecdh (311 samples, 62.32%)Hacl_Curve25519_51_ecdhHacl_Curve25519_51_scalarmult (311 samples, 62.32%)Hacl_Curve25519_51_scalarmultHacl_Curve25519_51_finv (40 samples, 8.02%)Hacl_Curve2..Hacl_Curve25519_51_fsquare_times (37 samples, 7.41%)Hacl_Curve..Hacl_Curve25519_51_finv (18 samples, 3.61%)Hacl..Hacl_Curve25519_51_fsquare_times (15 samples, 3.01%)Hac..all (499 samples, 100%)curve25519-0266 (499 samples, 100.00%)curve25519-0266_start (499 samples, 100.00%)_start__libc_start_main (499 samples, 100.00%)__libc_start_mainmain (499 samples, 100.00%)mainstd::rt::lang_start_internal (499 samples, 100.00%)std::rt::lang_start_internalstd::rt::lang_start::{{closure}} (499 samples, 100.00%)std::rt::lang_start::{{closure}}std::sys_common::backtrace::__rust_begin_short_backtrace (499 samples, 100.00%)std::sys_common::backtrace::__rust_begin_short_backtracecurve25519::main (499 samples, 100.00%)curve25519::main<criterion::routine::Function<M,F,T> as criterion::routine::Routine<M,T>>::warm_up (188 samples, 37.68%)<criterion::routine::Function<M,F,T> as criterion::routine::R..criterion::bencher::Bencher<M>::iter (188 samples, 37.68%)criterion::bencher::Bencher<M>::iterHacl_Curve25519_51_ecdh (188 samples, 37.68%)Hacl_Curve25519_51_ecdhHacl_Curve25519_51_scalarmult (188 samples, 37.68%)Hacl_Curve25519_51_scalarmultpoint_double.isra.0 (1 samples, 0.20%) \ No newline at end of file diff --git a/libcrux-ecdh/flamegraph_hacl-c_secret_to_public.svg b/libcrux-ecdh/flamegraph_hacl-c_secret_to_public.svg new file mode 100644 index 000000000..cb2b44bea --- /dev/null +++ b/libcrux-ecdh/flamegraph_hacl-c_secret_to_public.svg @@ -0,0 +1,491 @@ +Flame Graph Reset ZoomSearch Hacl_Curve25519_51_finv (29 samples, 5.80%)Hacl_Cu..Hacl_Curve25519_51_fsquare_times (28 samples, 5.60%)Hacl_Cu..<criterion::routine::Function<M,F,T> as criterion::routine::Routine<M,T>>::bench (312 samples, 62.40%)<criterion::routine::Function<M,F,T> as criterion::routine::Routine<M,T>>::benchcriterion::bencher::Bencher<M>::iter (312 samples, 62.40%)criterion::bencher::Bencher<M>::iterHacl_Curve25519_51_secret_to_public (312 samples, 62.40%)Hacl_Curve25519_51_secret_to_publicHacl_Curve25519_51_scalarmult (312 samples, 62.40%)Hacl_Curve25519_51_scalarmultpoint_double.isra.0 (3 samples, 0.60%)all (500 samples, 100%)curve25519-0266 (500 samples, 100.00%)curve25519-0266_start (500 samples, 100.00%)_start__libc_start_main (500 samples, 100.00%)__libc_start_mainmain (500 samples, 100.00%)mainstd::rt::lang_start_internal (500 samples, 100.00%)std::rt::lang_start_internalstd::rt::lang_start::{{closure}} (500 samples, 100.00%)std::rt::lang_start::{{closure}}std::sys_common::backtrace::__rust_begin_short_backtrace (500 samples, 100.00%)std::sys_common::backtrace::__rust_begin_short_backtracecurve25519::main (500 samples, 100.00%)curve25519::main<criterion::routine::Function<M,F,T> as criterion::routine::Routine<M,T>>::warm_up (188 samples, 37.60%)<criterion::routine::Function<M,F,T> as criterion::routine::R..criterion::bencher::Bencher<M>::iter (188 samples, 37.60%)criterion::bencher::Bencher<M>::iterHacl_Curve25519_51_secret_to_public (188 samples, 37.60%)Hacl_Curve25519_51_secret_to_publicHacl_Curve25519_51_scalarmult (188 samples, 37.60%)Hacl_Curve25519_51_scalarmultHacl_Curve25519_51_finv (22 samples, 4.40%)Hacl_..Hacl_Curve25519_51_fsquare_times (20 samples, 4.00%)Hacl.. \ No newline at end of file diff --git a/libcrux-ecdh/flamegraph_hacl-rs_ecdh.svg b/libcrux-ecdh/flamegraph_hacl-rs_ecdh.svg new file mode 100644 index 000000000..a57f61e54 --- /dev/null +++ b/libcrux-ecdh/flamegraph_hacl-rs_ecdh.svg @@ -0,0 +1,491 @@ +Flame Graph Reset ZoomSearch hacl_rs::hacl::curve25519_51::finv (28 samples, 5.47%)hacl_rs..hacl_rs::hacl::bignum25519_51::fmul2 (160 samples, 31.25%)hacl_rs::hacl::bignum25519_51::fmul2hacl_rs::hacl::curve25519_51::point_add_and_double (340 samples, 66.41%)hacl_rs::hacl::curve25519_51::point_add_and_doublehacl_rs::hacl::bignum25519_51::fsqr2 (101 samples, 19.73%)hacl_rs::hacl::bignum25519_51::..<criterion::routine::Function<M,F,T> as criterion::routine::Routine<M,T>>::bench (392 samples, 76.56%)<criterion::routine::Function<M,F,T> as criterion::routine::Routine<M,T>>::benchcriterion::bencher::Bencher<M>::iter (392 samples, 76.56%)criterion::bencher::Bencher<M>::iterhacl_rs::hacl::curve25519_51::scalarmult (391 samples, 76.37%)hacl_rs::hacl::curve25519_51::scalarmulthacl_rs::hacl::curve25519_51::point_double (2 samples, 0.39%)hacl_rs::hacl::bignum25519_51::fsqr2 (1 samples, 0.20%)hacl_rs::hacl::curve25519_51::finv (11 samples, 2.15%)h..hacl_rs::hacl::bignum25519_51::fmul2 (49 samples, 9.57%)hacl_rs::hacl:..hacl_rs::hacl::curve25519_51::point_add_and_double (99 samples, 19.34%)hacl_rs::hacl::curve25519_51::..hacl_rs::hacl::bignum25519_51::fsqr2 (26 samples, 5.08%)hacl_r..all (512 samples, 100%)curve25519-206f (512 samples, 100.00%)curve25519-206f_start (512 samples, 100.00%)_start__libc_start_main (512 samples, 100.00%)__libc_start_mainmain (512 samples, 100.00%)mainstd::rt::lang_start_internal (512 samples, 100.00%)std::rt::lang_start_internalstd::rt::lang_start::{{closure}} (512 samples, 100.00%)std::rt::lang_start::{{closure}}std::sys_common::backtrace::__rust_begin_short_backtrace (512 samples, 100.00%)std::sys_common::backtrace::__rust_begin_short_backtracecurve25519::main (512 samples, 100.00%)curve25519::main<criterion::routine::Function<M,F,T> as criterion::routine::Routine<M,T>>::warm_up (120 samples, 23.44%)<criterion::routine::Function<M,F,T> ..criterion::bencher::Bencher<M>::iter (120 samples, 23.44%)criterion::bencher::Bencher<M>::iterhacl_rs::hacl::curve25519_51::scalarmult (120 samples, 23.44%)hacl_rs::hacl::curve25519_51::scalarm..hacl_rs::hacl::curve25519_51::point_double (1 samples, 0.20%)hacl_rs::hacl::bignum25519_51::fsqr2 (1 samples, 0.20%) \ No newline at end of file diff --git a/libcrux-ecdh/flamegraph_hacl-rs_secret_to_public.svg b/libcrux-ecdh/flamegraph_hacl-rs_secret_to_public.svg new file mode 100644 index 000000000..0bf1fec65 --- /dev/null +++ b/libcrux-ecdh/flamegraph_hacl-rs_secret_to_public.svg @@ -0,0 +1,491 @@ +Flame Graph Reset ZoomSearch hacl_rs::hacl::bignum25519_51::fmul2 (1 samples, 0.20%)hacl_rs::hacl::curve25519_51::finv (30 samples, 5.93%)hacl_rs:..hacl_rs::hacl::bignum25519_51::fmul2 (171 samples, 33.79%)hacl_rs::hacl::bignum25519_51::fmul2hacl_rs::hacl::curve25519_51::point_add_and_double (335 samples, 66.21%)hacl_rs::hacl::curve25519_51::point_add_and_doublehacl_rs::hacl::bignum25519_51::fsqr2 (82 samples, 16.21%)hacl_rs::hacl::bignum2551..<criterion::routine::Function<M,F,T> as criterion::routine::Routine<M,T>>::bench (383 samples, 75.69%)<criterion::routine::Function<M,F,T> as criterion::routine::Routine<M,T>>::benchcriterion::bencher::Bencher<M>::iter (383 samples, 75.69%)criterion::bencher::Bencher<M>::iterhacl_rs::hacl::curve25519_51::scalarmult (383 samples, 75.69%)hacl_rs::hacl::curve25519_51::scalarmulthacl_rs::hacl::curve25519_51::point_double (1 samples, 0.20%)hacl_rs::hacl::bignum25519_51::fmul2 (1 samples, 0.20%)hacl_rs::hacl::curve25519_51::finv (8 samples, 1.58%)hacl_rs::hacl::bignum25519_51::fmul2 (51 samples, 10.08%)hacl_rs::hacl::..all (506 samples, 100%)curve25519-206f (506 samples, 100.00%)curve25519-206f_start (506 samples, 100.00%)_start__libc_start_main (506 samples, 100.00%)__libc_start_mainmain (506 samples, 100.00%)mainstd::rt::lang_start_internal (506 samples, 100.00%)std::rt::lang_start_internalstd::rt::lang_start::{{closure}} (506 samples, 100.00%)std::rt::lang_start::{{closure}}std::sys_common::backtrace::__rust_begin_short_backtrace (506 samples, 100.00%)std::sys_common::backtrace::__rust_begin_short_backtracecurve25519::main (506 samples, 100.00%)curve25519::main<criterion::routine::Function<M,F,T> as criterion::routine::Routine<M,T>>::warm_up (123 samples, 24.31%)<criterion::routine::Function<M,F,T> as..criterion::bencher::Bencher<M>::iter (123 samples, 24.31%)criterion::bencher::Bencher<M>::iterhacl_rs::hacl::curve25519_51::scalarmult (123 samples, 24.31%)hacl_rs::hacl::curve25519_51::scalarmulthacl_rs::hacl::curve25519_51::point_add_and_double (108 samples, 21.34%)hacl_rs::hacl::curve25519_51::poin..hacl_rs::hacl::bignum25519_51::fsqr2 (30 samples, 5.93%)hacl_rs:.. \ No newline at end of file From 00b3c4ae70c73fd44de6af305af7e39c09da575f Mon Sep 17 00:00:00 2001 From: Jonas Schneider-Bensch Date: Thu, 1 Aug 2024 16:39:45 +0200 Subject: [PATCH 3/5] Use `hacl_rs` version of P256 in `hacl-rs` feature --- libcrux-ecdh/src/hacl/curve25519.rs | 40 +++++------------------------ libcrux-ecdh/src/hacl/p256.rs | 33 +++++++++++++++++++++--- 2 files changed, 36 insertions(+), 37 deletions(-) diff --git a/libcrux-ecdh/src/hacl/curve25519.rs b/libcrux-ecdh/src/hacl/curve25519.rs index ba1be0a14..b19e98a14 100644 --- a/libcrux-ecdh/src/hacl/curve25519.rs +++ b/libcrux-ecdh/src/hacl/curve25519.rs @@ -9,13 +9,13 @@ pub enum Error { /// Compute the ECDH with the `private_key` and `public_key`. /// /// Returns the 32 bytes shared key. -#[cfg(not(feature = "hacl-rs"))] #[inline(always)] pub fn ecdh( private_key: impl AsRef<[u8; 32]>, public_key: impl AsRef<[u8; 32]>, ) -> Result<[u8; 32], Error> { let mut shared = [0u8; 32]; + #[cfg(not(feature = "hacl-rs"))] let ok = unsafe { Hacl_Curve25519_51_ecdh( shared.as_mut_ptr(), @@ -23,25 +23,9 @@ pub fn ecdh( public_key.as_ref().as_ptr() as _, ) }; - if !ok { - Err(Error::InvalidInput) - } else { - Ok(shared) - } -} - - -/// Compute the ECDH with the `private_key` and `public_key`. -/// -/// Returns the 32 bytes shared key. -#[cfg(feature = "hacl-rs")] -#[inline(always)] -pub fn ecdh( - private_key: impl AsRef<[u8; 32]>, - public_key: impl AsRef<[u8; 32]>, -) -> Result<[u8; 32], Error> { - let mut shared = [0u8; 32]; - let ok = hacl_rs::hacl::curve25519_51::ecdh(&mut shared, private_key.as_ref(), public_key.as_ref()); + #[cfg(feature = "hacl-rs")] + let ok = + hacl_rs::hacl::curve25519_51::ecdh(&mut shared, private_key.as_ref(), public_key.as_ref()); if !ok { Err(Error::InvalidInput) } else { @@ -53,26 +37,16 @@ pub fn ecdh( /// with the base point). /// /// Returns the 32 bytes shared key. -#[cfg(not(feature = "hacl-rs"))] + #[must_use] #[inline(always)] pub fn secret_to_public(private_key: impl AsRef<[u8; 32]>) -> [u8; 32] { let mut public = [0u8; 32]; + #[cfg(not(feature = "hacl-rs"))] unsafe { Hacl_Curve25519_51_secret_to_public(public.as_mut_ptr(), private_key.as_ref().as_ptr() as _) }; - public -} - -/// Compute the public key for the provided `private_key` (scalar multiplication -/// with the base point). -/// -/// Returns the 32 bytes shared key. -#[cfg(feature = "hacl-rs")] -#[must_use] -#[inline(always)] -pub fn secret_to_public(private_key: impl AsRef<[u8; 32]>) -> [u8; 32] { - let mut public = [0u8; 32]; + #[cfg(feature = "hacl-rs")] hacl_rs::hacl::curve25519_51::secret_to_public(&mut public, private_key.as_ref()); public } diff --git a/libcrux-ecdh/src/hacl/p256.rs b/libcrux-ecdh/src/hacl/p256.rs index f8cfe25e7..65d6f4667 100644 --- a/libcrux-ecdh/src/hacl/p256.rs +++ b/libcrux-ecdh/src/hacl/p256.rs @@ -1,3 +1,4 @@ +#[cfg(not(feature = "hacl-rs"))] use libcrux_hacl::{ Hacl_P256_compressed_to_raw, Hacl_P256_dh_initiator, Hacl_P256_dh_responder, Hacl_P256_uncompressed_to_raw, Hacl_P256_validate_private_key, Hacl_P256_validate_public_key, @@ -19,9 +20,13 @@ pub enum Error { pub fn uncompressed_to_coordinates(point: &[u8]) -> Result<[u8; 64], Error> { let mut concat_point = [0u8; 64]; if point.len() >= 65 { + #[cfg(not(feature = "hacl-rs"))] let ok = unsafe { Hacl_P256_uncompressed_to_raw(point.as_ptr() as _, concat_point.as_mut_ptr()) }; + + #[cfg(feature = "hacl-rs")] + let ok = hacl_rs::hacl::p256::uncompressed_to_raw(point, &mut concat_point); if ok { Ok(concat_point) } else { @@ -37,8 +42,11 @@ pub fn uncompressed_to_coordinates(point: &[u8]) -> Result<[u8; 64], Error> { pub fn compressed_to_coordinates(point: &[u8]) -> Result<[u8; 64], Error> { let mut concat_point = [0u8; 64]; if point.len() >= 33 { + #[cfg(not(feature = "hacl-rs"))] let ok = unsafe { Hacl_P256_compressed_to_raw(point.as_ptr() as _, concat_point.as_mut_ptr()) }; + #[cfg(feature = "hacl-rs")] + let ok = hacl_rs::hacl::p256::compressed_to_raw(point, &mut concat_point); if ok { Ok(concat_point) } else { @@ -54,7 +62,12 @@ pub fn compressed_to_coordinates(point: &[u8]) -> Result<[u8; 64], Error> { /// /// Returns [`Error::InvalidPoint`] if the `point` is not valid. pub fn validate_point(point: impl AsRef<[u8; 64]>) -> Result<(), Error> { - if unsafe { Hacl_P256_validate_public_key(point.as_ref().as_ptr() as _) } { + #[cfg(not(feature = "hacl-rs"))] + let valid_point = unsafe { Hacl_P256_validate_public_key(point.as_ref().as_ptr() as _) }; + #[cfg(feature = "hacl-rs")] + let valid_point = hacl_rs::hacl::p256::validate_public_key(point.as_ref()); + + if valid_point { Ok(()) } else { Err(Error::InvalidPoint) @@ -75,9 +88,12 @@ pub fn validate_scalar_(scalar: &[u8; 32]) -> Result<(), Error> { if scalar.as_ref().iter().all(|b| *b == 0) { return Err(Error::InvalidScalar); } - + #[cfg(not(feature = "hacl-rs"))] + let valid_scalar = unsafe { Hacl_P256_validate_private_key(scalar.as_ref().as_ptr() as _) }; + #[cfg(feature = "hacl-rs")] + let valid_scalar = hacl_rs::hacl::p256::validate_private_key(scalar); // Ensure that the key is in range [1, p-1] - if unsafe { Hacl_P256_validate_private_key(scalar.as_ref().as_ptr() as _) } { + if valid_scalar { Ok(()) } else { Err(Error::InvalidScalar) @@ -108,6 +124,7 @@ pub fn ecdh( public_key: impl AsRef<[u8; 64]>, ) -> Result<[u8; 64], Error> { let mut shared = [0u8; 64]; + #[cfg(not(feature = "hacl-rs"))] let ok = unsafe { Hacl_P256_dh_responder( shared.as_mut_ptr(), @@ -115,6 +132,10 @@ pub fn ecdh( private_key.as_ref().as_ptr() as _, ) }; + #[cfg(feature = "hacl-rs")] + let ok = + hacl_rs::hacl::p256::dh_responder(&mut shared, public_key.as_ref(), private_key.as_ref()); + if !ok { Err(Error::InvalidInput) } else { @@ -129,7 +150,11 @@ pub fn secret_to_public(s: impl AsRef<[u8; 32]>) -> Result<[u8; 64], Error> { validate_scalar(&s)?; let mut out = [0u8; 64]; - if unsafe { Hacl_P256_dh_initiator(out.as_mut_ptr(), s.as_ref().as_ptr() as _) } { + #[cfg(not(feature = "hacl-rs"))] + let ok = unsafe { Hacl_P256_dh_initiator(out.as_mut_ptr(), s.as_ref().as_ptr() as _) }; + #[cfg(feature = "hacl-rs")] + let ok = hacl_rs::hacl::p256::dh_initiator(&mut out, s.as_ref()); + if ok { Ok(out) } else { Err(Error::InvalidScalar) From 06ee544805cbdb767a9af980ec29819d86dfcbc1 Mon Sep 17 00:00:00 2001 From: Jonas Schneider-Bensch Date: Thu, 1 Aug 2024 16:42:12 +0200 Subject: [PATCH 4/5] Restore visibility to before benchmarking --- Cargo.lock | 408 +---------------------------- libcrux-ecdh/Cargo.toml | 5 - libcrux-ecdh/benches/curve25519.rs | 24 -- libcrux-ecdh/src/ecdh.rs | 2 +- libcrux-ecdh/src/hacl.rs | 2 +- 5 files changed, 5 insertions(+), 436 deletions(-) delete mode 100644 libcrux-ecdh/benches/curve25519.rs diff --git a/Cargo.lock b/Cargo.lock index b3e5ca95b..27fc9455d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,21 +2,6 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "addr2line" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - [[package]] name = "aead" version = "0.5.2" @@ -27,19 +12,6 @@ dependencies = [ "generic-array", ] -[[package]] -name = "ahash" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" -dependencies = [ - "cfg-if", - "getrandom", - "once_cell", - "version_check", - "zerocopy", -] - [[package]] name = "aho-corasick" version = "1.1.3" @@ -110,33 +82,12 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7d5a26814d8dcb93b0e5a0ff3c6d80a8843bafb21b39e8e18a6f05471870e110" -[[package]] -name = "arrayvec" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" - [[package]] name = "autocfg" version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" -[[package]] -name = "backtrace" -version = "0.3.73" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - [[package]] name = "base16ct" version = "0.2.0" @@ -179,7 +130,7 @@ version = "0.69.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a00dc851838a2120612785d195287475a3ac45514741da670b735818822129a0" dependencies = [ - "bitflags 2.6.0", + "bitflags", "cexpr", "clang-sys", "itertools 0.12.1", @@ -196,12 +147,6 @@ dependencies = [ "which", ] -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - [[package]] name = "bitflags" version = "2.6.0" @@ -223,12 +168,6 @@ version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" -[[package]] -name = "bytemuck" -version = "1.16.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b236fc92302c97ed75b38da1f4917b5cdda4984745740f153a5d3059e48d725e" - [[package]] name = "byteorder" version = "1.5.0" @@ -421,15 +360,6 @@ version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" -[[package]] -name = "cpp_demangle" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e8227005286ec39567949b33df9896bcadfa6051bccca2488129f108ca23119" -dependencies = [ - "cfg-if", -] - [[package]] name = "cpufeatures" version = "0.2.12" @@ -568,15 +498,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "debugid" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef552e6f588e446098f6ba40d89ac146c8c7b64aade83c051ee00bb5d2bc18d" -dependencies = [ - "uuid", -] - [[package]] name = "der" version = "0.7.9" @@ -679,12 +600,6 @@ dependencies = [ "termcolor", ] -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - [[package]] name = "errno" version = "0.3.9" @@ -695,12 +610,6 @@ dependencies = [ "windows-sys", ] -[[package]] -name = "fastrand" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" - [[package]] name = "ff" version = "0.13.0" @@ -717,18 +626,6 @@ version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d" -[[package]] -name = "findshlibs" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40b9e59cd0f7e0806cca4be089683ecb6434e602038df21fe6bf6711b2f07f64" -dependencies = [ - "cc", - "lazy_static", - "libc", - "winapi", -] - [[package]] name = "foreign-types" version = "0.3.2" @@ -774,12 +671,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "gimli" -version = "0.29.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" - [[package]] name = "glob" version = "0.3.1" @@ -815,12 +706,6 @@ dependencies = [ "crunchy", ] -[[package]] -name = "hashbrown" -version = "0.14.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" - [[package]] name = "hax-lib" version = "0.1.0-pre.1" @@ -943,34 +828,6 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" -[[package]] -name = "indexmap" -version = "2.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" -dependencies = [ - "equivalent", - "hashbrown", -] - -[[package]] -name = "inferno" -version = "0.11.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c77a3ae7d4761b9c64d2c030f70746ceb8cfba32dce0325a56792e0a4816c31" -dependencies = [ - "ahash", - "indexmap", - "is-terminal", - "itoa", - "log", - "num-format", - "once_cell", - "quick-xml", - "rgb", - "str_stack", -] - [[package]] name = "inout" version = "0.1.3" @@ -1114,11 +971,9 @@ dependencies = [ name = "libcrux-ecdh" version = "0.0.2-alpha.3" dependencies = [ - "criterion", "hacl-rs", "hex", "libcrux-hacl", - "pprof", "pretty_env_logger", "rand", "rand_core", @@ -1288,16 +1143,6 @@ version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - [[package]] name = "log" version = "0.4.22" @@ -1310,41 +1155,12 @@ version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" -[[package]] -name = "memmap2" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe751422e4a8caa417e13c3ea66452215d7d63e19e604f4980461212f3ae1322" -dependencies = [ - "libc", -] - [[package]] name = "minimal-lexical" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" -[[package]] -name = "miniz_oxide" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" -dependencies = [ - "adler", -] - -[[package]] -name = "nix" -version = "0.26.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "598beaf3cc6fdd9a5dfb1630c2800c7acd31df7aaf0f565796fba2b53ca1af1b" -dependencies = [ - "bitflags 1.3.2", - "cfg-if", - "libc", -] - [[package]] name = "nom" version = "7.1.3" @@ -1365,16 +1181,6 @@ dependencies = [ "num-traits", ] -[[package]] -name = "num-format" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a652d9771a63711fd3c3deb670acfbe5c30a4072e664d7a3bf5a9e1056ac72c3" -dependencies = [ - "arrayvec", - "itoa", -] - [[package]] name = "num-integer" version = "0.1.46" @@ -1393,15 +1199,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "object" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "081b846d1d56ddfc18fdf1a922e4f6e07a11768ea1b92dec44e42b72712ccfce" -dependencies = [ - "memchr", -] - [[package]] name = "once_cell" version = "1.19.0" @@ -1426,7 +1223,7 @@ version = "0.10.66" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" dependencies = [ - "bitflags 2.6.0", + "bitflags", "cfg-if", "foreign-types", "libc", @@ -1470,29 +1267,6 @@ dependencies = [ "sha2", ] -[[package]] -name = "parking_lot" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets", -] - [[package]] name = "pem-rfc7468" version = "0.7.0" @@ -1557,28 +1331,6 @@ dependencies = [ "universal-hash", ] -[[package]] -name = "pprof" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef5c97c51bd34c7e742402e216abdeb44d415fbe6ae41d56b114723e953711cb" -dependencies = [ - "backtrace", - "cfg-if", - "criterion", - "findshlibs", - "inferno", - "libc", - "log", - "nix", - "once_cell", - "parking_lot", - "smallvec", - "symbolic-demangle", - "tempfile", - "thiserror", -] - [[package]] name = "ppv-lite86" version = "0.2.17" @@ -1691,15 +1443,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "quick-xml" -version = "0.26.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f50b1c63b38611e7d4d7f68b82d3ad0cc71a2ad2e7f61fc10f1328d917c93cd" -dependencies = [ - "memchr", -] - [[package]] name = "quickcheck" version = "1.0.3" @@ -1781,15 +1524,6 @@ dependencies = [ "crossbeam-utils", ] -[[package]] -name = "redox_syscall" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a908a6e00f1fdd0dfd9c0eb08ce85126f6d8bbda50017e74bc4a4b7d4a926a4" -dependencies = [ - "bitflags 2.6.0", -] - [[package]] name = "regex" version = "1.10.5" @@ -1829,15 +1563,6 @@ dependencies = [ "subtle", ] -[[package]] -name = "rgb" -version = "0.8.45" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ade4539f42266ded9e755c605bdddf546242b2c961b03b06a7375260788a0523" -dependencies = [ - "bytemuck", -] - [[package]] name = "ring" version = "0.17.8" @@ -1853,12 +1578,6 @@ dependencies = [ "windows-sys", ] -[[package]] -name = "rustc-demangle" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" - [[package]] name = "rustc-hash" version = "1.1.0" @@ -1880,7 +1599,7 @@ version = "0.38.34" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" dependencies = [ - "bitflags 2.6.0", + "bitflags", "errno", "libc", "linux-raw-sys", @@ -1908,12 +1627,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - [[package]] name = "sec1" version = "0.7.3" @@ -2002,12 +1715,6 @@ dependencies = [ "rand_core", ] -[[package]] -name = "smallvec" -version = "1.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" - [[package]] name = "spin" version = "0.9.8" @@ -2024,18 +1731,6 @@ dependencies = [ "der", ] -[[package]] -name = "stable_deref_trait" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" - -[[package]] -name = "str_stack" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9091b6114800a5f2141aee1d1b9d6ca3592ac062dc5decb3764ec5895a47b4eb" - [[package]] name = "strsim" version = "0.11.1" @@ -2054,29 +1749,6 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "734676eb262c623cec13c3155096e08d1f8f29adce39ba17948b18dad1e54142" -[[package]] -name = "symbolic-common" -version = "12.9.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71297dc3e250f7dbdf8adb99e235da783d690f5819fdeb4cce39d9cfb0aca9f1" -dependencies = [ - "debugid", - "memmap2", - "stable_deref_trait", - "uuid", -] - -[[package]] -name = "symbolic-demangle" -version = "12.9.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "424fa2c9bf2c862891b9cfd354a752751a6730fd838a4691e7f6c2c7957b9daf" -dependencies = [ - "cpp_demangle", - "rustc-demangle", - "symbolic-common", -] - [[package]] name = "syn" version = "1.0.109" @@ -2099,18 +1771,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tempfile" -version = "3.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" -dependencies = [ - "cfg-if", - "fastrand", - "rustix", - "windows-sys", -] - [[package]] name = "termcolor" version = "1.4.1" @@ -2120,26 +1780,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "thiserror" -version = "1.0.63" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.63" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.72", -] - [[package]] name = "tinytemplate" version = "1.2.1" @@ -2334,22 +1974,6 @@ dependencies = [ "rustix", ] -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - [[package]] name = "winapi-util" version = "0.1.8" @@ -2359,12 +1983,6 @@ dependencies = [ "windows-sys", ] -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - [[package]] name = "windows-sys" version = "0.52.0" @@ -2462,26 +2080,6 @@ dependencies = [ "zeroize", ] -[[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.72", -] - [[package]] name = "zeroize" version = "1.8.1" diff --git a/libcrux-ecdh/Cargo.toml b/libcrux-ecdh/Cargo.toml index 6945bd8df..ac8df473c 100644 --- a/libcrux-ecdh/Cargo.toml +++ b/libcrux-ecdh/Cargo.toml @@ -26,9 +26,4 @@ hex = { version = "0.4.3", features = ["serde"] } serde_json = { version = "1.0" } serde = { version = "1.0", features = ["derive"] } pretty_env_logger = "0.5" -criterion = "0.5" -pprof = { version = "0.13.0", features = ["flamegraph", "criterion"]} -[[bench]] -name = "curve25519" -harness = false diff --git a/libcrux-ecdh/benches/curve25519.rs b/libcrux-ecdh/benches/curve25519.rs deleted file mode 100644 index fc23a6fc8..000000000 --- a/libcrux-ecdh/benches/curve25519.rs +++ /dev/null @@ -1,24 +0,0 @@ -use criterion::{black_box, criterion_group, criterion_main, Criterion}; - -use pprof::criterion::{Output, PProfProfiler}; - -pub fn curve_bench(c: &mut Criterion) { - let mut rng = rand::thread_rng(); - let mut group = c.benchmark_group("Curve 25519"); - - let (sk_a, _pk_a) = libcrux_ecdh::x25519_key_gen(&mut rng).unwrap(); - let (_sk_b, pk_b) = libcrux_ecdh::x25519_key_gen(&mut rng).unwrap(); - group.bench_function("ECDH", |b| { - b.iter(|| libcrux_ecdh::hacl::curve25519::ecdh(black_box(&sk_a), black_box(&pk_b))) - }); - group.bench_function("Secret to Public", |b| { - b.iter(|| libcrux_ecdh::hacl::curve25519::secret_to_public(black_box(&sk_a))) - }); -} - - -criterion_group!{name = benches; - config = Criterion::default().with_profiler(PProfProfiler::new(100, Output::Flamegraph(None))); - targets = curve_bench} - -criterion_main!(benches); diff --git a/libcrux-ecdh/src/ecdh.rs b/libcrux-ecdh/src/ecdh.rs index b32862e2a..3b9f11fe5 100644 --- a/libcrux-ecdh/src/ecdh.rs +++ b/libcrux-ecdh/src/ecdh.rs @@ -11,7 +11,7 @@ //! ## P256 //! For P256 the portable HACL implementation is used. -pub mod hacl; +mod hacl; #[derive(Debug, PartialEq, Eq)] pub enum LowLevelError { diff --git a/libcrux-ecdh/src/hacl.rs b/libcrux-ecdh/src/hacl.rs index b55b44f08..77dea8434 100644 --- a/libcrux-ecdh/src/hacl.rs +++ b/libcrux-ecdh/src/hacl.rs @@ -8,7 +8,7 @@ //! | simd128 | - | SSE2, SSE3, SSE4.1 | - | NEON | z14 | //! | simd256 | - | AVX, AVX2 | - | - | - | -pub mod curve25519; +pub(crate) mod curve25519; pub(crate) mod p256; /// Unified error type. From dc4ac696a6c35fbf6ae7beae451a5043f87cffa6 Mon Sep 17 00:00:00 2001 From: Jonas Schneider-Bensch Date: Thu, 1 Aug 2024 16:43:52 +0200 Subject: [PATCH 5/5] Remove obolete README --- libcrux-ecdh/README.md | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 libcrux-ecdh/README.md diff --git a/libcrux-ecdh/README.md b/libcrux-ecdh/README.md deleted file mode 100644 index 5fb0f089e..000000000 --- a/libcrux-ecdh/README.md +++ /dev/null @@ -1,15 +0,0 @@ -# Benchmarks -To run HACL* (C) benchmarks, just run `cargo bench` in this crate. -For the HACL-rs version, run `cargo bench --features hacl-rs`. - -To get flamegraphs, run -``` -cargo bench --bench curve25519 -- --profile-time=5 -``` -or -``` -cargo bench --bench curve25519 --features hacl-rs -- --profile-time=5 -``` - -The flamegraphs can then be found in `../target/criterion/Curve\ -25519/{ECDH/Secret\ to\ Public}/profile/flamegraph.svg`.