crypto.h 2.6 KB
Newer Older
1 2 3 4
/**
 *  @file
 *  @copyright defined in eos/LICENSE.txt
 */
5
#pragma once
6
#include <eosiolib/types.h>
M
Matias Romeo 已提交
7
extern "C" {
8 9 10
/**
 *  This method is implemented as:
 *
A
Andrianto Lie 已提交
11
 *  checksum calc_hash;
12
 *  sha256( data, length, &calc_hash );
13
 *  eosio_assert( calc_hash == hash, "invalid hash" );
14 15 16
 *
 *  This method is optimized to a NO-OP when in fast evaluation mode
 */
17
void assert_sha256( char* data, uint32_t length, const checksum256* hash );
B
Bucky Kittinger 已提交
18 19 20 21 22 23 24 25 26 27

/**
 *  This method is implemented as:
 *
 *  checksum calc_hash;
 *  sha1( data, length, &calc_hash );
 *  eos_assert( calc_hash == hash, "invalid hash" );
 *
 *  This method is optimized to a NO-OP when in fast evaluation mode
 */
28
void assert_sha1( char* data, uint32_t length, const checksum160* hash );
B
Bucky Kittinger 已提交
29 30 31 32 33 34 35 36 37 38

/**
 *  This method is implemented as:
 *
 *  checksum calc_hash;
 *  sha512( data, length, &calc_hash );
 *  eos_assert( calc_hash == hash, "invalid hash" );
 *
 *  This method is optimized to a NO-OP when in fast evaluation mode
 */
39
void assert_sha512( char* data, uint32_t length, const checksum512* hash );
B
Bucky Kittinger 已提交
40 41 42 43 44 45 46 47 48 49

/**
 *  This method is implemented as:
 *
 *  checksum calc_hash;
 *  ripemd160( data, length, &calc_hash );
 *  eos_assert( calc_hash == hash, "invalid hash" );
 *
 *  This method is optimized to a NO-OP when in fast evaluation mode
 */
50
void assert_ripemd160( char* data, uint32_t length, const checksum160* hash );
51 52 53

/**
 *  Calculates sha256( data,length) and stores result in memory pointed to by hash 
B
Bucky Kittinger 已提交
54 55
 *  `hash` should be checksum<256>
 */
56
void sha256( char* data, uint32_t length, checksum256* hash );
B
Bucky Kittinger 已提交
57 58 59 60

/**
 *  Calculates sha1( data,length) and stores result in memory pointed to by hash 
 *  `hash` should be checksum<160>
61
 */
62
void sha1( char* data, uint32_t length, checksum160* hash );
B
Bucky Kittinger 已提交
63 64 65 66 67

/**
 *  Calculates sha512( data,length) and stores result in memory pointed to by hash 
 *  `hash` should be checksum<512>
 */
68
void sha512( char* data, uint32_t length, checksum512* hash );
B
Bucky Kittinger 已提交
69 70 71 72 73

/**
 *  Calculates ripemd160( data,length) and stores result in memory pointed to by hash 
 *  `hash` should be checksum<160>
 */
74
void ripemd160( char* data, uint32_t length, checksum160* hash );
B
Bucky Kittinger 已提交
75 76

/**
B
Bucky Kittinger 已提交
77 78
 * Calculates the public key used for a given signature and hash used to create a message and places it in `pub`
 * returns the number of bytes read into pub
B
Bucky Kittinger 已提交
79 80
 * `digest` should be checksum<256>
 */
K
Kevin Heifner 已提交
81
int recover_key( const checksum256* digest, const char* sig, size_t siglen, char* pub, size_t publen );
B
Bucky Kittinger 已提交
82

B
Bucky Kittinger 已提交
83 84 85 86
/**
 * Tests a given public key with the generated key from digest and the signature
 * `digest` should be checksum<256>
 */
K
Kevin Heifner 已提交
87
void assert_recover_key( const checksum256* digest, const char* sig, size_t siglen, const char* pub, size_t publen );
B
Bucky Kittinger 已提交
88

A
Anton Perkov 已提交
89
}