libraries/eosiolib/capi/eosio/crypto_ext.h
Functions
Name | |
---|---|
attribute((eosio_wasm_import) ) const | |
int32_t | k1_recover(const char sig, uint32_t sig_len, const char dig, uint32_t dig_len, char * pub, uint32_t pub_len) |
Attributes
Name | |
---|---|
uint32_t | data_len |
uint32_t char * | hash |
uint32_t char uint32_t | hash_len |
uint32_t char uint32_t int32_t | keccak |
const char * | state |
const char uint32_t | state_len |
const char uint32_t const char * | msg |
const char uint32_t const char uint32_t | msg_len |
const char uint32_t const char uint32_t const char * | t0_offset |
const char uint32_t const char uint32_t const char uint32_t | t0_len |
const char uint32_t const char uint32_t const char uint32_t const char * | t1_offset |
const char uint32_t const char uint32_t const char uint32_t const char uint32_t | t1_len |
const char uint32_t const char uint32_t const char uint32_t const char uint32_t int32_t | final |
const char uint32_t const char uint32_t const char uint32_t const char uint32_t int32_t char * | result |
const char uint32_t const char uint32_t const char uint32_t const char uint32_t int32_t char uint32_t | result_len |
uint32_t | op1_len |
uint32_t const char * | op2 |
uint32_t const char uint32_t | op2_len |
uint32_t | g1_len |
uint32_t const char * | scalar |
uint32_t const char uint32_t | scalar_len |
uint32_t | pairs_len |
uint32_t | base_len |
uint32_t const char * | exp |
uint32_t const char uint32_t | exp_len |
uint32_t const char uint32_t const char * | mod |
uint32_t const char uint32_t const char uint32_t | mod_len |
Detailed Description
Copyright: defined in cdt/LICENSE
Functions Documentation
function attribute
__attribute__(
(eosio_wasm_import)
) const
Parameters:
- data - Data you want to hash
- length - Data length
- hash -
capi_checksum256*
hash to compare to - data - Data you want to hash
- length - Data length
- hash -
capi_checksum160*
hash to compare to - data - Data you want to hash
- length - Data length
- hash -
capi_checksum512*
hash to compare to - data - Data you want to hash
- length - Data length
- hash -
capi_checksum160*
hash to compare to - data - Data you want to hash
- length - Data length
- hash - Hash pointer
- data - Data you want to hash
- length - Data length
- hash - Hash pointer
- data - Data you want to hash
- length - Data length
- hash - Hash pointer
- data - Data you want to hash
- data_len - Data length
- hash - Hash pointer
- digest - Hash used to create a message
- sig - Signature
- siglen - Signature length
- pub - Public key
- publen - Public key length
- digest - What the key will be generated from
- sig - Signature
- siglen - Signature length
- pub - Public key
- publen - Public key length
- data - data you want to hash
- data_len - size of data
- hash - hash result
- hash_len - size of hash result
- keccak - whether to use
keccak
or NIST variant; keccak = 1 and NIST == 0 - rounds - the number of rounds
- state - state vector
- state_len - size of state vector
- msg - message block vector
- msg_len - size of message block vector
- t0_offset - offset counters
- t0_len - size of t0_offset
- t1_offset - offset counters
- t1_len - size of t1_offset
- final - final block flag
- result - the result of the compression
- result_len - size of result
- op1 - operand 1
- op1_len - size of operand 1
- op2 - operand 2
- op2_len - size of operand 2
- result - result of the addition operation
- result_len - size of result
- g1 - G1 point
- g1_len - size of G1 point
- scalar - scalar factor
- scalar_len - size of scalar
- result - result of the scalar multiplication operation
- result_len - size of result
- pairs - g1 and g2 pairs
- pairs_len - size of pairs
- result - result of the addition operation
- base - base of the exponentiation (BASE)
- base_len - size of base
- exp - exponent to raise to that power (EXP)
- exp_len - size of exp
- mod - modulus (MOD)
- mod_len - size of mod
- result - result of the modular exponentiation
- result_len - size of result
Return:
- int - number of bytes written to pub
- -1 if there is an error otherwise 0
- -1 if there is an error otherwise 0
- -1 if there is an error otherwise 0
- -1 if there is an error, 1 if false and 0 if true and successful
- -1 if there is an error otherwise 0
Note:
- This method is optimized to a NO-OP when in fast evaluation mode.
- This method is optimized to a NO-OP when in fast evaluation mode.
- This method is optimized to a NO-OP when in fast evaluation mode.
Precondition:
- assert256 hash of
data
equals providedhash
parameter. - sha1 hash of
data
equals providedhash
parameter. - assert512 hash of
data
equals providedhash
parameter. - assert160 hash of
data
equals providedhash
parameter. - assert recovery key of
pub
equals the key generated from thedigest
parameter
Postcondition:
- Executes next statement. If was not
true
, hard return. - Executes next statement. If was not
true
, hard return. - Executes next statement. If was not
true
, hard return. - Executes next statement. If was not
true
, hard return. - Executes next statement. If was not
true
, hard return.
Tests if the sha256 hash generated from data matches the provided checksum.
Example:
checksum hash;
char data;
uint32_t length;
assert_sha256( data, length, hash )
//If the sha256 hash generated from data does not equal provided hash, anything below will never fire.
eosio::print("sha256 hash generated from data equals provided hash");
Tests if the sha1 hash generated from data matches the provided checksum.
Example:
checksum hash;
char data;
uint32_t length;
assert_sha1( data, length, hash )
//If the sha1 hash generated from data does not equal provided hash, anything below will never fire.
eosio::print("sha1 hash generated from data equals provided hash");
Tests if the sha512 hash generated from data matches the provided checksum.
Example:
checksum hash;
char data;
uint32_t length;
assert_sha512( data, length, hash )
//If the sha512 hash generated from data does not equal provided hash, anything below will never fire.
eosio::print("sha512 hash generated from data equals provided hash");
Tests if the ripemod160 hash generated from data matches the provided checksum.
Example:
checksum hash;
char data;
uint32_t length;
assert_ripemod160( data, length, hash )
//If the ripemod160 hash generated from data does not equal provided hash, anything below will never fire.
eosio::print("ripemod160 hash generated from data equals provided hash");
Hashes data
using sha256
and stores result in memory pointed to by hash.
Example:
checksum calc_hash;
sha256( data, length, &calc_hash );
eos_assert( calc_hash == hash, "invalid hash" );
Hashes data
using sha1
and stores result in memory pointed to by hash.
Example:
checksum calc_hash;
sha1( data, length, &calc_hash );
eos_assert( calc_hash == hash, "invalid hash" );
Hashes data
using sha512
and stores result in memory pointed to by hash.
Example:
checksum calc_hash;
sha512( data, length, &calc_hash );
eos_assert( calc_hash == hash, "invalid hash" );
Hashes data
using ripemod160
and stores result in memory pointed to by hash.
Example:
checksum calc_hash;
ripemod160( data, length, &calc_hash );
eos_assert( calc_hash == hash, "invalid hash" );
Calculates the public key used for a given signature and hash used to create a message.
Example:
Tests a given public key with the generated key from digest and the signature.
Example:
checksum digest;
char sig;
size_t siglen;
char pub;
size_t publen;
assert_recover_key( digest, sig, siglen, pub, publen )
// If the given public key does not match with the generated key from digest and the signature, anything below will never fire.
eosio::print("pub key matches the pub key generated from digest");
Hashes data
using sha3
and stores result in memory pointed to by hash.
BLAKE2 compression function "F" https://eips.ethereum.org/EIPS/eip-152
Addition operation on the elliptic curve alt_bn128
Scalar multiplication operation on the elliptic curve alt_bn128
Optimal-Ate pairing check elliptic curve alt_bn128
Big integer modular exponentiation returns an output ( BASE^EXP ) % MOD
function k1_recover
int32_t k1_recover(
const char * sig,
uint32_t sig_len,
const char * dig,
uint32_t dig_len,
char * pub,
uint32_t pub_len
)
Parameters:
- sig - signature.
- sig_len - size of signature
- dig - digest of the message that was signed.
- dig_len - size of digest
- pub - public key result
- pub_len - size of public key result
Return: -1 if there was an error 0 otherwise.
Calculates the uncompressed public key used for a given signature on a given digest.
Attributes Documentation
variable data_len
uint32_t data_len;
variable hash
uint32_t char * hash;
variable hash_len
uint32_t char uint32_t hash_len;
variable keccak
uint32_t char uint32_t int32_t keccak;
variable state
const char * state;
variable state_len
const char uint32_t state_len;
variable msg
const char uint32_t const char * msg;
variable msg_len
const char uint32_t const char uint32_t msg_len;
variable t0_offset
const char uint32_t const char uint32_t const char * t0_offset;
variable t0_len
const char uint32_t const char uint32_t const char uint32_t t0_len;
variable t1_offset
const char uint32_t const char uint32_t const char uint32_t const char * t1_offset;
variable t1_len
const char uint32_t const char uint32_t const char uint32_t const char uint32_t t1_len;
variable final
const char uint32_t const char uint32_t const char uint32_t const char uint32_t int32_t final;
variable result
const char uint32_t const char uint32_t const char uint32_t const char uint32_t int32_t char * result;
variable result_len
const char uint32_t const char uint32_t const char uint32_t const char uint32_t int32_t char uint32_t result_len;
variable op1_len
uint32_t op1_len;
variable op2
uint32_t const char * op2;
variable op2_len
uint32_t const char uint32_t op2_len;
variable g1_len
uint32_t g1_len;
variable scalar
uint32_t const char * scalar;
variable scalar_len
uint32_t const char uint32_t scalar_len;
variable pairs_len
uint32_t pairs_len;
variable base_len
uint32_t base_len;
variable exp
uint32_t const char * exp;
variable exp_len
uint32_t const char uint32_t exp_len;
variable mod
uint32_t const char uint32_t const char * mod;
variable mod_len
uint32_t const char uint32_t const char uint32_t mod_len;
Source code
#pragma once
#include "types.h"
#ifdef __cplusplus
extern "C" {
#endif
__attribute__((eosio_wasm_import))
void sha3( const char* data, uint32_t data_len, char* hash, uint32_t hash_len, int32_t keccak );
__attribute__((eosio_wasm_import))
int32_t blake2_f( uint32_t rounds, const char* state, uint32_t state_len, const char* msg, uint32_t msg_len,
const char* t0_offset, uint32_t t0_len, const char* t1_offset, uint32_t t1_len, int32_t final, char* result, uint32_t result_len);
int32_t k1_recover( const char* sig, uint32_t sig_len, const char* dig, uint32_t dig_len, char* pub, uint32_t pub_len);
__attribute__((eosio_wasm_import))
int32_t alt_bn128_add( const char* op1, uint32_t op1_len, const char* op2, uint32_t op2_len, char* result, uint32_t result_len);
__attribute__((eosio_wasm_import))
int32_t alt_bn128_mul( const char* g1, uint32_t g1_len, const char* scalar, uint32_t scalar_len, char* result, uint32_t result_len);
__attribute__((eosio_wasm_import))
int32_t alt_bn128_pair( const char* pairs, uint32_t pairs_len);
__attribute__((eosio_wasm_import))
int32_t mod_exp( const char* base, uint32_t base_len, const char* exp, uint32_t exp_len, const char* mod, uint32_t mod_len, char* result, uint32_t result_len);
#ifdef __cplusplus
}
#endif
Updated on 2022-12-05 at 15:38:08 +0000