I am using p-384 crate for signature verification of API requests made from a site:
https://docs.rs/p384/latest/p384/ecdsa/index.html
Here's my test code:
use p384::elliptic_curve::rand_core;
use p384::ecdsa::{signature::Signer, Signature, SigningKey};
use rand_core::OsRng;
// Signing
let signing_key = SigningKey::random(&mut OsRng); // Serialize with `::to_bytes()`
let message = b"ECDSA proves knowledge of a secret number in the context of a single message";
let signature: Signature = signing_key.sign(message);
// Verification
use p384::ecdsa::{signature::Verifier, VerifyingKey};
let verifying_key = VerifyingKey::from(&signing_key);
let now = Instant::now();
match verifying_key.verify(message, &signature) {
Ok(_) => {
println!("Verification passed!");
},
Err(e) => {
println!("Verification failed: {:?}",e);
},
}
println!("Verification time: {:.2?}", now.elapsed());
This outputs:
Verification passed!
Verification time: 29.41ms
The verification is adding about 30ms for all my network requests. While it's a tiny amount, it adds up on the client side. A website which loads in 5ms now loads in 35-40ms. It goes from blazing fast to "okay fast".
This is on Mac mini 3 GHz 6-Core Intel Core i5 with macOS 13.4.1.
Is there any techniques or tuning or caching or something I can use to speed this up?