From: bg Date: Wed, 9 Jul 2008 03:22:58 +0000 (+0000) Subject: +some changes in make architecture +hmac-sha1 X-Git-Url: https://git.cryptolib.org/?a=commitdiff_plain;h=33c19d7ea9dafc19b818dd8de984dcf1543d7b37;p=avr-crypto-lib.git +some changes in make architecture +hmac-sha1 --- diff --git a/Makefile b/Makefile index e725133..ec201f4 100644 --- a/Makefile +++ b/Makefile @@ -150,7 +150,7 @@ $(1)_FLASH: $(2) endef $(foreach algo, $(ALGORITHMS),$(eval $(call FLASH_TEMPLATE, $(algo), \ - $(patsubst %.o,%.hex,$(firstword $($(algo)_TEST_BIN)))) )) + $(patsubst $(BIN_DIR)%.o,$(TESTBIN_DIR)%.hex,$(firstword $($(algo)_TEST_BIN)))) )) #------------------------------------------------------------------------------- diff --git a/hmac-sha256.c b/hmac-sha256.c index a0ad1dc..274c9c4 100644 --- a/hmac-sha256.c +++ b/hmac-sha256.c @@ -40,41 +40,41 @@ typedef sha256_ctx_t hmac_sha256_ctx_t; #ifndef HMAC_SHORTONLY -void hmac_sha256_init(hmac_sha256_ctx_t *s, void* key, uint16_t kl){ - uint8_t buffer[SHA256_BLOCK_BITS/8]; +void hmac_sha256_init(hmac_sha256_ctx_t *s, void* key, uint16_t keylength_b){ + uint8_t buffer[SHA256_HASH_BYTES]; uint8_t i; - memset(buffer, 0, SHA256_BLOCK_BITS/8); - if (kl > SHA256_BLOCK_BITS){ - sha256((void*)buffer, key, kl); + memset(buffer, 0, SHA256_HASH_BYTES); + if (keylength_b > SHA256_BLOCK_BITS){ + sha256((void*)buffer, key, keylength_b); } else { - memcpy(buffer, key, (kl+7)/8); + memcpy(buffer, key, (keylength_b+7)/8); } - for (i=0; i SHA256_BLOCK_BITS){ - sha256((void*)buffer, key, kl); + memset(buffer, 0, SHA256_HASH_BYTES); + if (keylength_b > SHA256_BLOCK_BITS){ + sha256((void*)buffer, key, keylength_b); } else { - memcpy(buffer, key, (kl+7)/8); + memcpy(buffer, key, (keylength_b+7)/8); } - for (i=0; i SHA256_BLOCK_BITS){ - sha256((void*)buffer, key, kl); + if (keylength_b > SHA256_BLOCK_BITS){ + sha256((void*)buffer, key, keylength_b); } else { - memcpy(buffer, key, (kl+7)/8); + memcpy(buffer, key, (keylength_b+7)/8); } - for (i=0; i= SHA256_BLOCK_BITS){ + while (msglength_b >= SHA256_BLOCK_BITS){ sha256_nextBlock(&s, msg); - msg = (uint8_t*)msg + SHA256_BLOCK_BITS/8; - ml -= SHA256_BLOCK_BITS; + msg = (uint8_t*)msg + SHA256_HASH_BYTES; + msglength_b -= SHA256_BLOCK_BITS; } - sha256_lastBlock(&s, msg, ml); + sha256_lastBlock(&s, msg, msglength_b); /* since buffer still contains key xor ipad we can do ... */ - for (i=0; i. -*/ -/** - * \file sha256-asm.h - * \author Daniel Otte - * \date 16.05.2006 - * \par License - * GPL - * - */ - -#ifndef SHA256ASM_H_ -#define SHA256ASM_H_ - - -#define SHA256_HASH_BITS 256 -#define SHA256_BLOCK_BITS 512 - -typedef struct { - uint32_t h[8]; - uint64_t length; -} sha256_ctx_t; - -typedef uint8_t sha256_hash_t[SHA256_HASH_BITS/8]; - -void sha256_ctx2hash(sha256_hash_t *dest, sha256_ctx_t *state); -void sha256(sha256_hash_t *dest, void* msg, uint32_t length); -void sha256_init(sha256_ctx_t *state); -void sha256_nextBlock(sha256_ctx_t *state, void* block); -void sha256_lastBlock(sha256_ctx_t *state, void* block, uint16_t length); -uint32_t rotr32(uint32_t, uint8_t); -uint32_t change_endian32(uint32_t x); - -#endif /*SHA256ASM_H_*/ diff --git a/sha256.h b/sha256.h index b76aa5f..ec1dac0 100644 --- a/sha256.h +++ b/sha256.h @@ -35,7 +35,9 @@ #define SHA256_HASH_BITS 256 +#define SHA256_HASH_BYTES (SHA256_HASH_BITS/8) #define SHA256_BLOCK_BITS 512 +#define SHA256_BLOCK_BYTES (SHA256_BLOCK_BITS/8) /** * \brief sha256 context type @@ -46,19 +48,19 @@ typedef struct { uint64_t length; } sha256_ctx_t; -typedef uint8_t sha256_hash_t[SHA256_HASH_BITS/8]; +typedef uint8_t sha256_hash_t[SHA256_HASH_BYTES]; void sha256_init(sha256_ctx_t *state); void sha256_nextBlock (sha256_ctx_t *state, const void* block); -void sha256_lastBlock(sha256_ctx_t *state, const void* block, uint16_t length); +void sha256_lastBlock(sha256_ctx_t *state, const void* block, uint16_t length_b); void sha256_ctx2hash(sha256_hash_t *dest, const sha256_ctx_t *state); /* * length in bits! */ -void sha256(sha256_hash_t *dest, const void* msg, uint32_t length); +void sha256(sha256_hash_t *dest, const void* msg, uint32_t length_b); uint32_t change_endian32(uint32_t x);