1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-22 22:38:08 +00:00

fix alignment in sha functions

This commit is contained in:
Pavol Rusnak 2016-05-12 16:16:01 +02:00
parent 454bebc162
commit 9e5d03a1fc
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
3 changed files with 17 additions and 17 deletions

View File

@ -3,7 +3,7 @@ CC = gcc
OPTFLAGS = -O3 -g
CFLAGS += $(OPTFLAGS) \
-std=c99 \
-std=gnu99 \
-W \
-Wall \
-Wextra \

30
sha2.c
View File

@ -385,7 +385,7 @@ void sha256_Transform(SHA256_CTX* context, const sha2_word32* data) {
sha2_word32 T1, T2, *W256;
int j;
W256 = (sha2_word32*)context->buffer;
W256 = (sha2_word32*)(void*)context->buffer;
/* Initialize registers with the prev. intermediate value */
a = context->state[0];
@ -479,7 +479,7 @@ void sha256_Update(SHA256_CTX* context, const sha2_byte *data, size_t len) {
context->bitcount += freespace << 3;
len -= freespace;
data += freespace;
sha256_Transform(context, (sha2_word32*)context->buffer);
sha256_Transform(context, (sha2_word32*)(void*)context->buffer);
} else {
/* The buffer is not yet full */
MEMCPY_BCOPY(&context->buffer[usedspace], data, len);
@ -491,7 +491,7 @@ void sha256_Update(SHA256_CTX* context, const sha2_byte *data, size_t len) {
}
while (len >= SHA256_BLOCK_LENGTH) {
/* Process as many complete blocks as we can */
sha256_Transform(context, (sha2_word32*)data);
sha256_Transform(context, (sha2_word32*)(void*)data);
context->bitcount += SHA256_BLOCK_LENGTH << 3;
len -= SHA256_BLOCK_LENGTH;
data += SHA256_BLOCK_LENGTH;
@ -506,7 +506,7 @@ void sha256_Update(SHA256_CTX* context, const sha2_byte *data, size_t len) {
}
void sha256_Final(SHA256_CTX* context, sha2_byte digest[]) {
sha2_word32 *d = (sha2_word32*)digest;
sha2_word32 *d = (sha2_word32*)(void*)digest;
unsigned int usedspace;
/* If no digest buffer is passed, we don't bother doing this: */
@ -528,7 +528,7 @@ void sha256_Final(SHA256_CTX* context, sha2_byte digest[]) {
MEMSET_BZERO(&context->buffer[usedspace], SHA256_BLOCK_LENGTH - usedspace);
}
/* Do second-to-last transform: */
sha256_Transform(context, (sha2_word32*)context->buffer);
sha256_Transform(context, (sha2_word32*)(void*)context->buffer);
/* And set-up for the last transform: */
MEMSET_BZERO(context->buffer, SHA256_SHORT_BLOCK_LENGTH);
@ -541,11 +541,11 @@ void sha256_Final(SHA256_CTX* context, sha2_byte digest[]) {
*context->buffer = 0x80;
}
/* Set the bit count: */
sha2_word64 *t = (sha2_word64 *)&context->buffer[SHA256_SHORT_BLOCK_LENGTH];
sha2_word64 *t = (sha2_word64 *)(void*)&context->buffer[SHA256_SHORT_BLOCK_LENGTH];
*t = context->bitcount;
/* Final transform: */
sha256_Transform(context, (sha2_word32*)context->buffer);
sha256_Transform(context, (sha2_word32*)(void*)context->buffer);
#if BYTE_ORDER == LITTLE_ENDIAN
{
@ -705,7 +705,7 @@ void sha512_Transform(SHA512_CTX* context, const sha2_word64* data) {
void sha512_Transform(SHA512_CTX* context, const sha2_word64* data) {
sha2_word64 a, b, c, d, e, f, g, h, s0, s1;
sha2_word64 T1, T2, *W512 = (sha2_word64*)context->buffer;
sha2_word64 T1, T2, *W512 = (sha2_word64*)(void*)context->buffer;
int j;
/* Initialize registers with the prev. intermediate value */
@ -800,7 +800,7 @@ void sha512_Update(SHA512_CTX* context, const sha2_byte *data, size_t len) {
ADDINC128(context->bitcount, freespace << 3);
len -= freespace;
data += freespace;
sha512_Transform(context, (sha2_word64*)context->buffer);
sha512_Transform(context, (sha2_word64*)(void*)context->buffer);
} else {
/* The buffer is not yet full */
MEMCPY_BCOPY(&context->buffer[usedspace], data, len);
@ -812,7 +812,7 @@ void sha512_Update(SHA512_CTX* context, const sha2_byte *data, size_t len) {
}
while (len >= SHA512_BLOCK_LENGTH) {
/* Process as many complete blocks as we can */
sha512_Transform(context, (sha2_word64*)data);
sha512_Transform(context, (sha2_word64*)(void*)data);
ADDINC128(context->bitcount, SHA512_BLOCK_LENGTH << 3);
len -= SHA512_BLOCK_LENGTH;
data += SHA512_BLOCK_LENGTH;
@ -847,7 +847,7 @@ void sha512_Last(SHA512_CTX* context) {
MEMSET_BZERO(&context->buffer[usedspace], SHA512_BLOCK_LENGTH - usedspace);
}
/* Do second-to-last transform: */
sha512_Transform(context, (sha2_word64*)context->buffer);
sha512_Transform(context, (sha2_word64*)(void*)context->buffer);
/* And set-up for the last transform: */
MEMSET_BZERO(context->buffer, SHA512_BLOCK_LENGTH - 2);
@ -861,17 +861,17 @@ void sha512_Last(SHA512_CTX* context) {
}
/* Store the length of input data (in bits): */
sha2_word64 *t;
t = (sha2_word64 *)&context->buffer[SHA512_SHORT_BLOCK_LENGTH];
t = (sha2_word64 *)(void*)&context->buffer[SHA512_SHORT_BLOCK_LENGTH];
*t = context->bitcount[1];
t = (sha2_word64 *)&context->buffer[SHA512_SHORT_BLOCK_LENGTH+8];
t = (sha2_word64 *)(void*)&context->buffer[SHA512_SHORT_BLOCK_LENGTH+8];
*t = context->bitcount[0];
/* Final transform: */
sha512_Transform(context, (sha2_word64*)context->buffer);
sha512_Transform(context, (sha2_word64*)(void*)context->buffer);
}
void sha512_Final(SHA512_CTX* context, sha2_byte digest[]) {
sha2_word64 *d = (sha2_word64*)digest;
sha2_word64 *d = (sha2_word64*)(void*)digest;
/* If no digest buffer is passed, we don't bother doing this: */
if (digest != (sha2_byte*)0) {

2
sha3.c
View File

@ -289,7 +289,7 @@ void sha3_Update(SHA3_CTX *ctx, const unsigned char *msg, size_t size)
if (IS_ALIGNED_64(msg)) {
/* the most common case is processing of an already aligned message
without copying it */
aligned_message_block = (uint64_t*)msg;
aligned_message_block = (uint64_t*)(void*)msg;
} else {
memcpy(ctx->message, msg, block_size);
aligned_message_block = ctx->message;