crypto.h
Helper functions for crypto operations.
address_t[ADDRESS_SIZE]
Ethereum address type (20 bytes)
typedef uint8_t address_t[ADDRESS_SIZE];bytes32_t[BYTES32_SIZE]
32-byte hash or value type
typedef uint8_t bytes32_t[BYTES32_SIZE];bls_pubkey_t[BLS_PUBKEY_SIZE]
BLS12-381 public key type (48 bytes compressed)
typedef uint8_t bls_pubkey_t[BLS_PUBKEY_SIZE];bls_signature_t[BLS_SIGNATURE_SIZE]
BLS12-381 signature type (96 bytes)
keccak
Computes the Keccak-256 hash of the input data.
Parameters
data: The input data to hashout: Pointer to 32-byte buffer to store the hash result (must not be NULL)
sha256
Computes the SHA-256 hash of the input data.
Parameters
data: The input data to hashout: Pointer to 32-byte buffer to store the hash result (must not be NULL)
sha256_merkle
Computes the SHA-256 hash of two concatenated data buffers (merkle node hash). This is equivalent to sha256(data1 || data2) but more efficient.
Parameters
data1: The first data bufferdata2: The second data bufferout: Pointer to 32-byte buffer to store the hash result (must not be NULL)
blst_deserialize_p1_affine
Deserializes compressed BLS12-381 public keys into affine point representation. This is used as an optimization to avoid repeated deserialization during verification.
Parameters
compressed_pubkeys: Pointer to compressed public keys (48 bytes each, must not be NULL)num_public_keys: The number of public keys to deserializeout: Optional pre-allocated buffer for the result. If NULL, memory will be allocated.
Returns
A bytes_t containing the deserialized public keys, or NULL_BYTES on error
deserialized)
Verifies a BLS12-381 aggregate signature against a message and a set of public keys. This function aggregates the specified public keys and verifies the signature using pairing operations on the BLS12-381 curve.
Example:
Parameters
message: 32-byte hashed message (must not be NULL)signature: 96-byte BLS signature (must not be NULL)public_keys: Array of public keys, either 48 bytes each (compressed) or 96 bytes each (deserialized affine points) (must not be NULL)num_public_keys: The total number of public keys in the arraypubkey_bitmask: Bitmask indicating which public keys to aggregate (length must be num_public_keys/8)deserialized: If true, public_keys contains deserialized affine points (96 bytes each); if false, compressed keys (48 bytes each)
Returns
true if the signature is valid, false otherwise
secp256k1_recover
Recovers the public key from a secp256k1 ECDSA signature. Used primarily in Ethereum to derive the signer's address from a transaction signature.
Parameters
digest: The 32-byte message digest that was signed (must not be NULL)signature: The signature bytes (must be exactly 65 bytes: r||s||v where v is the recovery id)pubkey: Pointer to 64-byte buffer to store the recovered uncompressed public key (must not be NULL)
Returns
true if recovery was successful, false on error (invalid signature or recovery id)
secp256k1_sign
Signs a digest with a secp256k1 private key using ECDSA.
Parameters
sk: The 32-byte secret key (must not be NULL)digest: The 32-byte message digest to sign (must not be NULL)signature: Pointer to 65-byte buffer to store the signature (r||s||v format, must not be NULL)
Returns
true if signing was successful, false on error (invalid private key)
Last updated