diff options
author | Constanza Heath <[email protected]> | 2015-08-28 17:49:18 -0700 |
---|---|---|
committer | Constanza Heath <[email protected]> | 2015-08-28 17:49:18 -0700 |
commit | d89a484317b7835d2eacddaee806e6ec08e0d213 (patch) | |
tree | bc6dc4b85a2f401bb819584b8e01eeb79be6a64d /lib | |
parent | 4808968a4a4704db83130eae00c24fc48cf11686 (diff) |
Fix bug in conversion from macro to inline
Signed-off-by: Constanza Heath <[email protected]>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/sha256.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/lib/sha256.c b/lib/sha256.c index 4530750..2edc696 100644 --- a/lib/sha256.c +++ b/lib/sha256.c @@ -36,6 +36,7 @@ #include "sha256.h" #include "utils.h" +#include <stdio.h> static void compress (uint32_t *iv, const uint8_t *data); @@ -162,11 +163,14 @@ static inline uint32_t ROTR (uint32_t a, uint32_t n) { #define Ch(a,b,c) (((a) & (b)) ^ ((~(a)) & (c))) #define Maj(a,b,c) (((a) & (b)) ^ ((a) & (c)) ^ ((b) & (c))) -#define BigEndian(n,c) (n = (((uint32_t)(*((c)++))) << 24), \ - n |= ((uint32_t)(*((c)++)) << 16), \ - n |= ((uint32_t)(*((c)++)) << 8), \ - n |= ((uint32_t)(*((c)++))), \ - n) +static inline uint32_t BigEndian (uint32_t c) { + uint32_t n = 0; + n |= ((c & 0x000000FF) << 24); + n |= ((c & 0x0000FF00) << 8); + n |= ((c & 0x00FF0000) >> 8); + n |= ((c & 0xFF000000) >> 24); + return n; +} static void compress (uint32_t *iv, const uint8_t *data) { uint32_t a, b, c, d, e, f, g, h; @@ -180,7 +184,8 @@ static void compress (uint32_t *iv, const uint8_t *data) { e = iv[4]; f = iv[5]; g = iv[6]; h = iv[7]; for (i = 0; i < 16; ++i) { - BigEndian(n,data); + n = BigEndian(*(const uint32_t *)data); + data += sizeof(uint32_t); t1 = work_space[i] = n; t1 += h + Sigma1(e) + Ch(e,f,g) + k256[i]; t2 = Sigma0(a) + Maj(a,b,c); |