libbtc
bitcoinclibrary
|
Go to the source code of this file.
Macros | |
#define | LITTLE_ENDIAN 1234 |
#define | BIG_ENDIAN 4321 |
#define | BYTE_ORDER LITTLE_ENDIAN |
#define | SHA256_SHORT_BLOCK_LENGTH (SHA256_BLOCK_LENGTH - 8) |
#define | SHA512_SHORT_BLOCK_LENGTH (SHA512_BLOCK_LENGTH - 16) |
#define | REVERSE32(w, x) |
#define | REVERSE64(w, x) |
#define | ADDINC128(w, n) |
#define | MEMSET_BZERO(p, l) memset((p), 0, (l)) |
#define | MEMCPY_BCOPY(d, s, l) memcpy((d), (s), (l)) |
#define | R(b, x) ((x) >> (b)) |
#define | S32(b, x) (((x) >> (b)) | ((x) << (32 - (b)))) |
#define | S64(b, x) (((x) >> (b)) | ((x) << (64 - (b)))) |
#define | Ch(x, y, z) (((x) & (y)) ^ ((~(x)) & (z))) |
#define | Maj(x, y, z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z))) |
#define | Sigma0_256(x) (S32(2, (x)) ^ S32(13, (x)) ^ S32(22, (x))) |
#define | Sigma1_256(x) (S32(6, (x)) ^ S32(11, (x)) ^ S32(25, (x))) |
#define | sigma0_256(x) (S32(7, (x)) ^ S32(18, (x)) ^ R(3, (x))) |
#define | sigma1_256(x) (S32(17, (x)) ^ S32(19, (x)) ^ R(10, (x))) |
#define | Sigma0_512(x) (S64(28, (x)) ^ S64(34, (x)) ^ S64(39, (x))) |
#define | Sigma1_512(x) (S64(14, (x)) ^ S64(18, (x)) ^ S64(41, (x))) |
#define | sigma0_512(x) (S64(1, (x)) ^ S64(8, (x)) ^ R(7, (x))) |
#define | sigma1_512(x) (S64(19, (x)) ^ S64(61, (x)) ^ R(6, (x))) |
Typedefs | |
typedef uint8_t | sha2_byte |
typedef uint32_t | sha2_word32 |
typedef uint64_t | sha2_word64 |
Functions | |
void | sha512_Last (SHA512_CTX *) |
void | sha256_Transform (SHA256_CTX *, const sha2_word32 *) |
void | sha512_Transform (SHA512_CTX *, const sha2_word64 *) |
void | sha256_Init (SHA256_CTX *context) |
void | sha256_Update (SHA256_CTX *context, const sha2_byte *data, size_t len) |
void | sha256_Final (sha2_byte digest[], SHA256_CTX *context) |
void | sha256_Raw (const sha2_byte *data, size_t len, uint8_t digest[SHA256_DIGEST_LENGTH]) |
void | sha512_Init (SHA512_CTX *context) |
void | sha512_Update (SHA512_CTX *context, const sha2_byte *data, size_t len) |
void | sha512_Final (sha2_byte digest[], SHA512_CTX *context) |
void | sha512_Raw (const sha2_byte *data, size_t len, uint8_t digest[SHA512_DIGEST_LENGTH]) |
void | hmac_sha256 (const uint8_t *key, const uint32_t keylen, const uint8_t *msg, const uint32_t msglen, uint8_t *hmac) |
void | hmac_sha512 (const uint8_t *key, const uint32_t keylen, const uint8_t *msg, const uint32_t msglen, uint8_t *hmac) |
void | btc_hash (const unsigned char *datain, size_t length, uint256 hashout) |
void | btc_hash_sngl_sha256 (const unsigned char *datain, size_t length, uint256 hashout) |
Variables | |
static const sha2_word32 | K256 [64] |
static const sha2_word32 | sha256_initial_hash_value [8] |
static const sha2_word64 | K512 [80] |
static const sha2_word64 | sha512_initial_hash_value [8] |
#define ADDINC128 | ( | w, | |
n | |||
) |
Definition at line 132 of file sha2.c.
Referenced by sha512_Update().
#define BYTE_ORDER LITTLE_ENDIAN |
Definition at line 93 of file sha2.c.
Referenced by sha256_Transform(), and sha512_Transform().
#define Ch | ( | x, | |
y, | |||
z | |||
) | (((x) & (y)) ^ ((~(x)) & (z))) |
Definition at line 160 of file sha2.c.
Referenced by sha256_Transform(), and sha512_Transform().
#define LITTLE_ENDIAN 1234 |
Copyright (c) 2000-2001 Aaron D. Gifford Copyright (c) 2013 Pavol Rusnak Copyright (c) 2015 Jonas Schnelli All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(S) ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Definition at line 88 of file sha2.c.
Referenced by sha256_Transform(), and sha512_Transform().
#define Maj | ( | x, | |
y, | |||
z | |||
) | (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z))) |
Definition at line 161 of file sha2.c.
Referenced by sha256_Transform(), and sha512_Transform().
#define MEMCPY_BCOPY | ( | d, | |
s, | |||
l | |||
) | memcpy((d), (s), (l)) |
Definition at line 141 of file sha2.c.
Referenced by sha256_Final(), sha256_Init(), sha256_Update(), sha512_Final(), sha512_Init(), and sha512_Update().
#define MEMSET_BZERO | ( | p, | |
l | |||
) | memset((p), 0, (l)) |
Definition at line 140 of file sha2.c.
Referenced by sha256_Final(), sha256_Init(), sha512_Final(), sha512_Init(), and sha512_Last().
#define REVERSE32 | ( | w, | |
x | |||
) |
Definition at line 112 of file sha2.c.
Referenced by sha256_Final(), and sha256_Transform().
#define REVERSE64 | ( | w, | |
x | |||
) |
Definition at line 118 of file sha2.c.
Referenced by sha256_Final(), sha512_Final(), sha512_Last(), and sha512_Transform().
#define SHA256_SHORT_BLOCK_LENGTH (SHA256_BLOCK_LENGTH - 8) |
Definition at line 106 of file sha2.c.
Referenced by sha256_Final().
#define SHA512_SHORT_BLOCK_LENGTH (SHA512_BLOCK_LENGTH - 16) |
Definition at line 107 of file sha2.c.
Referenced by sha512_Last().
Definition at line 164 of file sha2.c.
Referenced by sha256_Transform().
Definition at line 170 of file sha2.c.
Referenced by sha512_Transform().
Definition at line 165 of file sha2.c.
Referenced by sha256_Transform().
Definition at line 171 of file sha2.c.
Referenced by sha512_Transform().
typedef uint32_t sha2_word32 |
typedef uint64_t sha2_word64 |
void btc_hash | ( | const unsigned char * | datain, |
size_t | length, | ||
uint256 | hashout | ||
) |
Definition at line 1026 of file sha2.c.
References sha256_Raw().
Referenced by btc_privkey_verify_pubkey().
void btc_hash_sngl_sha256 | ( | const unsigned char * | datain, |
size_t | length, | ||
uint256 | hashout | ||
) |
Definition at line 1033 of file sha2.c.
References sha256_Raw().
void hmac_sha256 | ( | const uint8_t * | key, |
const uint32_t | keylen, | ||
const uint8_t * | msg, | ||
const uint32_t | msglen, | ||
uint8_t * | hmac | ||
) |
Definition at line 966 of file sha2.c.
References SHA256_BLOCK_LENGTH, SHA256_DIGEST_LENGTH, sha256_Final(), sha256_Init(), sha256_Raw(), and sha256_Update().
void hmac_sha512 | ( | const uint8_t * | key, |
const uint32_t | keylen, | ||
const uint8_t * | msg, | ||
const uint32_t | msglen, | ||
uint8_t * | hmac | ||
) |
Definition at line 996 of file sha2.c.
References SHA512_BLOCK_LENGTH, SHA512_DIGEST_LENGTH, sha512_Final(), sha512_Init(), sha512_Raw(), and sha512_Update().
Referenced by btc_hdnode_from_seed(), btc_hdnode_private_ckd(), and btc_hdnode_public_ckd().
void sha256_Final | ( | sha2_byte | digest[], |
SHA256_CTX * | context | ||
) |
Definition at line 590 of file sha2.c.
References _SHA256_CTX::bitcount, _SHA256_CTX::buffer, MEMCPY_BCOPY, MEMSET_BZERO, REVERSE32, REVERSE64, SHA256_BLOCK_LENGTH, SHA256_DIGEST_LENGTH, SHA256_SHORT_BLOCK_LENGTH, sha256_Transform(), and _SHA256_CTX::state.
Referenced by hmac_sha256(), and sha256_Raw().
void sha256_Init | ( | SHA256_CTX * | context | ) |
Definition at line 360 of file sha2.c.
References _SHA256_CTX::bitcount, _SHA256_CTX::buffer, MEMCPY_BCOPY, MEMSET_BZERO, SHA256_BLOCK_LENGTH, SHA256_DIGEST_LENGTH, sha256_initial_hash_value, and _SHA256_CTX::state.
Referenced by hmac_sha256(), and sha256_Raw().
void sha256_Raw | ( | const sha2_byte * | data, |
size_t | len, | ||
uint8_t | digest[SHA256_DIGEST_LENGTH] | ||
) |
Definition at line 652 of file sha2.c.
References sha256_Final(), sha256_Init(), and sha256_Update().
Referenced by btc_b58check(), btc_base58_encode_check(), btc_hash(), btc_hash_sngl_sha256(), btc_hdnode_private_ckd(), btc_hdnode_public_ckd(), btc_tx_hash(), btc_tx_sighash(), and hmac_sha256().
void sha256_Transform | ( | SHA256_CTX * | context, |
const sha2_word32 * | data | ||
) |
Definition at line 463 of file sha2.c.
References _SHA256_CTX::buffer, BYTE_ORDER, Ch, K256, LITTLE_ENDIAN, Maj, REVERSE32, Sigma0_256, Sigma1_256, and _SHA256_CTX::state.
Referenced by sha256_Final(), and sha256_Update().
void sha256_Update | ( | SHA256_CTX * | context, |
const sha2_byte * | data, | ||
size_t | len | ||
) |
Definition at line 544 of file sha2.c.
References _SHA256_CTX::bitcount, _SHA256_CTX::buffer, MEMCPY_BCOPY, SHA256_BLOCK_LENGTH, and sha256_Transform().
Referenced by hmac_sha256(), and sha256_Raw().
void sha512_Final | ( | sha2_byte | digest[], |
SHA512_CTX * | context | ||
) |
Definition at line 931 of file sha2.c.
References MEMCPY_BCOPY, MEMSET_BZERO, REVERSE64, SHA512_DIGEST_LENGTH, sha512_Last(), and _SHA512_CTX::state.
Referenced by hmac_sha512(), and sha512_Raw().
void sha512_Init | ( | SHA512_CTX * | context | ) |
Definition at line 662 of file sha2.c.
References _SHA512_CTX::bitcount, _SHA512_CTX::buffer, MEMCPY_BCOPY, MEMSET_BZERO, SHA512_BLOCK_LENGTH, SHA512_DIGEST_LENGTH, sha512_initial_hash_value, and _SHA512_CTX::state.
Referenced by hmac_sha512(), and sha512_Raw().
void sha512_Last | ( | SHA512_CTX * | context | ) |
Definition at line 886 of file sha2.c.
References _SHA512_CTX::bitcount, _SHA512_CTX::buffer, MEMSET_BZERO, REVERSE64, SHA512_BLOCK_LENGTH, SHA512_SHORT_BLOCK_LENGTH, and sha512_Transform().
Referenced by sha512_Final().
void sha512_Raw | ( | const sha2_byte * | data, |
size_t | len, | ||
uint8_t | digest[SHA512_DIGEST_LENGTH] | ||
) |
Definition at line 958 of file sha2.c.
References sha512_Final(), sha512_Init(), and sha512_Update().
Referenced by hmac_sha512().
void sha512_Transform | ( | SHA512_CTX * | context, |
const sha2_word64 * | data | ||
) |
Definition at line 761 of file sha2.c.
References _SHA512_CTX::buffer, BYTE_ORDER, Ch, K512, LITTLE_ENDIAN, Maj, REVERSE64, Sigma0_512, Sigma1_512, and _SHA512_CTX::state.
Referenced by sha512_Last(), and sha512_Update().
void sha512_Update | ( | SHA512_CTX * | context, |
const sha2_byte * | data, | ||
size_t | len | ||
) |
Definition at line 840 of file sha2.c.
References ADDINC128, _SHA512_CTX::bitcount, _SHA512_CTX::buffer, MEMCPY_BCOPY, SHA512_BLOCK_LENGTH, and sha512_Transform().
Referenced by hmac_sha512(), and sha512_Raw().
|
static |
Definition at line 187 of file sha2.c.
Referenced by sha256_Transform().
|
static |
Definition at line 265 of file sha2.c.
Referenced by sha512_Transform().
|
static |
Definition at line 254 of file sha2.c.
Referenced by sha256_Init().
|
static |
Definition at line 348 of file sha2.c.
Referenced by sha512_Init().