Skip to content

Commit

Permalink
readme and benches
Browse files Browse the repository at this point in the history
  • Loading branch information
Dr. Capybara committed Dec 11, 2023
1 parent 25e2302 commit 3257821
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 43 deletions.
102 changes: 102 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tiny_ed448_goldilocks"
version = "0.1.3"
version = "0.1.4"
edition = "2021"

license = "MIT"
Expand All @@ -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
Expand All @@ -28,4 +33,4 @@ opt-level = 0
opt-level = 3

[profile.test]
opt-level = 3
opt-level = 3
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 | |
Expand All @@ -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.
76 changes: 38 additions & 38 deletions benches/benchmark_e448_512.rs
Original file line number Diff line number Diff line change
@@ -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<u8>, 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<u8>, 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);

0 comments on commit 3257821

Please sign in to comment.