跳到主要内容

libraries/eosiolib/core/eosio/crypto_ext.hpp

More...

Namespaces

Name
eosio
eosio::internal_use_do_not_use

Detailed Description

Copyright: defined in cdt/LICENSE

Source code


#pragma once

#include "fixed_bytes.hpp"
#include "varint.hpp"
#include "serialize.hpp"

#include <array>

namespace eosio {

namespace internal_use_do_not_use {
extern "C" {

struct __attribute__((aligned (16))) capi_checksum256_ext { uint8_t hash[32]; };

__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);

__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);

__attribute__((eosio_wasm_import))
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))
void sha3( const char* data, uint32_t data_len, char* hash, uint32_t hash_len, int32_t keccak );
}

static inline auto sha3_helper(const char* data, uint32_t length, bool keccak) {
internal_use_do_not_use::capi_checksum256_ext hash;
internal_use_do_not_use::sha3( data, length, (char*)&hash, sizeof(hash), keccak);
eosio::checksum256 dg;
eosio::datastream<uint8_t*> ds = {&hash.hash[0], sizeof(hash)};
ds >> dg;
return dg;
}
}

inline 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 ) {
return internal_use_do_not_use::alt_bn128_add( op1, op1_len, op2, op2_len, result, result_len);
}

inline 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 ) {
return internal_use_do_not_use::alt_bn128_mul( g1, g1_len, scalar, scalar_len, result, result_len );
}

inline int32_t alt_bn128_pair( const char* pairs, uint32_t pairs_len ) {
return internal_use_do_not_use::alt_bn128_pair( pairs, pairs_len );
}

inline 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 ) {
return internal_use_do_not_use::mod_exp( base, base_len, exp, exp_len, mod, mod_len, result, result_len);
}

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) {
return internal_use_do_not_use::blake2_f( rounds, state, state_len, msg, msg_len, t0_offset, t0_len, t1_offset, t1_len, final, result, result_len);
}

inline eosio::checksum256 sha3(const char* data, uint32_t length) {
return internal_use_do_not_use::sha3_helper(data, length, false);
}

inline void assert_sha3(const char* data, uint32_t length, const eosio::checksum256& hash) {
const auto& res = internal_use_do_not_use::sha3_helper(data, length, false);
check( hash == res, "SHA3 hash of `data` does not match given `hash`");
}

inline eosio::checksum256 keccak(const char* data, uint32_t length) {
return internal_use_do_not_use::sha3_helper(data, length, true);
}

inline void assert_keccak(const char* data, uint32_t length, const eosio::checksum256& hash) {
const auto& res = internal_use_do_not_use::sha3_helper(data, length, true);
check( hash == res, "Keccak hash of `data` does not match given `hash`");
}

inline int32_t k1_recover( const char* sig, uint32_t sig_len, const char* dig, uint32_t dig_len, char* pub, uint32_t pub_len ) {
return internal_use_do_not_use::k1_recover( sig, sig_len, dig, dig_len, pub, pub_len );
}
}

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