-1

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?

  • 3
    Standard question that must be asked anyway: are you running in a release mode? – Aleksander Krauze Aug 04 '23 at 09:45
  • @AleksanderKrauze WOW! That made a big difference. I just tested in release mode and it was down to just around 1.3ms to 1.5ms which is a lot more acceptable. Thanks for the suggestion. If you post as an answer, I will accept it. – sudoExclaimationExclaimation Aug 04 '23 at 18:04
  • 1
    thanks, but this is not really an answer, so I couldn't accept it. Just remember that rust (and most other compiled languages) when compiled in a "debug" mode do not enable any (or only very insignificant) optimizations. And when you do enable then (in rust by compiling in a release mode) you will often get _massive_ performance improvements, because as it turns out compilers are _really good_ at optimizing code. – Aleksander Krauze Aug 04 '23 at 20:11

1 Answers1

0

As answered by @AleksanderKrauze:

After testing in release mode instead of debug mode, it was down to just around 1.3ms to 1.5ms which is a lot more acceptable.