From 4320bc47617a66d4219e66e2420311dbfb6c3cb0 Mon Sep 17 00:00:00 2001 From: David Benjamin Date: Mon, 29 Mar 2021 14:26:07 -0400 Subject: [PATCH] Pull HASH_TRANSFORM out of md32_common.h. The macro isn't doing any work here. Change-Id: Id97dfa4b027407c5e4b3e7eb1586c3c2a2d977d8 Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/47806 Commit-Queue: David Benjamin Reviewed-by: Adam Langley --- crypto/fipsmodule/digest/md32_common.h | 11 ----------- crypto/fipsmodule/md4/md4.c | 6 ++++-- crypto/fipsmodule/md5/md5.c | 5 +++-- crypto/fipsmodule/sha/sha1.c | 16 +++++++++------- crypto/fipsmodule/sha/sha256.c | 15 +++++++++------ decrepit/ripemd/ripemd.c | 6 +++++- 6 files changed, 30 insertions(+), 29 deletions(-) diff --git a/crypto/fipsmodule/digest/md32_common.h b/crypto/fipsmodule/digest/md32_common.h index a0634d1ef..8a1410849 100644 --- a/crypto/fipsmodule/digest/md32_common.h +++ b/crypto/fipsmodule/digest/md32_common.h @@ -86,9 +86,6 @@ extern "C" { // |HASH_UPDATE| must be defined as the name of the "Update" function to // generate. // -// |HASH_TRANSFORM| must be defined as the the name of the "Transform" -// function to generate. -// // |HASH_FINAL| must be defined as the name of "Final" function to generate. // // |HASH_BLOCK_DATA_ORDER| must be defined as the name of the "Block" function. @@ -121,9 +118,6 @@ extern "C" { #ifndef HASH_UPDATE #error "HASH_UPDATE must be defined!" #endif -#ifndef HASH_TRANSFORM -#error "HASH_TRANSFORM must be defined!" -#endif #ifndef HASH_FINAL #error "HASH_FINAL must be defined!" #endif @@ -185,11 +179,6 @@ int HASH_UPDATE(HASH_CTX *c, const void *data_, size_t len) { } -void HASH_TRANSFORM(HASH_CTX *c, const uint8_t data[HASH_CBLOCK]) { - HASH_BLOCK_DATA_ORDER(c->h, data, 1); -} - - int HASH_FINAL(uint8_t out[HASH_DIGEST_LENGTH], HASH_CTX *c) { // |c->data| always has room for at least one byte. A full block would have // been consumed. diff --git a/crypto/fipsmodule/md4/md4.c b/crypto/fipsmodule/md4/md4.c index 0551664fc..9d229bff8 100644 --- a/crypto/fipsmodule/md4/md4.c +++ b/crypto/fipsmodule/md4/md4.c @@ -84,13 +84,16 @@ int MD4_Init(MD4_CTX *md4) { void md4_block_data_order(uint32_t *state, const uint8_t *data, size_t num); +void MD4_Transform(MD4_CTX *c, const uint8_t data[MD4_CBLOCK]) { + md4_block_data_order(c->h, data, 1); +} + #define DATA_ORDER_IS_LITTLE_ENDIAN #define HASH_CTX MD4_CTX #define HASH_CBLOCK 64 #define HASH_DIGEST_LENGTH 16 #define HASH_UPDATE MD4_Update -#define HASH_TRANSFORM MD4_Transform #define HASH_FINAL MD4_Final #define HASH_MAKE_STRING(c, s) \ do { \ @@ -240,7 +243,6 @@ void md4_block_data_order(uint32_t *state, const uint8_t *data, size_t num) { #undef HASH_CBLOCK #undef HASH_DIGEST_LENGTH #undef HASH_UPDATE -#undef HASH_TRANSFORM #undef HASH_FINAL #undef HASH_MAKE_STRING #undef HASH_BLOCK_DATA_ORDER diff --git a/crypto/fipsmodule/md5/md5.c b/crypto/fipsmodule/md5/md5.c index bd6bf6a56..e454a84e2 100644 --- a/crypto/fipsmodule/md5/md5.c +++ b/crypto/fipsmodule/md5/md5.c @@ -89,6 +89,9 @@ static void md5_block_data_order(uint32_t *state, const uint8_t *data, size_t num); #endif +void MD5_Transform(MD5_CTX *c, const uint8_t data[MD5_CBLOCK]) { + md5_block_data_order(c->h, data, 1); +} #define DATA_ORDER_IS_LITTLE_ENDIAN @@ -96,7 +99,6 @@ static void md5_block_data_order(uint32_t *state, const uint8_t *data, #define HASH_CBLOCK 64 #define HASH_DIGEST_LENGTH 16 #define HASH_UPDATE MD5_Update -#define HASH_TRANSFORM MD5_Transform #define HASH_FINAL MD5_Final #define HASH_MAKE_STRING(c, s) \ do { \ @@ -283,7 +285,6 @@ static void md5_block_data_order(uint32_t *state, const uint8_t *data, #undef HASH_CBLOCK #undef HASH_DIGEST_LENGTH #undef HASH_UPDATE -#undef HASH_TRANSFORM #undef HASH_FINAL #undef HASH_MAKE_STRING #undef HASH_BLOCK_DATA_ORDER diff --git a/crypto/fipsmodule/sha/sha1.c b/crypto/fipsmodule/sha/sha1.c index 2f50c67dd..7149d11cb 100644 --- a/crypto/fipsmodule/sha/sha1.c +++ b/crypto/fipsmodule/sha/sha1.c @@ -83,6 +83,15 @@ uint8_t *SHA1(const uint8_t *data, size_t len, uint8_t out[SHA_DIGEST_LENGTH]) { return out; } +#if !defined(SHA1_ASM) +static void sha1_block_data_order(uint32_t *state, const uint8_t *data, + size_t num); +#endif + +void SHA1_Transform(SHA_CTX *c, const uint8_t data[SHA_CBLOCK]) { + sha1_block_data_order(c->h, data, 1); +} + #define DATA_ORDER_IS_BIG_ENDIAN #define HASH_CTX SHA_CTX @@ -103,7 +112,6 @@ uint8_t *SHA1(const uint8_t *data, size_t len, uint8_t out[SHA_DIGEST_LENGTH]) { } while (0) #define HASH_UPDATE SHA1_Update -#define HASH_TRANSFORM SHA1_Transform #define HASH_FINAL SHA1_Final #define HASH_BLOCK_DATA_ORDER sha1_block_data_order #define ROTATE(a, n) (((a) << (n)) | ((a) >> (32 - (n)))) @@ -113,11 +121,6 @@ uint8_t *SHA1(const uint8_t *data, size_t len, uint8_t out[SHA_DIGEST_LENGTH]) { (ix) = (a) = ROTATE((a), 1); \ } while (0) -#if !defined(SHA1_ASM) -static void sha1_block_data_order(uint32_t *state, const uint8_t *data, - size_t num); -#endif - #include "../digest/md32_common.h" #define K_00_19 0x5a827999UL @@ -346,7 +349,6 @@ static void sha1_block_data_order(uint32_t *state, const uint8_t *data, #undef HASH_DIGEST_LENGTH #undef HASH_MAKE_STRING #undef HASH_UPDATE -#undef HASH_TRANSFORM #undef HASH_FINAL #undef HASH_BLOCK_DATA_ORDER #undef ROTATE diff --git a/crypto/fipsmodule/sha/sha256.c b/crypto/fipsmodule/sha/sha256.c index 390ee3a7c..ff961c85a 100644 --- a/crypto/fipsmodule/sha/sha256.c +++ b/crypto/fipsmodule/sha/sha256.c @@ -122,6 +122,15 @@ int SHA224_Final(uint8_t out[SHA224_DIGEST_LENGTH], SHA256_CTX *ctx) { return SHA256_Final(out, ctx); } +#ifndef SHA256_ASM +static void sha256_block_data_order(uint32_t *state, const uint8_t *in, + size_t num); +#endif + +void SHA256_Transform(SHA256_CTX *c, const uint8_t data[SHA256_CBLOCK]) { + sha256_block_data_order(c->h, data, 1); +} + #define DATA_ORDER_IS_BIG_ENDIAN #define HASH_CTX SHA256_CTX @@ -167,13 +176,8 @@ int SHA224_Final(uint8_t out[SHA224_DIGEST_LENGTH], SHA256_CTX *ctx) { #define HASH_UPDATE SHA256_Update -#define HASH_TRANSFORM SHA256_Transform #define HASH_FINAL SHA256_Final #define HASH_BLOCK_DATA_ORDER sha256_block_data_order -#ifndef SHA256_ASM -static void sha256_block_data_order(uint32_t *state, const uint8_t *in, - size_t num); -#endif #include "../digest/md32_common.h" @@ -324,7 +328,6 @@ void SHA256_TransformBlocks(uint32_t state[8], const uint8_t *data, #undef HASH_DIGEST_LENGTH #undef HASH_MAKE_STRING #undef HASH_UPDATE -#undef HASH_TRANSFORM #undef HASH_FINAL #undef HASH_BLOCK_DATA_ORDER #undef ROTATE diff --git a/decrepit/ripemd/ripemd.c b/decrepit/ripemd/ripemd.c index 50329c7c1..ac6bd83bb 100644 --- a/decrepit/ripemd/ripemd.c +++ b/decrepit/ripemd/ripemd.c @@ -80,6 +80,11 @@ int RIPEMD160_Init(RIPEMD160_CTX *ctx) { static void ripemd160_block_data_order(uint32_t h[5], const uint8_t *data, size_t num); +void RIPEMD160_Transform(RIPEMD160_CTX *c, + const uint8_t data[RIPEMD160_CBLOCK]) { + ripemd160_block_data_order(c->h, data, 1); +} + #define DATA_ORDER_IS_LITTLE_ENDIAN #define HASH_LONG uint32_t @@ -87,7 +92,6 @@ static void ripemd160_block_data_order(uint32_t h[5], const uint8_t *data, #define HASH_CBLOCK RIPEMD160_CBLOCK #define HASH_DIGEST_LENGTH RIPEMD160_DIGEST_LENGTH #define HASH_UPDATE RIPEMD160_Update -#define HASH_TRANSFORM RIPEMD160_Transform #define HASH_FINAL RIPEMD160_Final #define HASH_MAKE_STRING(c, s) \ do { \