Skip to main content

ethrex_crypto/
native.rs

1use crate::provider::Crypto;
2
3/// Native crypto implementation using system libraries.
4///
5/// Most method bodies live as defaults on the [`Crypto`] trait itself. The
6/// P-256 (secp256r1) verify is overridden here to use the assembly-optimized
7/// `aws-lc-rs` backend when the `aws-lc-rs` feature is enabled, since the
8/// portable `p256` default does two constant-time scalar muls with no
9/// Shamir/basepoint optimization and is a P256VERIFY hot-path outlier. On the
10/// host the BLS12-381 (EIP-2537) defaults likewise route through the
11/// assembly-optimized `blst` backend (the `blst` feature, default-on); zkVM
12/// guest builds compile both backends out and use their own `Crypto` providers
13/// instead of this type. This
14/// struct exists so callers outside zkVM contexts have a concrete type to
15/// instantiate.
16#[derive(Debug)]
17pub struct NativeCrypto;
18
19#[cfg(not(feature = "aws-lc-rs"))]
20impl Crypto for NativeCrypto {}
21
22#[cfg(feature = "aws-lc-rs")]
23impl Crypto for NativeCrypto {
24    fn secp256r1_verify(&self, msg: &[u8; 32], sig: &[u8; 64], pk: &[u8; 64]) -> bool {
25        crate::p256_awslc::secp256r1_verify(msg, sig, pk)
26    }
27}