X-Git-Url: https://git.cryptolib.org/?p=avr-crypto-lib.git;a=blobdiff_plain;f=twister%2Ftwister-large.c;h=1cbc9f199ba2929c16c1a228c62853e6c58ea549;hp=1775488ef3c128e30bb932363af4bfe892e6400a;hb=4b5da1dc27a791b5c448274a3db09cd035b33493;hpb=b8d6b2bd3ddea45506f584c7d44fe5fff0557ed1 diff --git a/twister/twister-large.c b/twister/twister-large.c index 1775488..1cbc9f1 100644 --- a/twister/twister-large.c +++ b/twister/twister-large.c @@ -1,7 +1,7 @@ /* twister-large.c */ /* This file is part of the AVR-Crypto-Lib. - Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) + Copyright (C) 2006-2015 Daniel Otte (bg@nerilex.org) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -26,7 +26,7 @@ /*********************************************************************/ static -void checksum_update(twister_large_ctx_t* ctx, uint8_t col){ +void checksum_update(twister_large_ctx_t *ctx, uint8_t col){ uint8_t i, col2; uint8_t carry = 0; int sum = 0; @@ -46,7 +46,7 @@ void checksum_update(twister_large_ctx_t* ctx, uint8_t col){ /*********************************************************************/ -void twister_large_init(twister_large_ctx_t* ctx, uint16_t hashsize_b){ +void twister_large_init(twister_large_ctx_t *ctx, uint16_t hashsize_b){ memset(ctx->state.s, 0, 64); memset(ctx->checksum, 0, 64); ctx->state.counter=0xffffffffffffffffLL; @@ -57,7 +57,7 @@ void twister_large_init(twister_large_ctx_t* ctx, uint16_t hashsize_b){ /*********************************************************************/ -void twister_large_nextBlock(twister_large_ctx_t* ctx, const void* msg){ +void twister_large_nextBlock(twister_large_ctx_t *ctx, const void *msg){ uint8_t tmp[8][8]; /* 1st maxi round */ @@ -108,14 +108,18 @@ void twister_large_nextBlock(twister_large_ctx_t* ctx, const void* msg){ /*********************************************************************/ -void twister_inject_chksum(twister_large_ctx_t* ctx, uint8_t col){ - *((uint64_t*)(&ctx->state.s[7][0])) ^= *((uint64_t*)(&ctx->checksum[col][0])); +void twister_inject_chksum(twister_large_ctx_t *ctx, uint8_t col){ + uint8_t i=7; + do{ + ctx->state.s[7][i] ^= ctx->checksum[col][i]; + + }while(i--); twister_blank_round(&ctx->state); } /*********************************************************************/ -void twister_large_lastBlock(twister_large_ctx_t* ctx, const void* msg, uint16_t length_b){ +void twister_large_lastBlock(twister_large_ctx_t *ctx, const void *msg, uint16_t length_b){ uint8_t tmp[64]; while(length_b>=512){ twister_large_nextBlock(ctx, msg); @@ -151,38 +155,38 @@ void twister_large_lastBlock(twister_large_ctx_t* ctx, const void* msg, uint16_t /*********************************************************************/ -void twister_large_ctx2hash(void* dest, twister_large_ctx_t* ctx, uint16_t hashsize_b){ +void twister_large_ctx2hash(void *dest, twister_large_ctx_t *ctx, uint16_t hashsize_b){ twister_ctx2hash(dest, &(ctx->state), hashsize_b); } /*********************************************************************/ /*********************************************************************/ -void twister384_init(twister384_ctx_t* ctx){ +void twister384_init(twister384_ctx_t *ctx){ twister_large_init(ctx, 384); } /*********************************************************************/ -void twister384_nextBlock(twister384_ctx_t* ctx, const void* msg){ +void twister384_nextBlock(twister384_ctx_t *ctx, const void *msg){ twister_large_nextBlock(ctx, msg); } /*********************************************************************/ -void twister384_lastBlock(twister384_ctx_t* ctx, const void* msg, uint16_t length_b){ +void twister384_lastBlock(twister384_ctx_t *ctx, const void *msg, uint16_t length_b){ twister_large_lastBlock(ctx, msg, length_b); } /*********************************************************************/ -void twister384_ctx2hash(void* dest, twister384_ctx_t* ctx){ +void twister384_ctx2hash(void *dest, twister384_ctx_t *ctx){ twister_large_ctx2hash(dest, ctx, 384); } /*********************************************************************/ -void twister384(void* dest, const void* msg, uint32_t msg_length_b){ +void twister384(void *dest, const void *msg, uint32_t msg_length_b){ twister_large_ctx_t ctx; twister_large_init(&ctx, 384); while(msg_length_b >=512){ @@ -198,31 +202,31 @@ void twister384(void* dest, const void* msg, uint32_t msg_length_b){ /*********************************************************************/ -void twister512_init(twister512_ctx_t* ctx){ +void twister512_init(twister512_ctx_t *ctx){ twister_large_init(ctx, 512); } /*********************************************************************/ -void twister512_nextBlock(twister512_ctx_t* ctx, const void* msg){ +void twister512_nextBlock(twister512_ctx_t *ctx, const void *msg){ twister_large_nextBlock(ctx, msg); } /*********************************************************************/ -void twister512_lastBlock(twister512_ctx_t* ctx, const void* msg, uint16_t length_b){ +void twister512_lastBlock(twister512_ctx_t *ctx, const void *msg, uint16_t length_b){ twister_large_lastBlock(ctx, msg, length_b); } /*********************************************************************/ -void twister512_ctx2hash(void* dest, twister512_ctx_t* ctx){ +void twister512_ctx2hash(void *dest, twister512_ctx_t *ctx){ twister_large_ctx2hash(dest, ctx, 512); } /*********************************************************************/ -void twister512(void* dest, const void* msg, uint32_t msg_length_b){ +void twister512(void *dest, const void *msg, uint32_t msg_length_b){ twister_large_ctx_t ctx; twister_large_init(&ctx, 512); while(msg_length_b >=512){