Skip to main content

bench_ed25519/
lib.rs

1//! Ed25519 signature verification benchmark.
2
3#![cfg_attr(target_os = "none", no_std)]
4
5use subsoil as _;
6
7use ed25519_compact::{PublicKey, Signature};
8
9// RFC 8032 Test Vector 3 (2-byte message)
10const PUBLIC_KEY_BYTES: [u8; 32] = [
11    0xfc, 0x51, 0xcd, 0x8e, 0x62, 0x18, 0xa1, 0xa3, 0x8d, 0xa4, 0x7e, 0xd0, 0x02, 0x30, 0xf0, 0x58,
12    0x08, 0x16, 0xed, 0x13, 0xba, 0x33, 0x03, 0xac, 0x5d, 0xeb, 0x91, 0x15, 0x48, 0x90, 0x80, 0x25,
13];
14
15const MESSAGE: [u8; 2] = [0xaf, 0x82];
16
17const SIGNATURE_BYTES: [u8; 64] = [
18    0x62, 0x91, 0xd6, 0x57, 0xde, 0xec, 0x24, 0x02, 0x48, 0x27, 0xe6, 0x9c, 0x3a, 0xbe, 0x01, 0xa3,
19    0x0c, 0xe5, 0x48, 0xa2, 0x84, 0x74, 0x3a, 0x44, 0x5e, 0x36, 0x80, 0xd7, 0xdb, 0x5a, 0xc3, 0xac,
20    0x18, 0xff, 0x9b, 0x53, 0x8d, 0x16, 0xf2, 0x90, 0xae, 0x67, 0xf7, 0x60, 0x98, 0x4d, 0xc6, 0x59,
21    0x4a, 0x7c, 0x15, 0xe9, 0x71, 0x6e, 0xd2, 0x8d, 0xc0, 0x27, 0xbe, 0xce, 0xea, 0x1e, 0xc4, 0x0a,
22];
23
24/// Verify an Ed25519 signature. Returns 1 on success, 0 on failure.
25pub fn ed25519_verify_bench() -> u32 {
26    let pk = match PublicKey::from_slice(&PUBLIC_KEY_BYTES) {
27        Ok(pk) => pk,
28        Err(_) => return 0,
29    };
30    let sig = match Signature::from_slice(&SIGNATURE_BYTES) {
31        Ok(sig) => sig,
32        Err(_) => return 0,
33    };
34    match pk.verify(MESSAGE, &sig) {
35        Ok(_) => 1,
36        Err(_) => 0,
37    }
38}