From 3257821f00f74128c2dc4ed584423018f9e8cfb3 Mon Sep 17 00:00:00 2001 From: "Dr. Capybara" Date: Sun, 10 Dec 2023 22:10:26 -0800 Subject: [PATCH] readme and benches --- Cargo.lock | 102 ++++++++++++++++++++++++++++++++++ Cargo.toml | 9 ++- README.md | 6 +- benches/benchmark_e448_512.rs | 76 ++++++++++++------------- 4 files changed, 150 insertions(+), 43 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 74d8d1f..a6b3932 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -61,6 +61,24 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" +[[package]] +name = "capycrypt" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c1d6e88a8b3162662ab742e4180ee4cf895c257a03ea9e6ad5d94ae8e34649c" +dependencies = [ + "byteorder", + "chrono", + "criterion", + "crypto-bigint", + "fiat-crypto", + "hex", + "num", + "num-bigint", + "rand", + "tiny_ed448_goldilocks 0.1.3", +] + [[package]] name = "cast" version = "0.3.0" @@ -337,6 +355,74 @@ dependencies = [ "autocfg", ] +[[package]] +name = "num" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b05180d69e3da0e530ba2a1dae5110317e49e3b7f3d41be227dc5f92e49ee7af" +dependencies = [ + "num-bigint", + "num-complex", + "num-integer", + "num-iter", + "num-rational", + "num-traits", +] + +[[package]] +name = "num-bigint" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "608e7659b5c3d7cba262d894801b9ec9d00de989e8a82bd4bef91d08da45cdc0" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", + "rand", +] + +[[package]] +name = "num-complex" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ba157ca0885411de85d6ca030ba7e2a83a28636056c7c699b07c8b6f7383214" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-integer" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-iter" +version = "0.1.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d03e6c028c5dc5cac6e2dec0efda81fc887605bb3d884578bb6d6bf7514e252" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-rational" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0" +dependencies = [ + "autocfg", + "num-bigint", + "num-integer", + "num-traits", +] + [[package]] name = "num-traits" version = "0.2.17" @@ -580,8 +666,24 @@ dependencies = [ [[package]] name = "tiny_ed448_goldilocks" version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "304288400eeeca61a1438ece1cba533502b4bc41a95b6dc952767a9f597e5ccd" +dependencies = [ + "byteorder", + "chrono", + "criterion", + "crypto-bigint", + "fiat-crypto", + "hex", + "rand", +] + +[[package]] +name = "tiny_ed448_goldilocks" +version = "0.1.4" dependencies = [ "byteorder", + "capycrypt", "chrono", "criterion", "crypto-bigint", diff --git a/Cargo.toml b/Cargo.toml index 822e0c7..f955eb9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tiny_ed448_goldilocks" -version = "0.1.3" +version = "0.1.4" edition = "2021" license = "MIT" @@ -20,6 +20,11 @@ criterion = "0.3" crypto-bigint = "0.5.3" fiat-crypto = "0.2.2" rand = "0.8" +capycrypt = "0.6.4" + +[[bench]] +name = "benchmark_e448_512" +harness = false [profile.dev] opt-level = 0 @@ -28,4 +33,4 @@ opt-level = 0 opt-level = 3 [profile.test] -opt-level = 3 \ No newline at end of file +opt-level = 3 diff --git a/README.md b/README.md index 6e33172..9c622e8 100644 --- a/README.md +++ b/README.md @@ -88,7 +88,7 @@ Using this crate as the elliptic-curve backend for [capyCRYPT](https://github.co /// Signs a [`Message`] under passphrase pw. /// /// ## Algorithm: -/// * `s` ← kmac_xof(pw, “”, 448, “K”); s ← 4s +/// * `s` ← kmac_xof(pw, “”, 448, “SK”); s ← 4s /// * `k` ← kmac_xof(s, m, 448, “N”); k ← 4k /// * `𝑈` ← k*𝑮; /// * `ℎ` ← kmac_xof(𝑈ₓ , m, 448, “T”); 𝑍 ← (𝑘 – ℎ𝑠) mod r @@ -122,7 +122,7 @@ cargo bench Approximate runtimes for Intel® Core™ i7-10710U × 12 on 5mb random data: -| Operation | ~Time (ms) | OpenSSL | +| Operation | ~Time (ms) | OpenSSL (ms) | |------------|------------|------------| | Encrypt| 75 | | | Decrypt| 75 | | @@ -132,4 +132,4 @@ Approximate runtimes for Intel® Core™ i7-10710U × 12 on 5mb random data: ## Acknowledgements -The authors wish to sincerely thank Dr. Paulo Barreto for the general design of this library as well as the curve functionality. We also wish to extend gratitude to the curve-dalek authors [here](https://github.com/crate-crypto/Ed448-Goldilocks) and [here](https://docs.rs/curve25519-dalek/4.1.1/curve25519_dalek/) for the excellent reference implementations and exemplary instances of rock-solid cryptography. Thanks to [otsmr](https://github.com/otsmr) for the callout on the original attempt at an affine-coordinate Montgomery ladder. +The authors wish to sincerely thank Dr. Paulo Barreto for consultation on the fixed-time operations and his work in the field in general. We also wish to extend gratitude to the curve-dalek authors [here](https://github.com/crate-crypto/Ed448-Goldilocks) and [here](https://docs.rs/curve25519-dalek/4.1.1/curve25519_dalek/) for the excellent reference implementations and exemplary instances of rock-solid cryptography. Thanks to [otsmr](https://github.com/otsmr) for the callout on the original attempt at an affine-coordinate Montgomery ladder. diff --git a/benches/benchmark_e448_512.rs b/benches/benchmark_e448_512.rs index 1f8afab..043de57 100644 --- a/benches/benchmark_e448_512.rs +++ b/benches/benchmark_e448_512.rs @@ -1,44 +1,44 @@ -// use capycrypt::sha3::aux_functions::byte_utils::get_random_bytes; -// use capycrypt::{KeyEncryptable, KeyPair, Message, Signable}; -// use criterion::{criterion_group, criterion_main, Criterion}; +use capycrypt::sha3::aux_functions::byte_utils::get_random_bytes; +use capycrypt::{KeyEncryptable, KeyPair, Message, Signable}; +use criterion::{criterion_group, criterion_main, Criterion}; -// const BIT_SECURITY: u64 = 256; +const BIT_SECURITY: u64 = 256; -// /// Asymmetric encrypt and decrypt roundtrip + keygen -// fn key_gen_enc_dec(pw: &mut Vec, mut msg: Message) { -// let key_pair = KeyPair::new(pw, "test key".to_string(), BIT_SECURITY); -// msg.key_encrypt(&key_pair.pub_key, BIT_SECURITY); -// msg.key_decrypt(&key_pair.priv_key); -// } +/// Asymmetric encrypt and decrypt roundtrip + keygen +fn key_gen_enc_dec(pw: &mut Vec, mut msg: Message) { + let key_pair = KeyPair::new(pw, "test key".to_string(), BIT_SECURITY); + msg.key_encrypt(&key_pair.pub_key, BIT_SECURITY); + msg.key_decrypt(&key_pair.priv_key); +} -// /// Signature generation + verification roundtrip -// pub fn sign_verify(mut key_pair: KeyPair, mut msg: Message) { -// msg.sign(&mut key_pair, BIT_SECURITY); -// // msg.verify(&key_pair.pub_key); -// } +/// Signature generation + verification roundtrip +pub fn sign_verify(mut key_pair: KeyPair, mut msg: Message) { + msg.sign(&mut key_pair, BIT_SECURITY); + // msg.verify(&key_pair.pub_key); +} -// fn bench_sign_verify(c: &mut Criterion) { -// c.bench_function("e448 + SHA3-256 Sign + Verify Roundtrip 5mb", |b| { -// b.iter(|| { -// sign_verify( -// KeyPair::new(&get_random_bytes(16), "test key".to_string(), BIT_SECURITY), -// Message::new(get_random_bytes(5242880)), -// ) -// }); -// }); -// } +fn bench_sign_verify(c: &mut Criterion) { + c.bench_function("e448 + SHA3-256 Sign + Verify Roundtrip 5mb", |b| { + b.iter(|| { + sign_verify( + KeyPair::new(&get_random_bytes(16), "test key".to_string(), BIT_SECURITY), + Message::new(get_random_bytes(5242880)), + ) + }); + }); +} -// fn bench_key_gen_enc_dec(c: &mut Criterion) { -// c.bench_function("e448 + SHA3-256 Asymmetric enc + dec 5mb", |b| { -// b.iter(|| { -// key_gen_enc_dec( -// &mut KeyPair::new(&get_random_bytes(32), "test key".to_string(), BIT_SECURITY) -// .priv_key, -// Message::new(get_random_bytes(5242880)), -// ) -// }); -// }); -// } +fn bench_key_gen_enc_dec(c: &mut Criterion) { + c.bench_function("e448 + SHA3-256 Asymmetric enc + dec 5mb", |b| { + b.iter(|| { + key_gen_enc_dec( + &mut KeyPair::new(&get_random_bytes(32), "test key".to_string(), BIT_SECURITY) + .priv_key, + Message::new(get_random_bytes(5242880)), + ) + }); + }); +} -// criterion_group!(benches, bench_key_gen_enc_dec, bench_sign_verify); -// criterion_main!(benches); +criterion_group!(benches, bench_key_gen_enc_dec, bench_sign_verify); +criterion_main!(benches);