1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-26 01:18:28 +00:00

replace SHA256/SHA512 prefix with sha256/sha512 (OpenSSL clash)

This commit is contained in:
Pavol Rusnak 2014-02-19 21:26:42 +01:00
parent 1034b28f90
commit d0e152a088
7 changed files with 73 additions and 73 deletions

View File

@ -71,7 +71,7 @@ int hdnode_private_ckd(HDNode *inout, uint32_t i)
}
write_be(data + 33, i);
SHA256_Raw(inout->public_key, 33, fingerprint);
sha256_Raw(inout->public_key, 33, fingerprint);
ripemd160(fingerprint, 32, fingerprint);
inout->fingerprint = (fingerprint[0] << 24) + (fingerprint[1] << 16) + (fingerprint[2] << 8) + fingerprint[3];
@ -111,7 +111,7 @@ int hdnode_public_ckd(HDNode *inout, uint32_t i)
}
write_be(data + 33, i);
SHA256_Raw(inout->public_key, 33, fingerprint);
sha256_Raw(inout->public_key, 33, fingerprint);
ripemd160(fingerprint, 32, fingerprint);
inout->fingerprint = (fingerprint[0] << 24) + (fingerprint[1] << 16) + (fingerprint[2] << 8) + fingerprint[3];

View File

