diff --git a/ctaocrypt/src/md4.c b/ctaocrypt/src/md4.c index 0126428a7..15961a007 100644 --- a/ctaocrypt/src/md4.c +++ b/ctaocrypt/src/md4.c @@ -161,7 +161,7 @@ void Md4Update(Md4* md4, const byte* data, word32 len) if (md4->buffLen == MD4_BLOCK_SIZE) { #ifdef BIG_ENDIAN_ORDER - ByteReverseBytes(local, local, MD4_BLOCK_SIZE); + ByteReverseWords(md4->buffer, md4->buffer, MD4_BLOCK_SIZE); #endif Transform(md4); AddLength(md4, MD4_BLOCK_SIZE); @@ -185,7 +185,7 @@ void Md4Final(Md4* md4, byte* hash) md4->buffLen += MD4_BLOCK_SIZE - md4->buffLen; #ifdef BIG_ENDIAN_ORDER - ByteReverseBytes(local, local, MD4_BLOCK_SIZE); + ByteReverseWords(md4->buffer, md4->buffer, MD4_BLOCK_SIZE); #endif Transform(md4); md4->buffLen = 0; @@ -199,7 +199,7 @@ void Md4Final(Md4* md4, byte* hash) /* store lengths */ #ifdef BIG_ENDIAN_ORDER - ByteReverseBytes(local, local, MD4_BLOCK_SIZE); + ByteReverseWords(md4->buffer, md4->buffer, MD4_BLOCK_SIZE); #endif /* ! length ordering dependent on digest endian type ! */ XMEMCPY(&local[MD4_PAD_SIZE], &md4->loLen, sizeof(word32)); diff --git a/ctaocrypt/src/md5.c b/ctaocrypt/src/md5.c index 7d2fe1429..96bcc359d 100644 --- a/ctaocrypt/src/md5.c +++ b/ctaocrypt/src/md5.c @@ -300,7 +300,7 @@ void Md5Update(Md5* md5, const byte* data, word32 len) if (md5->buffLen == MD5_BLOCK_SIZE) { #if defined(BIG_ENDIAN_ORDER) && !defined(FREESCALE_MMCAU) - ByteReverseBytes(local, local, MD5_BLOCK_SIZE); + ByteReverseWords(md5->buffer, md5->buffer, MD5_BLOCK_SIZE); #endif XTRANSFORM(md5, local); AddLength(md5, MD5_BLOCK_SIZE); @@ -324,7 +324,7 @@ void Md5Final(Md5* md5, byte* hash) md5->buffLen += MD5_BLOCK_SIZE - md5->buffLen; #if defined(BIG_ENDIAN_ORDER) && !defined(FREESCALE_MMCAU) - ByteReverseBytes(local, local, MD5_BLOCK_SIZE); + ByteReverseWords(md5->buffer, md5->buffer, MD5_BLOCK_SIZE); #endif XTRANSFORM(md5, local); md5->buffLen = 0; @@ -338,7 +338,7 @@ void Md5Final(Md5* md5, byte* hash) /* store lengths */ #if defined(BIG_ENDIAN_ORDER) && !defined(FREESCALE_MMCAU) - ByteReverseBytes(local, local, MD5_BLOCK_SIZE); + ByteReverseWords(md5->buffer, md5->buffer, MD5_BLOCK_SIZE); #endif /* ! length ordering dependent on digest endian type ! */ XMEMCPY(&local[MD5_PAD_SIZE], &md5->loLen, sizeof(word32)); diff --git a/ctaocrypt/src/misc.c b/ctaocrypt/src/misc.c index 453608957..971af0aa5 100644 --- a/ctaocrypt/src/misc.c +++ b/ctaocrypt/src/misc.c @@ -146,15 +146,6 @@ STATIC INLINE void ByteReverseWords64(word64* out, const word64* in, #endif /* WORD64_AVAILABLE */ -STATIC INLINE void ByteReverseBytes(byte* out, const byte* in, word32 byteCount) -{ - word32* op = (word32*)out; - const word32* ip = (const word32*)in; - - ByteReverseWords(op, ip, byteCount); -} - - STATIC INLINE void XorWords(word* r, const word* a, word32 n) { word32 i; @@ -163,13 +154,16 @@ STATIC INLINE void XorWords(word* r, const word* a, word32 n) } -STATIC INLINE void xorbuf(byte* buf, const byte* mask, word32 count) +STATIC INLINE void xorbuf(void* buf, const void* mask, word32 count) { if (((word)buf | (word)mask | count) % CYASSL_WORD_SIZE == 0) XorWords( (word*)buf, (const word*)mask, count / CYASSL_WORD_SIZE); else { word32 i; - for (i = 0; i < count; i++) buf[i] ^= mask[i]; + byte* b = (byte*)buf; + const byte* m = (const byte*)mask; + + for (i = 0; i < count; i++) b[i] ^= m[i]; } } #undef STATIC diff --git a/ctaocrypt/src/ripemd.c b/ctaocrypt/src/ripemd.c index f32351d5c..f885a6f30 100644 --- a/ctaocrypt/src/ripemd.c +++ b/ctaocrypt/src/ripemd.c @@ -295,7 +295,8 @@ void RipeMdUpdate(RipeMd* ripemd, const byte* data, word32 len) if (ripemd->buffLen == RIPEMD_BLOCK_SIZE) { #ifdef BIG_ENDIAN_ORDER - ByteReverseBytes(local, local, RIPEMD_BLOCK_SIZE); + ByteReverseWords(ripemd->buffer, ripemd->buffer, + RIPEMD_BLOCK_SIZE); #endif Transform(ripemd); AddLength(ripemd, RIPEMD_BLOCK_SIZE); @@ -319,7 +320,7 @@ void RipeMdFinal(RipeMd* ripemd, byte* hash) ripemd->buffLen += RIPEMD_BLOCK_SIZE - ripemd->buffLen; #ifdef BIG_ENDIAN_ORDER - ByteReverseBytes(local, local, RIPEMD_BLOCK_SIZE); + ByteReverseWords(ripemd->buffer, ripemd->buffer, RIPEMD_BLOCK_SIZE); #endif Transform(ripemd); ripemd->buffLen = 0; @@ -333,7 +334,7 @@ void RipeMdFinal(RipeMd* ripemd, byte* hash) /* store lengths */ #ifdef BIG_ENDIAN_ORDER - ByteReverseBytes(local, local, RIPEMD_BLOCK_SIZE); + ByteReverseWords(ripemd->buffer, ripemd->buffer, RIPEMD_BLOCK_SIZE); #endif /* ! length ordering dependent on digest endian type ! */ XMEMCPY(&local[RIPEMD_PAD_SIZE], &ripemd->loLen, sizeof(word32)); diff --git a/ctaocrypt/src/sha.c b/ctaocrypt/src/sha.c index 30b669341..93683ee95 100644 --- a/ctaocrypt/src/sha.c +++ b/ctaocrypt/src/sha.c @@ -311,7 +311,7 @@ void ShaUpdate(Sha* sha, const byte* data, word32 len) if (sha->buffLen == SHA_BLOCK_SIZE) { #if defined(LITTLE_ENDIAN_ORDER) && !defined(FREESCALE_MMCAU) - ByteReverseBytes(local, local, SHA_BLOCK_SIZE); + ByteReverseWords(sha->buffer, sha->buffer, SHA_BLOCK_SIZE); #endif XTRANSFORM(sha, local); AddLength(sha, SHA_BLOCK_SIZE); @@ -335,7 +335,7 @@ void ShaFinal(Sha* sha, byte* hash) sha->buffLen += SHA_BLOCK_SIZE - sha->buffLen; #if defined(LITTLE_ENDIAN_ORDER) && !defined(FREESCALE_MMCAU) - ByteReverseBytes(local, local, SHA_BLOCK_SIZE); + ByteReverseWords(sha->buffer, sha->buffer, SHA_BLOCK_SIZE); #endif XTRANSFORM(sha, local); sha->buffLen = 0; @@ -349,7 +349,7 @@ void ShaFinal(Sha* sha, byte* hash) /* store lengths */ #if defined(LITTLE_ENDIAN_ORDER) && !defined(FREESCALE_MMCAU) - ByteReverseBytes(local, local, SHA_BLOCK_SIZE); + ByteReverseWords(sha->buffer, sha->buffer, SHA_BLOCK_SIZE); #endif /* ! length ordering dependent on digest endian type ! */ XMEMCPY(&local[SHA_PAD_SIZE], &sha->hiLen, sizeof(word32)); @@ -357,8 +357,9 @@ void ShaFinal(Sha* sha, byte* hash) #ifdef FREESCALE_MMCAU /* Kinetis requires only these bytes reversed */ - ByteReverseBytes(&local[SHA_PAD_SIZE], &local[SHA_PAD_SIZE], - 2 * sizeof(word32)); + ByteReverseWords(&sha->buffer[SHA_PAD_SIZE/sizeof(word32)], + &sha->buffer[SHA_PAD_SIZE/sizeof(word32)], + 2 * sizeof(word32)); #endif XTRANSFORM(sha, local); diff --git a/ctaocrypt/src/sha256.c b/ctaocrypt/src/sha256.c index 97f64a3ca..769edf9e2 100644 --- a/ctaocrypt/src/sha256.c +++ b/ctaocrypt/src/sha256.c @@ -167,7 +167,8 @@ void Sha256Update(Sha256* sha256, const byte* data, word32 len) if (sha256->buffLen == SHA256_BLOCK_SIZE) { #if defined(LITTLE_ENDIAN_ORDER) && !defined(FREESCALE_MMCAU) - ByteReverseBytes(local, local, SHA256_BLOCK_SIZE); + ByteReverseWords(sha256->buffer, sha256->buffer, + SHA256_BLOCK_SIZE); #endif XTRANSFORM(sha256, local); AddLength(sha256, SHA256_BLOCK_SIZE); @@ -191,7 +192,7 @@ void Sha256Final(Sha256* sha256, byte* hash) sha256->buffLen += SHA256_BLOCK_SIZE - sha256->buffLen; #if defined(LITTLE_ENDIAN_ORDER) && !defined(FREESCALE_MMCAU) - ByteReverseBytes(local, local, SHA256_BLOCK_SIZE); + ByteReverseWords(sha256->buffer, sha256->buffer, SHA256_BLOCK_SIZE); #endif XTRANSFORM(sha256, local); sha256->buffLen = 0; @@ -205,7 +206,7 @@ void Sha256Final(Sha256* sha256, byte* hash) /* store lengths */ #if defined(LITTLE_ENDIAN_ORDER) && !defined(FREESCALE_MMCAU) - ByteReverseBytes(local, local, SHA256_BLOCK_SIZE); + ByteReverseWords(sha256->buffer, sha256->buffer, SHA256_BLOCK_SIZE); #endif /* ! length ordering dependent on digest endian type ! */ XMEMCPY(&local[SHA256_PAD_SIZE], &sha256->hiLen, sizeof(word32)); @@ -214,8 +215,9 @@ void Sha256Final(Sha256* sha256, byte* hash) #ifdef FREESCALE_MMCAU /* Kinetis requires only these bytes reversed */ - ByteReverseBytes(&local[SHA256_PAD_SIZE], &local[SHA256_PAD_SIZE], - 2 * sizeof(word32)); + ByteReverseWords(&sha256->buffer[SHA256_PAD_SIZE/sizeof(word32)], + &sha256->buffer[SHA256_PAD_SIZE/sizeof(word32)], + 2 * sizeof(word32)); #endif XTRANSFORM(sha256, local); diff --git a/cyassl/ctaocrypt/misc.h b/cyassl/ctaocrypt/misc.h index 49c9fa179..1740e1ab7 100644 --- a/cyassl/ctaocrypt/misc.h +++ b/cyassl/ctaocrypt/misc.h @@ -42,13 +42,11 @@ CYASSL_LOCAL word32 ByteReverseWord32(word32); CYASSL_LOCAL void ByteReverseWords(word32*, const word32*, word32); -CYASSL_LOCAL -void ByteReverseBytes(byte*, const byte*, word32); CYASSL_LOCAL void XorWords(word*, const word*, word32); CYASSL_LOCAL -void xorbuf(byte*, const byte*, word32); +void xorbuf(void*, const void*, word32); #ifdef WORD64_AVAILABLE CYASSL_LOCAL diff --git a/cyassl/test.h b/cyassl/test.h index c5e2799d0..91ef89692 100644 --- a/cyassl/test.h +++ b/cyassl/test.h @@ -1146,7 +1146,8 @@ static INLINE int CurrentDir(const char* str) if (ptr == NULL) return; - mt = (memoryTrack*)((byte*)ptr - sizeof(memoryTrack)); + mt = (memoryTrack*)ptr; + --mt; /* same as minus sizeof(memoryTrack), removes header */ #ifdef DO_MEM_STATS ourMemStats.currentBytes -= mt->u.hint.thisSize; @@ -1162,7 +1163,8 @@ static INLINE int CurrentDir(const char* str) if (ptr) { /* if realloc is bigger, don't overread old ptr */ - memoryTrack* mt = (memoryTrack*)((byte*)ptr - sizeof(memoryTrack)); + memoryTrack* mt = (memoryTrack*)ptr; + --mt; /* same as minus sizeof(memoryTrack), removes header */ if (mt->u.hint.thisSize < sz) sz = mt->u.hint.thisSize;