본문으로 건너뛰기

libraries/eosiolib/capi/eosio/crypto.h

More...

Functions

Name
attribute((eosio_wasm_import) ) const

Attributes

Name
uint32_tlength
uint32_t const struct capi_checksum256 *hash
const char *sig
const char size_tsiglen
const char size_t char *pub
const char size_t char size_tpublen

Detailed Description

Copyright: defined in eos/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 provided hash parameter.
  • sha1 hash of data equals provided hash parameter.
  • assert512 hash of data equals provided hash parameter.
  • assert160 hash of data equals provided hash parameter.
  • assert recovery key of pub equals the key generated from the digest 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

Attributes Documentation

variable length

uint32_t length;

variable hash

uint32_t const struct capi_checksum256 * hash;

variable sig

const char * sig;

variable siglen

const char size_t siglen;

variable pub

const char size_t char * pub;

variable publen

const char size_t char size_t publen;

Source code


#pragma once
#include "types.h"
#ifdef __cplusplus
extern "C" {
#endif

__attribute__((eosio_wasm_import))
void assert_sha256( const char* data, uint32_t length, const struct capi_checksum256* hash );

__attribute__((eosio_wasm_import))
void assert_sha1( const char* data, uint32_t length, const struct capi_checksum160* hash );

__attribute__((eosio_wasm_import))
void assert_sha512( const char* data, uint32_t length, const struct capi_checksum512* hash );

__attribute__((eosio_wasm_import))
void assert_ripemd160( const char* data, uint32_t length, const struct capi_checksum160* hash );

__attribute__((eosio_wasm_import))
void sha256( const char* data, uint32_t length, struct capi_checksum256* hash );

__attribute__((eosio_wasm_import))
void sha1( const char* data, uint32_t length, struct capi_checksum160* hash );

__attribute__((eosio_wasm_import))
void sha512( const char* data, uint32_t length, struct capi_checksum512* hash );

__attribute__((eosio_wasm_import))
void ripemd160( const char* data, uint32_t length, struct capi_checksum160* hash );

__attribute__((eosio_wasm_import))
int recover_key( const struct capi_checksum256* digest, const char* sig, size_t siglen, char* pub, size_t publen );

__attribute__((eosio_wasm_import))
void assert_recover_key( const struct capi_checksum256* digest, const char* sig, size_t siglen, const char* pub, size_t publen );

#ifdef __cplusplus
}
#endif

Updated on 2022-12-05 at 15:38:08 +0000