diff --git a/Cargo.toml b/Cargo.toml index f23f4aa..13aaaa7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,7 @@ gmp-mpfr-sys = "1.4.12" criterion = "0.3" [[bench]] -name = "benchmark_e222_256" +name = "benchmark_e222_224" harness = false [[bench]] diff --git a/benches/benchmark_e222_256.rs b/benches/benchmark_e222_224.rs similarity index 82% rename from benches/benchmark_e222_256.rs rename to benches/benchmark_e222_224.rs index 829eff7..f6ff7af 100644 --- a/benches/benchmark_e222_256.rs +++ b/benches/benchmark_e222_224.rs @@ -7,24 +7,25 @@ use capycrypt::sha3::aux_functions::byte_utils::get_random_bytes; use criterion::{criterion_group, criterion_main, Criterion}; const SELECTED_CURVE: EdCurves = E222; +const BIT_SECURITY: u64 = 224; /// Symmetric encrypt and decrypt roundtrip fn sym_enc(pw: &mut Vec, mut msg: Message) { - msg.pw_encrypt(&mut pw.clone(), 256); - msg.pw_decrypt(&mut pw.clone(), 256); + msg.pw_encrypt(&mut pw.clone(), BIT_SECURITY); + msg.pw_decrypt(&mut pw.clone(), BIT_SECURITY); } /// 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(), SELECTED_CURVE, 256); - msg.key_encrypt(&key_pair.pub_key, 256); - msg.key_decrypt(&key_pair.priv_key, 256); + let key_pair = KeyPair::new(pw, "test key".to_string(), SELECTED_CURVE, BIT_SECURITY); + msg.key_encrypt(&key_pair.pub_key, BIT_SECURITY); + msg.key_decrypt(&key_pair.priv_key, BIT_SECURITY); } /// Signature generation + verification roundtrip pub fn sign_verify(mut key_pair: KeyPair, mut msg: Message) { - msg.sign(&mut key_pair, 512); - msg.verify(&key_pair.pub_key, 512); + msg.sign(&mut key_pair, BIT_SECURITY); + msg.verify(&key_pair.pub_key, BIT_SECURITY); } fn bench_sign_verify(c: &mut Criterion) { @@ -35,7 +36,7 @@ fn bench_sign_verify(c: &mut Criterion) { &get_random_bytes(16), "test key".to_string(), SELECTED_CURVE, - 512, + BIT_SECURITY, ), Message::new(&mut get_random_bytes(5242880)), ) @@ -62,7 +63,7 @@ fn bench_key_gen_enc_dec(c: &mut Criterion) { &get_random_bytes(32), "test key".to_string(), SELECTED_CURVE, - 256, + BIT_SECURITY, ) .priv_key, Message::new(&mut get_random_bytes(5242880)), diff --git a/benches/benchmark_e521_512.rs b/benches/benchmark_e521_512.rs index dd7d6bb..7f50768 100644 --- a/benches/benchmark_e521_512.rs +++ b/benches/benchmark_e521_512.rs @@ -7,24 +7,26 @@ use capycrypt::sha3::aux_functions::byte_utils::get_random_bytes; use criterion::{criterion_group, criterion_main, Criterion}; const SELECTED_CURVE: EdCurves = E521; +const BIT_SECURITY: u64 = 512; + /// Symmetric encrypt and decrypt roundtrip fn sym_enc(pw: &mut Vec, mut msg: Message) { - msg.pw_encrypt(&mut pw.clone(), 512); - msg.pw_decrypt(&mut pw.clone(), 512); + msg.pw_encrypt(&mut pw.clone(), BIT_SECURITY); + msg.pw_decrypt(&mut pw.clone(), BIT_SECURITY); } /// 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(), SELECTED_CURVE, 512); - msg.key_encrypt(&key_pair.pub_key, 512); - msg.key_decrypt(&key_pair.priv_key, 512); + let key_pair = KeyPair::new(pw, "test key".to_string(), SELECTED_CURVE, BIT_SECURITY); + msg.key_encrypt(&key_pair.pub_key, BIT_SECURITY); + msg.key_decrypt(&key_pair.priv_key, BIT_SECURITY); } /// Signature generation + verification roundtrip pub fn sign_verify(mut key_pair: KeyPair, mut msg: Message) { - msg.sign(&mut key_pair, 512); - msg.verify(&key_pair.pub_key, 512); + msg.sign(&mut key_pair, BIT_SECURITY); + msg.verify(&key_pair.pub_key, BIT_SECURITY); } fn bench_sign_verify(c: &mut Criterion) { @@ -35,7 +37,7 @@ fn bench_sign_verify(c: &mut Criterion) { &get_random_bytes(16), "test key".to_string(), SELECTED_CURVE, - 512, + BIT_SECURITY, ), Message::new(&mut get_random_bytes(5242880)), ) @@ -62,7 +64,7 @@ fn bench_key_gen_enc_dec(c: &mut Criterion) { &get_random_bytes(32), "test key".to_string(), SELECTED_CURVE, - 512, + BIT_SECURITY, ) .priv_key, Message::new(&mut get_random_bytes(5242880)), diff --git a/src/ops.rs b/src/ops.rs index 8b19019..5722d7b 100644 --- a/src/ops.rs +++ b/src/ops.rs @@ -72,9 +72,11 @@ pub fn cshake(x: &mut Vec, l: u64, n: &str, s: &str, d: u64) -> Vec { encoded_n.extend_from_slice(&encoded_s); let bytepad_w = match d { + 224 => 172, 256 => 168, + 384 => 152, 512 => 136, - _ => panic!("Value must be either 256 or 512"), + _ => panic!("Unsupported security strength. Must be 224, 384, 256, or 512"), }; let mut out = byte_pad(&mut encoded_n, bytepad_w); @@ -100,9 +102,11 @@ pub fn cshake(x: &mut Vec, l: u64, n: &str, s: &str, d: u64) -> Vec { pub fn kmac_xof(k: &Vec, x: &Vec, l: u64, s: &str, d: u64) -> Vec { let mut encode_k = encode_string(k); let bytepad_w = match d { + 224 => 172, 256 => 168, + 384 => 152, 512 => 136, - _ => panic!("Value must be either 256 or 512"), + _ => panic!("Unsupported security strength. Must be 224, 384, 256, or 512"), }; let mut bp = byte_pad(&mut encode_k, bytepad_w); bp.append(&mut x.to_owned());