diff options
author | Brian Smith <brian@briansmith.org> | 2015-11-01 23:13:24 +0300 |
---|---|---|
committer | Adam Langley <agl@google.com> | 2015-11-03 05:04:38 +0300 |
commit | 00461cf201b66205653fd6159ae260f453738641 (patch) | |
tree | 656151ba243139bf71ee1cfa1712c7fb75ee4c60 /crypto/md5 | |
parent | ecc2591b6cbb376dfa0ea1dfce35f1f172ffd0d5 (diff) |
Improve crypto/digest/md32_common.h mechanism.
The documentation in md32_common.h is now (more) correct with respect
to the most important details of the layout of |HASH_CTX|. The
documentation explaining why sha512.c doesn't use md32_common.h is now
more accurate as well.
Before, the C implementations of HASH_BLOCK_DATA_ORDER took a pointer
to the |HASH_CTX| and the assembly language implementations tool a
pointer to the hash state |h| member of |HASH_CTX|. (This worked
because |h| is always the first member of |HASH_CTX|.) Now, the C
implementations take a pointer directly to |h| too.
The definitions of |MD4_CTX|, |MD5_CTX|, and |SHA1_CTX| were changed to
be consistent with |SHA256_CTX| and |SHA512_CTX| in storing the hash
state in an array. This will break source compatibility with any
external code that accesses the hash state directly, but will not
affect binary compatibility.
The second parameter of |HASH_BLOCK_DATA_ORDER| is now of type
|const uint8_t *|; previously it was |void *| and all implementations
had a |uint8_t *data| variable to access it as an array of bytes.
This change paves the way for future refactorings such as automatically
generating the |*_Init| functions and/or sharing one I-U-F
implementation across all digest algorithms.
Change-Id: I30513bb40b5f1d2c8932551d54073c35484b3f8b
Reviewed-on: https://boringssl-review.googlesource.com/6401
Reviewed-by: Adam Langley <agl@google.com>
Diffstat (limited to 'crypto/md5')
-rw-r--r-- | crypto/md5/md5.c | 38 |
1 files changed, 18 insertions, 20 deletions
diff --git a/crypto/md5/md5.c b/crypto/md5/md5.c index 6ad8d128..f27e62de 100644 --- a/crypto/md5/md5.c +++ b/crypto/md5/md5.c @@ -79,10 +79,10 @@ uint8_t *MD5(const uint8_t *data, size_t len, uint8_t *out) { int MD5_Init(MD5_CTX *md5) { memset(md5, 0, sizeof(MD5_CTX)); - md5->A = 0x67452301UL; - md5->B = 0xefcdab89UL; - md5->C = 0x98badcfeUL; - md5->D = 0x10325476UL; + md5->h[0] = 0x67452301UL; + md5->h[1] = 0xefcdab89UL; + md5->h[2] = 0x98badcfeUL; + md5->h[3] = 0x10325476UL; return 1; } @@ -93,11 +93,10 @@ int MD5_Init(MD5_CTX *md5) { #endif -void md5_block_data_order(MD5_CTX *md5, const void *p, size_t num); +void md5_block_data_order(uint32_t *state, const uint8_t *data, size_t num); #define DATA_ORDER_IS_LITTLE_ENDIAN -#define HASH_LONG uint32_t #define HASH_CTX MD5_CTX #define HASH_CBLOCK 64 #define HASH_UPDATE MD5_Update @@ -106,13 +105,13 @@ void md5_block_data_order(MD5_CTX *md5, const void *p, size_t num); #define HASH_MAKE_STRING(c, s) \ do { \ uint32_t ll; \ - ll = (c)->A; \ + ll = (c)->h[0]; \ (void) HOST_l2c(ll, (s)); \ - ll = (c)->B; \ + ll = (c)->h[1]; \ (void) HOST_l2c(ll, (s)); \ - ll = (c)->C; \ + ll = (c)->h[2]; \ (void) HOST_l2c(ll, (s)); \ - ll = (c)->D; \ + ll = (c)->h[3]; \ (void) HOST_l2c(ll, (s)); \ } while (0) #define HASH_BLOCK_DATA_ORDER md5_block_data_order @@ -152,17 +151,16 @@ void md5_block_data_order(MD5_CTX *md5, const void *p, size_t num); #ifdef X #undef X #endif -void md5_block_data_order(MD5_CTX *md5, const void *in_data, size_t num) { - const uint8_t *data = in_data; +void md5_block_data_order(uint32_t *state, const uint8_t *data, size_t num) { uint32_t A, B, C, D, l; uint32_t XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7, XX8, XX9, XX10, XX11, XX12, XX13, XX14, XX15; #define X(i) XX##i - A = md5->A; - B = md5->B; - C = md5->C; - D = md5->D; + A = state[0]; + B = state[1]; + C = state[2]; + D = state[3]; for (; num--;) { HOST_c2l(data, l); @@ -266,10 +264,10 @@ void md5_block_data_order(MD5_CTX *md5, const void *in_data, size_t num) { R3(C, D, A, B, X(2), 15, 0x2ad7d2bbL); R3(B, C, D, A, X(9), 21, 0xeb86d391L); - A = md5->A += A; - B = md5->B += B; - C = md5->C += C; - D = md5->D += D; + A = state[0] += A; + B = state[1] += B; + C = state[2] += C; + D = state[3] += D; } } #endif |