@ -33,7 +33,7 @@ const char *mnemonic_from_data(const uint8_t *data, int len)
return 0;
}
SHA256_Raw((const uint8_t *)data, len, hash);
sha256_Raw((const uint8_t *)data, len, hash);
for (i = 0; i < len; i++) {
for (j = 0; j < 8; j++) {

24
ecdsa.c
View File

@ -227,7 +227,7 @@ int generate_k_rfc6979(bignum256 *secret, const uint8_t *priv_key, const uint8_t
int ecdsa_sign(const uint8_t *priv_key, const uint8_t *msg, uint32_t msg_len, uint8_t *sig)
{
uint8_t hash[32];
SHA256_Raw(msg, msg_len, hash);
sha256_Raw(msg, msg_len, hash);
return ecdsa_sign_digest(priv_key, hash, sig);
}
@ -236,8 +236,8 @@ int ecdsa_sign(const uint8_t *priv_key, const uint8_t *msg, uint32_t msg_len, ui
int ecdsa_sign_double(const uint8_t *priv_key, const uint8_t *msg, uint32_t msg_len, uint8_t *sig)
{
uint8_t hash[32];
SHA256_Raw(msg, msg_len, hash);
SHA256_Raw(hash, 32, hash);
sha256_Raw(msg, msg_len, hash);
sha256_Raw(hash, 32, hash);
return ecdsa_sign_digest(priv_key, hash, sig);
}
@ -343,15 +343,15 @@ void ecdsa_get_address(const uint8_t *pub_key, uint8_t version, char *addr)
int i, l;
if (pub_key[0] == 0x04) {
SHA256_Raw(pub_key, 65, a);
sha256_Raw(pub_key, 65, a);
} else {
SHA256_Raw(pub_key, 33, a);
sha256_Raw(pub_key, 33, a);
}
b[0] = version;
ripemd160(a, 32, b + 1);
SHA256_Raw(b, 21, a);
SHA256_Raw(a, 32, a);
sha256_Raw(b, 21, a);
sha256_Raw(a, 32, a);
memcpy(a + 28, a, 4); // checksum
memset(a, 0, 7); // zeroes
@ -405,8 +405,8 @@ int ecdsa_address_decode(const char *addr, uint8_t *out)
}
bn_write_be(&num, buf);
// compute address hash
SHA256_Raw(buf + 7, 21, check);
SHA256_Raw(check, 32, check);
sha256_Raw(buf + 7, 21, check);
sha256_Raw(check, 32, check);
// check if valid
if (memcmp(buf + 7 + 21, check, 4) != 0) {
return 0;
@ -453,15 +453,15 @@ int ecdsa_read_pubkey(const uint8_t *pub_key, curve_point *pub)
int ecdsa_verify(const uint8_t *pub_key, const uint8_t *sig, const uint8_t *msg, uint32_t msg_len)
{
uint8_t hash[32];
SHA256_Raw(msg, msg_len, hash);
sha256_Raw(msg, msg_len, hash);
return ecdsa_verify_digest(pub_key, sig, hash);
}
int ecdsa_verify_double(const uint8_t *pub_key, const uint8_t *sig, const uint8_t *msg, uint32_t msg_len)
{
uint8_t hash[32];
SHA256_Raw(msg, msg_len, hash);
SHA256_Raw(hash, 32, hash);
sha256_Raw(msg, msg_len, hash);
sha256_Raw(hash, 32, hash);
return ecdsa_verify_digest(pub_key, sig, hash);
}

36
hmac.c
View File

@ -11,7 +11,7 @@ void hmac_sha256(const uint8_t *key, const uint32_t keylen, const uint8_t *msg,
memset(buf, 0, SHA256_BLOCK_LENGTH);
if (keylen > SHA256_BLOCK_LENGTH) {
SHA256_Raw(key, keylen, buf);
sha256_Raw(key, keylen, buf);
} else {
memcpy(buf, key, keylen);
}
@ -21,15 +21,15 @@ void hmac_sha256(const uint8_t *key, const uint32_t keylen, const uint8_t *msg,
i_key_pad[i] = buf[i] ^ 0x36;
}
SHA256_Init(&ctx);
SHA256_Update(&ctx, i_key_pad, SHA256_BLOCK_LENGTH);
SHA256_Update(&ctx, msg, msglen);
SHA256_Final(buf, &ctx);
sha256_Init(&ctx);
sha256_Update(&ctx, i_key_pad, SHA256_BLOCK_LENGTH);
sha256_Update(&ctx, msg, msglen);
sha256_Final(buf, &ctx);
SHA256_Init(&ctx);
SHA256_Update(&ctx, o_key_pad, SHA256_BLOCK_LENGTH);
SHA256_Update(&ctx, buf, SHA256_DIGEST_LENGTH);
SHA256_Final(hmac, &ctx);
sha256_Init(&ctx);
sha256_Update(&ctx, o_key_pad, SHA256_BLOCK_LENGTH);
sha256_Update(&ctx, buf, SHA256_DIGEST_LENGTH);
sha256_Final(hmac, &ctx);
}
void hmac_sha512(const uint8_t *key, const uint32_t keylen, const uint8_t *msg, const uint32_t msglen, uint8_t *hmac)
@ -40,7 +40,7 @@ void hmac_sha512(const uint8_t *key, const uint32_t keylen, const uint8_t *msg,
memset(buf, 0, SHA512_BLOCK_LENGTH);
if (keylen > SHA512_BLOCK_LENGTH) {
SHA512_Raw(key, keylen, buf);
sha512_Raw(key, keylen, buf);
} else {
memcpy(buf, key, keylen);
}
@ -50,13 +50,13 @@ void hmac_sha512(const uint8_t *key, const uint32_t keylen, const uint8_t *msg,
i_key_pad[i] = buf[i] ^ 0x36;
}
SHA512_Init(&ctx);
SHA512_Update(&ctx, i_key_pad, SHA512_BLOCK_LENGTH);
SHA512_Update(&ctx, msg, msglen);
SHA512_Final(buf, &ctx);
sha512_Init(&ctx);
sha512_Update(&ctx, i_key_pad, SHA512_BLOCK_LENGTH);
sha512_Update(&ctx, msg, msglen);
sha512_Final(buf, &ctx);
SHA512_Init(&ctx);
SHA512_Update(&ctx, o_key_pad, SHA512_BLOCK_LENGTH);
SHA512_Update(&ctx, buf, SHA512_DIGEST_LENGTH);
SHA512_Final(hmac, &ctx);
sha512_Init(&ctx);
sha512_Update(&ctx, o_key_pad, SHA512_BLOCK_LENGTH);
sha512_Update(&ctx, buf, SHA512_DIGEST_LENGTH);
sha512_Final(hmac, &ctx);
}

52
sha2.c
View File

@ -288,7 +288,7 @@ static const char *sha2_hex_digits = "0123456789abcdef";
/*** SHA-256: *********************************************************/
void SHA256_Init(SHA256_CTX* context) {
void sha256_Init(SHA256_CTX* context) {
if (context == (SHA256_CTX*)0) {
return;
}
@ -472,7 +472,7 @@ void SHA256_Transform(SHA256_CTX* context, const sha2_word32* data) {
#endif /* SHA2_UNROLL_TRANSFORM */
void SHA256_Update(SHA256_CTX* context, const sha2_byte *data, size_t len) {
void sha256_Update(SHA256_CTX* context, const sha2_byte *data, size_t len) {
unsigned int freespace, usedspace;
if (len == 0) {
@ -517,7 +517,7 @@ void SHA256_Update(SHA256_CTX* context, const sha2_byte *data, size_t len) {
usedspace = freespace = 0;
}
void SHA256_Final(sha2_byte digest[], SHA256_CTX* context) {
void sha256_Final(sha2_byte digest[], SHA256_CTX* context) {
sha2_word32 *d = (sha2_word32*)digest;
unsigned int usedspace;
@ -578,12 +578,12 @@ void SHA256_Final(sha2_byte digest[], SHA256_CTX* context) {
usedspace = 0;
}
char *SHA256_End(SHA256_CTX* context, char buffer[]) {
char *sha256_End(SHA256_CTX* context, char buffer[]) {
sha2_byte digest[SHA256_DIGEST_LENGTH], *d = digest;
int i;
if (buffer != (char*)0) {
SHA256_Final(digest, context);
sha256_Final(digest, context);
for (i = 0; i < SHA256_DIGEST_LENGTH; i++) {
*buffer++ = sha2_hex_digits[(*d & 0xf0) >> 4];
@ -598,24 +598,24 @@ char *SHA256_End(SHA256_CTX* context, char buffer[]) {
return buffer;
}
void SHA256_Raw(const sha2_byte* data, size_t len, uint8_t digest[SHA256_DIGEST_LENGTH]) {
void sha256_Raw(const sha2_byte* data, size_t len, uint8_t digest[SHA256_DIGEST_LENGTH]) {
SHA256_CTX context;
SHA256_Init(&context);
SHA256_Update(&context, data, len);
SHA256_Final(digest, &context);
sha256_Init(&context);
sha256_Update(&context, data, len);
sha256_Final(digest, &context);
}
char* SHA256_Data(const sha2_byte* data, size_t len, char digest[SHA256_DIGEST_STRING_LENGTH]) {
char* sha256_Data(const sha2_byte* data, size_t len, char digest[SHA256_DIGEST_STRING_LENGTH]) {
SHA256_CTX context;
SHA256_Init(&context);
SHA256_Update(&context, data, len);
return SHA256_End(&context, digest);
sha256_Init(&context);
sha256_Update(&context, data, len);
return sha256_End(&context, digest);
}
/*** SHA-512: *********************************************************/
void SHA512_Init(SHA512_CTX* context) {
void sha512_Init(SHA512_CTX* context) {
if (context == (SHA512_CTX*)0) {
return;
}
@ -793,7 +793,7 @@ void SHA512_Transform(SHA512_CTX* context, const sha2_word64* data) {
#endif /* SHA2_UNROLL_TRANSFORM */
void SHA512_Update(SHA512_CTX* context, const sha2_byte *data, size_t len) {
void sha512_Update(SHA512_CTX* context, const sha2_byte *data, size_t len) {
unsigned int freespace, usedspace;
if (len == 0) {
@ -882,7 +882,7 @@ void SHA512_Last(SHA512_CTX* context) {
SHA512_Transform(context, (sha2_word64*)context->buffer);
}
void SHA512_Final(sha2_byte digest[], SHA512_CTX* context) {
void sha512_Final(sha2_byte digest[], SHA512_CTX* context) {
sha2_word64 *d = (sha2_word64*)digest;
/* If no digest buffer is passed, we don't bother doing this: */
@ -908,12 +908,12 @@ void SHA512_Final(sha2_byte digest[], SHA512_CTX* context) {
MEMSET_BZERO(context, sizeof(SHA512_CTX));
}
char *SHA512_End(SHA512_CTX* context, char buffer[]) {
char *sha512_End(SHA512_CTX* context, char buffer[]) {
sha2_byte digest[SHA512_DIGEST_LENGTH], *d = digest;
int i;
if (buffer != (char*)0) {
SHA512_Final(digest, context);
sha512_Final(digest, context);
for (i = 0; i < SHA512_DIGEST_LENGTH; i++) {
*buffer++ = sha2_hex_digits[(*d & 0xf0) >> 4];
@ -928,17 +928,17 @@ char *SHA512_End(SHA512_CTX* context, char buffer[]) {
return buffer;
}
void SHA512_Raw(const sha2_byte* data, size_t len, uint8_t digest[SHA512_DIGEST_LENGTH]) {
void sha512_Raw(const sha2_byte* data, size_t len, uint8_t digest[SHA512_DIGEST_LENGTH]) {
SHA512_CTX context;
SHA512_Init(&context);
SHA512_Update(&context, data, len);
SHA512_Final(digest, &context);
sha512_Init(&context);
sha512_Update(&context, data, len);
sha512_Final(digest, &context);
}
char* SHA512_Data(const sha2_byte* data, size_t len, char digest[SHA512_DIGEST_STRING_LENGTH]) {
char* sha512_Data(const sha2_byte* data, size_t len, char digest[SHA512_DIGEST_STRING_LENGTH]) {
SHA512_CTX context;
SHA512_Init(&context);
SHA512_Update(&context, data, len);
return SHA512_End(&context, digest);
sha512_Init(&context);
sha512_Update(&context, data, len);
return sha512_End(&context, digest);
}

24
sha2.h
View File

@ -52,18 +52,18 @@ typedef struct _SHA512_CTX {
uint8_t buffer[SHA512_BLOCK_LENGTH];
} SHA512_CTX;
void SHA256_Init(SHA256_CTX *);
void SHA256_Update(SHA256_CTX*, const uint8_t*, size_t);
void SHA256_Final(uint8_t[SHA256_DIGEST_LENGTH], SHA256_CTX*);
char* SHA256_End(SHA256_CTX*, char[SHA256_DIGEST_STRING_LENGTH]);
void SHA256_Raw(const uint8_t*, size_t, uint8_t[SHA256_DIGEST_LENGTH]);
char* SHA256_Data(const uint8_t*, size_t, char[SHA256_DIGEST_STRING_LENGTH]);
void sha256_Init(SHA256_CTX *);
void sha256_Update(SHA256_CTX*, const uint8_t*, size_t);
void sha256_Final(uint8_t[SHA256_DIGEST_LENGTH], SHA256_CTX*);
char* sha256_End(SHA256_CTX*, char[SHA256_DIGEST_STRING_LENGTH]);
void sha256_Raw(const uint8_t*, size_t, uint8_t[SHA256_DIGEST_LENGTH]);
char* sha256_Data(const uint8_t*, size_t, char[SHA256_DIGEST_STRING_LENGTH]);
void SHA512_Init(SHA512_CTX*);
void SHA512_Update(SHA512_CTX*, const uint8_t*, size_t);
void SHA512_Final(uint8_t[SHA512_DIGEST_LENGTH], SHA512_CTX*);
char* SHA512_End(SHA512_CTX*, char[SHA512_DIGEST_STRING_LENGTH]);
void SHA512_Raw(const uint8_t*, size_t, uint8_t[SHA512_DIGEST_LENGTH]);
char* SHA512_Data(const uint8_t*, size_t, char[SHA512_DIGEST_STRING_LENGTH]);
void sha512_Init(SHA512_CTX*);
void sha512_Update(SHA512_CTX*, const uint8_t*, size_t);
void sha512_Final(uint8_t[SHA512_DIGEST_LENGTH], SHA512_CTX*);
char* sha512_End(SHA512_CTX*, char[SHA512_DIGEST_STRING_LENGTH]);
void sha512_Raw(const uint8_t*, size_t, uint8_t[SHA512_DIGEST_LENGTH]);
char* sha512_Data(const uint8_t*, size_t, char[SHA512_DIGEST_STRING_LENGTH]);
#endif

View File

@ -210,7 +210,7 @@ END_TEST
int generate_k_rfc6979(bignum256 *secret, const uint8_t *priv_key, const uint8_t *hash);
#define test_deterministic(KEY, MSG, K) do { \
SHA256_Raw((uint8_t *)MSG, strlen(MSG), buf); \
sha256_Raw((uint8_t *)MSG, strlen(MSG), buf); \
res = generate_k_rfc6979(&k, fromhex(KEY), buf); \
ck_assert_int_eq(res, 0); \
bn_write_be(&k, buf); \
@ -299,7 +299,7 @@ START_TEST(test_verify_speed)
END_TEST
#define test_aes(KEY, BLKLEN, IN, OUT) do { \
SHA256_Raw((uint8_t *)KEY, strlen(KEY), key); \
sha256_Raw((uint8_t *)KEY, strlen(KEY), key); \
aes_enc_key(key, 32, &ctx); \
memcpy(in, fromhex(IN), BLKLEN); \
aes_enc_blk(in, out, &ctx); \