pub struct NativeCrypto;Expand description
Native crypto implementation using system libraries.
Most method bodies live as defaults on the Crypto trait itself. The
P-256 (secp256r1) verify is overridden here to use the assembly-optimized
aws-lc-rs backend when the aws-lc-rs feature is enabled, since the
portable p256 default does two constant-time scalar muls with no
Shamir/basepoint optimization and is a P256VERIFY hot-path outlier. On the
host the BLS12-381 (EIP-2537) defaults likewise route through the
assembly-optimized blst backend (the blst feature, default-on); zkVM
guest builds compile both backends out and use their own Crypto providers
instead of this type. BN254 ECADD/ECMUL use the dedicated G1 code in
[crate::bn254], which avoids the generic decoding, inversion and scalar
multiplication paths of the trait defaults. This
struct exists so callers outside zkVM contexts have a concrete type to
instantiate.
Trait Implementations§
Source§impl Crypto for NativeCrypto
impl Crypto for NativeCrypto
Source§fn modexp(
&self,
base: &[u8],
exp: &[u8],
modulus: &[u8],
) -> Result<Vec<u8>, CryptoError>
fn modexp( &self, base: &[u8], exp: &[u8], modulus: &[u8], ) -> Result<Vec<u8>, CryptoError>
Odd moduli of up to 128 bytes take the fixed-width Montgomery path; everything else uses the arbitrary-precision default.
Source§fn bn254_g1_add(&self, p1: &[u8], p2: &[u8]) -> Result<[u8; 64], CryptoError>
fn bn254_g1_add(&self, p1: &[u8], p2: &[u8]) -> Result<[u8; 64], CryptoError>
>= p first, as the precompile does: implementations
differ there (NativeCrypto rejects them, this default reduces them mod p).Source§fn bn254_g1_mul(
&self,
point: &[u8],
scalar: &[u8],
) -> Result<[u8; 64], CryptoError>
fn bn254_g1_mul( &self, point: &[u8], scalar: &[u8], ) -> Result<[u8; 64], CryptoError>
>= p first, as the precompile does: implementations
differ there (NativeCrypto rejects them, this default reduces them mod p).Source§fn bn254_pairing_check(
&self,
pairs: &[(&[u8], &[u8])],
) -> Result<bool, CryptoError>
fn bn254_pairing_check( &self, pairs: &[(&[u8], &[u8])], ) -> Result<bool, CryptoError>
>= p first, as the precompile does: implementations
differ there (NativeCrypto rejects them, this default reduces them mod p).Source§fn secp256k1_ecrecover(
&self,
sig: &[u8; 64],
recid: u8,
msg: &[u8; 32],
) -> Result<[u8; 32], CryptoError>
fn secp256k1_ecrecover( &self, sig: &[u8; 64], recid: u8, msg: &[u8; 32], ) -> Result<[u8; 32], CryptoError>
Source§fn recover_signer(
&self,
sig: &[u8; 65],
msg: &[u8; 32],
) -> Result<H160, CryptoError>
fn recover_signer( &self, sig: &[u8; 65], msg: &[u8; 32], ) -> Result<H160, CryptoError>
Source§fn keccak256(&self, input: &[u8]) -> [u8; 32]
fn keccak256(&self, input: &[u8]) -> [u8; 32]
Source§fn sha256(&self, input: &[u8]) -> [u8; 32]
fn sha256(&self, input: &[u8]) -> [u8; 32]
Source§fn ripemd160(&self, input: &[u8]) -> [u8; 32]
fn ripemd160(&self, input: &[u8]) -> [u8; 32]
Source§fn mulmod256(&self, a: &[u8; 32], b: &[u8; 32], m: &[u8; 32]) -> [u8; 32]
fn mulmod256(&self, a: &[u8; 32], b: &[u8; 32], m: &[u8; 32]) -> [u8; 32]
crate::u256_div::mul_mod.
ZisK overrides with a native circuit instruction.Source§fn blake2_compress(
&self,
rounds: u32,
h: &mut [u64; 8],
m: [u64; 16],
t: [u64; 2],
f: bool,
)
fn blake2_compress( &self, rounds: u32, h: &mut [u64; 8], m: [u64; 16], t: [u64; 2], f: bool, )
Source§fn secp256r1_verify(
&self,
msg: &[u8; 32],
sig: &[u8; 64],
pk: &[u8; 64],
) -> bool
fn secp256r1_verify( &self, msg: &[u8; 32], sig: &[u8; 64], pk: &[u8; 64], ) -> bool
fn verify_kzg_proof( &self, z: &[u8; 32], y: &[u8; 32], commitment: &[u8; 48], proof: &[u8; 48], ) -> Result<(), CryptoError>
fn verify_blob_kzg_proof( &self, blob: &[u8], commitment: &[u8; 48], proof: &[u8; 48], ) -> Result<bool, CryptoError>
Source§fn bls12_381_g1_add(
&self,
a: ([u8; 48], [u8; 48]),
b: ([u8; 48], [u8; 48]),
) -> Result<[u8; 96], CryptoError>
fn bls12_381_g1_add( &self, a: ([u8; 48], [u8; 48]), b: ([u8; 48], [u8; 48]), ) -> Result<[u8; 96], CryptoError>
Source§fn bls12_381_g1_msm(
&self,
pairs: &[(([u8; 48], [u8; 48]), [u8; 32])],
) -> Result<[u8; 96], CryptoError>
fn bls12_381_g1_msm( &self, pairs: &[(([u8; 48], [u8; 48]), [u8; 32])], ) -> Result<[u8; 96], CryptoError>
Source§fn bls12_381_g2_add(
&self,
a: ([u8; 48], [u8; 48], [u8; 48], [u8; 48]),
b: ([u8; 48], [u8; 48], [u8; 48], [u8; 48]),
) -> Result<[u8; 192], CryptoError>
fn bls12_381_g2_add( &self, a: ([u8; 48], [u8; 48], [u8; 48], [u8; 48]), b: ([u8; 48], [u8; 48], [u8; 48], [u8; 48]), ) -> Result<[u8; 192], CryptoError>
Source§fn bls12_381_g2_msm(
&self,
pairs: &[(([u8; 48], [u8; 48], [u8; 48], [u8; 48]), [u8; 32])],
) -> Result<[u8; 192], CryptoError>
fn bls12_381_g2_msm( &self, pairs: &[(([u8; 48], [u8; 48], [u8; 48], [u8; 48]), [u8; 32])], ) -> Result<[u8; 192], CryptoError>
Source§fn bls12_381_pairing_check(
&self,
pairs: &[(([u8; 48], [u8; 48]), ([u8; 48], [u8; 48], [u8; 48], [u8; 48]))],
) -> Result<bool, CryptoError>
fn bls12_381_pairing_check( &self, pairs: &[(([u8; 48], [u8; 48]), ([u8; 48], [u8; 48], [u8; 48], [u8; 48]))], ) -> Result<bool, CryptoError>
Source§fn bls12_381_fp_to_g1(&self, fp: &[u8; 48]) -> Result<[u8; 96], CryptoError>
fn bls12_381_fp_to_g1(&self, fp: &[u8; 48]) -> Result<[u8; 96], CryptoError>
Auto Trait Implementations§
impl Freeze for NativeCrypto
impl RefUnwindSafe for NativeCrypto
impl Send for NativeCrypto
impl Sync for NativeCrypto
impl Unpin for NativeCrypto
impl UnsafeUnpin for NativeCrypto
impl UnwindSafe for NativeCrypto
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.