Skip to content

Commit 6968f36

Browse files
zh-jqcursoragent
andcommitted
vey-crypto-mb: fix Ed25519 verify to use public key
Match vey-bench keyless verify_ed (EVP_PKEY_verify on the public key) and keep the helper local to the ed25519 test. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 37ea724 commit 6968f36

2 files changed

Lines changed: 17 additions & 14 deletions

File tree

lib/vey-crypto-mb/tests/common/mod.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,3 @@ pub fn test_ecdsa_sign<const N: usize>(key: &PKey<Private>, digest: &[u8], slot:
124124
"EVP_PKEY_verify failed"
125125
);
126126
}
127-
128-
/// `EVP_PKEY_verify`.
129-
pub fn verify_ed25519(key: &PKey<Private>, sig: &[u8], msg: &[u8]) {
130-
let mut ctx = PkeyCtx::new(key).expect("pkey ctx");
131-
ctx.verify_init().expect("verify init");
132-
assert_eq!(
133-
ctx.verify(msg, sig).ok(),
134-
Some(true),
135-
"Ed25519 EVP_PKEY_verify failed"
136-
);
137-
}

lib/vey-crypto-mb/tests/ed25519.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
mod common;
77

8-
use openssl::pkey::PKey;
8+
use openssl::pkey::{Id, PKey, Private};
9+
use openssl::pkey_ctx::PkeyCtx;
910

1011
use vey_crypto_mb::{Ed25519Slot, ed25519_sign_mb8, status_ok};
1112

@@ -30,6 +31,19 @@ fn ed25519_sign() {
3031
"statuses={statuses:?}"
3132
);
3233

33-
common::verify_ed25519(&key0, slots[0].signature(), msg0);
34-
common::verify_ed25519(&key1, slots[1].signature(), msg1);
34+
verify_ed25519(&key0, slots[0].signature(), msg0);
35+
verify_ed25519(&key1, slots[1].signature(), msg1);
36+
}
37+
38+
/// `EVP_PKEY_verify` with the public key, matching vey-bench keyless `verify_ed`.
39+
fn verify_ed25519(key: &PKey<Private>, sig: &[u8], msg: &[u8]) {
40+
let pub_raw = key.raw_public_key().expect("ed25519 public key");
41+
let public_key =
42+
PKey::public_key_from_raw_bytes(&pub_raw, Id::ED25519).expect("pkey from raw public");
43+
let mut ctx = PkeyCtx::new(&public_key).expect("pkey ctx");
44+
ctx.verify_init().expect("verify init");
45+
assert!(
46+
ctx.verify(msg, sig).expect("verify"),
47+
"Ed25519 EVP_PKEY_verify failed"
48+
);
3549
}

0 commit comments

Comments
 (0)