p256/
ecdsa.rs

1// re-export types that are visible in the p256 crate for API compatibility
2
3// Use these types instead of unpatched p256::ecdsa::{Signature, VerifyingKey}
4// because those are type aliases that use non-zkvm implementations
5
6pub use ecdsa_core::signature::{self, Error};
7#[cfg(feature = "ecdsa")]
8use openvm_ecc_guest::ecdsa::VerifyCustomHook;
9#[cfg(feature = "ecdsa")]
10use {super::P256Point, ecdsa_core::hazmat::VerifyPrimitive};
11
12use super::NistP256;
13
14/// ECDSA/secp256k1 signature (fixed-size)
15pub type Signature = ecdsa_core::Signature<NistP256>;
16
17/// ECDSA/secp256k1 signing key
18#[cfg(feature = "ecdsa")]
19pub type SigningKey = ecdsa_core::SigningKey<NistP256>;
20
21/// ECDSA/secp256k1 verification key (i.e. public key)
22#[cfg(feature = "ecdsa")]
23pub type VerifyingKey = openvm_ecc_guest::ecdsa::VerifyingKey<NistP256>;
24
25// No custom hook
26#[cfg(feature = "ecdsa")]
27impl VerifyCustomHook<NistP256> for P256Point {}
28
29#[cfg(feature = "ecdsa")]
30impl VerifyPrimitive<NistP256> for P256Point {
31    fn verify_prehashed(
32        &self,
33        z: &crate::point::FieldBytes,
34        sig: &Signature,
35    ) -> Result<(), ecdsa_core::Error> {
36        openvm_ecc_guest::ecdsa::verify_prehashed::<NistP256>(
37            *self,
38            z.as_slice(),
39            sig.to_bytes().as_slice(),
40        )
41        .map_err(|_| ecdsa_core::Error::new())
42    }
43}