Skip to content
This repository has been archived by the owner on May 25, 2024. It is now read-only.

Commit

Permalink
Mandel RC2 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jafri authored and conr2d committed Jul 23, 2022
1 parent 7c52dd6 commit 156ada3
Show file tree
Hide file tree
Showing 8 changed files with 219 additions and 1,620 deletions.
107 changes: 106 additions & 1 deletion libraries/eosiolib/capi/eosio/crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,24 @@ 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 );

/**
* Hashes `data` using `sha3` and stores result in memory pointed to by hash.
*
* @param data - data you want to hash
* @param data_len - size of data
* @param hash - hash result
* @param hash_len - size of hash result
* @param keccak - whether to use `keccak` or NIST variant; keccak = 1 and NIST == 0
*
*/
__attribute__((eosio_wasm_import))
void sha3( const char* data, uint32_t data_len, char* hash, uint32_t hash_len, int32_t keccak );

/**
* Hashes `data` using `ripemod160` and stores result in memory pointed to by hash.
*
* @param data - Data you want to hash
* @param length - Data length
* @param data_len - Data length
* @param hash - Hash pointer
*
* Example:
Expand All @@ -186,6 +199,28 @@ 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 );

/**
* BLAKE2 compression function "F"
* https://eips.ethereum.org/EIPS/eip-152
*
* @param rounds - the number of rounds
* @param state - state vector
* @param state_len - size of state vector
* @param msg - message block vector
* @param msg_len - size of message block vector
* @param t0_offset - offset counters
* @param t0_len - size of t0_offset
* @param t1_offset - offset counters
* @param t1_len - size of t1_offset
* @param final - final block flag
* @param result - the result of the compression
* @param result_len - size of result
* @return -1 if there is an error otherwise 0
*/
__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);

/**
* Calculates the public key used for a given signature and hash used to create a message.
*
Expand Down Expand Up @@ -232,6 +267,76 @@ int recover_key( const struct capi_checksum256* digest, const char* sig, size_t
__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 );

/**
* Calculates the uncompressed public key used for a given signature on a given digest.
*
* @param sig - signature.
* @param sig_len - size of signature
* @param dig - digest of the message that was signed.
* @param dig_len - size of digest
* @param pub - public key result
* @param pub_len - size of public key result
*
* @return -1 if there was an error 0 otherwise.
*/
int32_t k1_recover( const char* sig, uint32_t sig_len, const char* dig, uint32_t dig_len, char* pub, uint32_t pub_len);

/**
* Addition operation on the elliptic curve `alt_bn128`
*
* @param op1 - operand 1
* @param op1_len - size of operand 1
* @param op2 - operand 2
* @param op2_len - size of operand 2
* @param result - result of the addition operation
* @param result_len - size of result
* @return -1 if there is an error otherwise 0
*/
__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);

/**
* Scalar multiplication operation on the elliptic curve `alt_bn128`
*
* @param g1 - G1 point
* @param g1_len - size of G1 point
* @param scalar - scalar factor
* @param scalar_len - size of scalar
* @param result - result of the scalar multiplication operation
* @param result_len - size of result
* @return -1 if there is an error otherwise 0
*/
__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);

/**
* Optimal-Ate pairing check elliptic curve `alt_bn128`
*
* @param pairs - g1 and g2 pairs
* @param pairs_len - size of pairs
* @param result - result of the addition operation
* @return -1 if there is an error, 1 if false and 0 if true and successful
*/
__attribute__((eosio_wasm_import))
int32_t alt_bn128_pair( const char* pairs, uint32_t pairs_len);

/**
* Big integer modular exponentiation
* returns an output ( BASE^EXP ) % MOD
*
* @param base - base of the exponentiation (BASE)
* @param base_len - size of base
* @param exp - exponent to raise to that power (EXP)
* @param exp_len - size of exp
* @param mod - modulus (MOD)
* @param mod_len - size of mod
* @param result - result of the modular exponentiation
* @param result_len - size of result
* @return -1 if there is an error otherwise 0
*/
__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
Expand Down
8 changes: 8 additions & 0 deletions libraries/eosiolib/capi/eosio/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ void eosio_exit( int32_t code );
__attribute__((eosio_wasm_import))
uint64_t current_time( void );

/**
* Returns the current block number
*
* @return current block number
*/
__attribute__((eosio_wasm_import))
uint32_t get_block_num( void );

/**
* Check if specified protocol feature has been activated
*
Expand Down
Loading

0 comments on commit 156ada3

Please sign in to comment.