pub trait CryptoOps {
// Required methods
fn verify_signature(
&self,
sig_type: SignatureType,
signature: &[u8],
signer: &Address,
plaintext: &[u8],
) -> Result<bool>;
fn verify_bls_aggregate(
&self,
aggregate_sig: &[u8; 96],
pub_keys: &[[u8; 48]],
plaintexts_concat: &[u8],
plaintext_lens: &[u32],
) -> Result<bool>;
fn recover_secp_public_key(
&self,
hash: &[u8; 32],
signature: &[u8; 65],
) -> Result<[u8; 65]>;
fn hash(&self, code: u64, data: &[u8]) -> Result<Multihash>;
}
Expand description
Cryptographic primitives provided by the kernel.
Required Methods§
sourcefn verify_signature(
&self,
sig_type: SignatureType,
signature: &[u8],
signer: &Address,
plaintext: &[u8],
) -> Result<bool>
fn verify_signature( &self, sig_type: SignatureType, signature: &[u8], signer: &Address, plaintext: &[u8], ) -> Result<bool>
Verifies that a signature is valid for an address and plaintext.
sourcefn verify_bls_aggregate(
&self,
aggregate_sig: &[u8; 96],
pub_keys: &[[u8; 48]],
plaintexts_concat: &[u8],
plaintext_lens: &[u32],
) -> Result<bool>
fn verify_bls_aggregate( &self, aggregate_sig: &[u8; 96], pub_keys: &[[u8; 48]], plaintexts_concat: &[u8], plaintext_lens: &[u32], ) -> Result<bool>
Verifies a BLS aggregate signature. In the case where there is one signer/signed plaintext, this is equivalent to verifying a non-aggregated BLS signature.
Returns:
Ok(true)
on a valid signature.Ok(false)
on an invalid signature or if the signature or public keys’ bytes represent an invalid curve point.Err(IllegalArgument)
ifpub_keys.len() != plaintexts.len()
.
sourcefn recover_secp_public_key(
&self,
hash: &[u8; 32],
signature: &[u8; 65],
) -> Result<[u8; 65]>
fn recover_secp_public_key( &self, hash: &[u8; 32], signature: &[u8; 65], ) -> Result<[u8; 65]>
Given a message hash and its signature, recovers the public key of the signer.
sourcefn hash(&self, code: u64, data: &[u8]) -> Result<Multihash>
fn hash(&self, code: u64, data: &[u8]) -> Result<Multihash>
Hashes input data_in
using with the specified hash function, writing the output to
digest_out
, returning the size of the digest written to digest_out
. If digest_out
is
to small to fit the entire digest, it will be truncated. If too large, the leftover space
will not be overwritten.