mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-02-21 12:02:19 +00:00
feat(crypto): Implement sha384_Raw().
This commit is contained in:
parent
5898b16cd2
commit
91ef616b56
@ -273,6 +273,18 @@ const sha2_word64 sha512_initial_hash_value[8] = {
|
|||||||
0x5be0cd19137e2179ULL
|
0x5be0cd19137e2179ULL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Initial hash value H for SHA-384 */
|
||||||
|
const sha2_word64 sha384_initial_hash_value[8] = {
|
||||||
|
0xcbbb9d5dc1059ed8ULL,
|
||||||
|
0x629a292a367cd507ULL,
|
||||||
|
0x9159015a3070dd17ULL,
|
||||||
|
0x152fecd8f70e5939ULL,
|
||||||
|
0x67332667ffc00b31ULL,
|
||||||
|
0x8eb44a8768581511ULL,
|
||||||
|
0xdb0c2e0d64f98fa7ULL,
|
||||||
|
0x47b5481dbefa4fa4ULL
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Constant used by SHA256/384/512_End() functions for converting the
|
* Constant used by SHA256/384/512_End() functions for converting the
|
||||||
* digest to a readable hexadecimal character string:
|
* digest to a readable hexadecimal character string:
|
||||||
@ -984,7 +996,7 @@ char* sha256_Data(const sha2_byte* data, size_t len, char digest[SHA256_DIGEST_S
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*** SHA-512: *********************************************************/
|
/*** SHA-512 and SHA-384: *********************************************/
|
||||||
void sha512_Init(SHA512_CTX* context) {
|
void sha512_Init(SHA512_CTX* context) {
|
||||||
if (context == (SHA512_CTX*)0) {
|
if (context == (SHA512_CTX*)0) {
|
||||||
return;
|
return;
|
||||||
@ -994,6 +1006,15 @@ void sha512_Init(SHA512_CTX* context) {
|
|||||||
context->bitcount[0] = context->bitcount[1] = 0;
|
context->bitcount[0] = context->bitcount[1] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void sha384_Init(SHA512_CTX* context) {
|
||||||
|
if (context == (SHA512_CTX*)0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
MEMCPY_BCOPY(context->state, sha384_initial_hash_value, SHA512_DIGEST_LENGTH);
|
||||||
|
memzero(context->buffer, SHA512_BLOCK_LENGTH);
|
||||||
|
context->bitcount[0] = context->bitcount[1] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef SHA2_UNROLL_TRANSFORM
|
#ifdef SHA2_UNROLL_TRANSFORM
|
||||||
|
|
||||||
/* Unrolled SHA-512 round macros: */
|
/* Unrolled SHA-512 round macros: */
|
||||||
@ -1284,6 +1305,16 @@ void sha512_Raw(const sha2_byte* data, size_t len, uint8_t digest[SHA512_DIGEST_
|
|||||||
sha512_Final(&context, digest);
|
sha512_Final(&context, digest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sha384_Raw(const sha2_byte* data, size_t len, uint8_t digest[SHA384_DIGEST_LENGTH]) {
|
||||||
|
uint8_t full_digest[SHA512_DIGEST_LENGTH] = {0};
|
||||||
|
SHA512_CTX context = {0};
|
||||||
|
sha384_Init(&context);
|
||||||
|
sha512_Update(&context, data, len);
|
||||||
|
sha512_Final(&context, full_digest);
|
||||||
|
memcpy(digest, full_digest, SHA384_DIGEST_LENGTH);
|
||||||
|
memzero(full_digest, sizeof(full_digest));
|
||||||
|
}
|
||||||
|
|
||||||
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 = {0};
|
SHA512_CTX context = {0};
|
||||||
|
|
||||||
|
@ -41,6 +41,7 @@
|
|||||||
#define SHA256_BLOCK_LENGTH 64
|
#define SHA256_BLOCK_LENGTH 64
|
||||||
#define SHA256_DIGEST_LENGTH 32
|
#define SHA256_DIGEST_LENGTH 32
|
||||||
#define SHA256_DIGEST_STRING_LENGTH (SHA256_DIGEST_LENGTH * 2 + 1)
|
#define SHA256_DIGEST_STRING_LENGTH (SHA256_DIGEST_LENGTH * 2 + 1)
|
||||||
|
#define SHA384_DIGEST_LENGTH 48
|
||||||
#define SHA512_BLOCK_LENGTH 128
|
#define SHA512_BLOCK_LENGTH 128
|
||||||
#define SHA512_DIGEST_LENGTH 64
|
#define SHA512_DIGEST_LENGTH 64
|
||||||
#define SHA512_DIGEST_STRING_LENGTH (SHA512_DIGEST_LENGTH * 2 + 1)
|
#define SHA512_DIGEST_STRING_LENGTH (SHA512_DIGEST_LENGTH * 2 + 1)
|
||||||
@ -81,6 +82,8 @@ char* sha256_End(SHA256_CTX*, char[SHA256_DIGEST_STRING_LENGTH]);
|
|||||||
void sha256_Raw(const uint8_t*, size_t, uint8_t[SHA256_DIGEST_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]);
|
char* sha256_Data(const uint8_t*, size_t, char[SHA256_DIGEST_STRING_LENGTH]);
|
||||||
|
|
||||||
|
void sha384_Raw(const uint8_t*, size_t, uint8_t[SHA384_DIGEST_LENGTH]);
|
||||||
|
|
||||||
void sha512_Transform(const uint64_t* state_in, const uint64_t* data, uint64_t* state_out);
|
void sha512_Transform(const uint64_t* state_in, const uint64_t* data, uint64_t* state_out);
|
||||||
void sha512_Init(SHA512_CTX*);
|
void sha512_Init(SHA512_CTX*);
|
||||||
void sha512_Update(SHA512_CTX*, const uint8_t*, size_t);
|
void sha512_Update(SHA512_CTX*, const uint8_t*, size_t);
|
||||||
|
Loading…
Reference in New Issue
Block a user