+some changes in make architecture +hmac-sha1
This commit is contained in:
parent
e048ac1e57
commit
33c19d7ea9
2
Makefile
2
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)))) ))
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -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/8; ++i){
|
||||
for (i=0; i<SHA256_HASH_BYTES; ++i){
|
||||
buffer[i] ^= IPAD;
|
||||
}
|
||||
|
||||
sha256_init(s);
|
||||
sha256_nextBlock(s, buffer);
|
||||
#if defined SECURE_WIPE_BUFFER
|
||||
memset(buffer, 0, SHA256_BLOCK_BITS/8);
|
||||
memset(buffer, 0, SHA256_HASH_BYTES);
|
||||
#endif
|
||||
}
|
||||
|
||||
void hmac_sha256_final(hmac_sha256_ctx_t *s, void* key, uint16_t kl){
|
||||
uint8_t buffer[SHA256_BLOCK_BITS/8];
|
||||
void hmac_sha256_final(hmac_sha256_ctx_t *s, void* key, uint16_t keylength_b){
|
||||
uint8_t buffer[SHA256_HASH_BYTES];
|
||||
uint8_t i;
|
||||
sha256_ctx_t a;
|
||||
|
||||
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/8; ++i){
|
||||
for (i=0; i<SHA256_HASH_BYTES; ++i){
|
||||
buffer[i] ^= OPAD;
|
||||
}
|
||||
|
||||
|
@ -84,7 +84,7 @@ void hmac_sha256_final(hmac_sha256_ctx_t *s, void* key, uint16_t kl){
|
|||
sha256_lastBlock(&a, buffer, SHA256_HASH_BITS);
|
||||
memcpy(s, &a, sizeof(sha256_ctx_t));
|
||||
#if defined SECURE_WIPE_BUFFER
|
||||
memset(buffer, 0, SHA256_BLOCK_BITS/8);
|
||||
memset(buffer, 0, SHA256_HASH_BYTES);
|
||||
memset(a.h, 0, 8*4);
|
||||
#endif
|
||||
}
|
||||
|
@ -100,33 +100,33 @@ void hmac_sha256_lastBlock()
|
|||
* keylength in bits!
|
||||
* message length in bits!
|
||||
*/
|
||||
void hmac_sha256(void* dest, void* key, uint16_t kl, void* msg, uint64_t ml){ /* a one-shot*/
|
||||
void hmac_sha256(void* dest, void* key, uint16_t keylength_b, void* msg, uint64_t msglength_b){ /* a one-shot*/
|
||||
sha256_ctx_t s;
|
||||
uint8_t i;
|
||||
uint8_t buffer[SHA256_BLOCK_BITS/8];
|
||||
uint8_t buffer[SHA256_HASH_BYTES];
|
||||
|
||||
memset(buffer, 0, SHA256_BLOCK_BITS/8);
|
||||
memset(buffer, 0, SHA256_HASH_BYTES);
|
||||
|
||||
/* if key is larger than a block we have to hash it*/
|
||||
if (kl > 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/8; ++i){
|
||||
for (i=0; i<SHA256_HASH_BYTES; ++i){
|
||||
buffer[i] ^= IPAD;
|
||||
}
|
||||
sha256_init(&s);
|
||||
sha256_nextBlock(&s, buffer);
|
||||
while (ml >= 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<SHA256_BLOCK_BITS/8; ++i){
|
||||
for (i=0; i<SHA256_HASH_BYTES; ++i){
|
||||
buffer[i] ^= IPAD ^ OPAD;
|
||||
}
|
||||
sha256_ctx2hash(dest, &s); /* save inner hash temporary to dest */
|
||||
|
|
|
@ -27,9 +27,9 @@
|
|||
typedef sha256_ctx_t hmac_sha256_ctx_t;
|
||||
|
||||
|
||||
void hmac_sha256_init(hmac_sha256_ctx_t *s, void* key, uint16_t kl);
|
||||
void hmac_sha256_final(hmac_sha256_ctx_t *s, void* key, uint16_t kl);
|
||||
void hmac_sha256(void* dest, void* key, uint16_t kl, void* msg, uint64_t ml);
|
||||
void hmac_sha256_init(hmac_sha256_ctx_t *s, void* key, uint16_t keylength_b);
|
||||
void hmac_sha256_final(hmac_sha256_ctx_t *s, void* key, uint16_t keylength_b);
|
||||
void hmac_sha256(void* dest, void* key, uint16_t keylength_b, void* msg, uint64_t msglength_b);
|
||||
|
||||
|
||||
#endif /*HMACSHA256_H_*/
|
||||
|
|
10
sha1.h
10
sha1.h
|
@ -19,7 +19,7 @@
|
|||
/**
|
||||
* \file sha1.c
|
||||
* \author Daniel Otte
|
||||
* \date 08.10.2006
|
||||
* \date 2006-10-08
|
||||
* \par License:
|
||||
* GPL
|
||||
* \brief SHA-1 declaration.
|
||||
|
@ -33,7 +33,9 @@
|
|||
|
||||
|
||||
#define SHA1_HASH_BITS 160
|
||||
#define SHA1_HASH_BYTES (SHA1_HASH_BITS/8)
|
||||
#define SHA1_BLOCK_BITS 512
|
||||
#define SHA1_BLOCK_BYTES (SHA1_BLOCK_BITS/8)
|
||||
|
||||
/**
|
||||
* \brief SHA-1 context type
|
||||
|
@ -49,12 +51,10 @@ typedef uint8_t sha1_hash_t[SHA1_HASH_BITS/8];
|
|||
void sha1_init(sha1_ctx_t *state);
|
||||
|
||||
void sha1_nextBlock (sha1_ctx_t *state, void* block);
|
||||
void sha1_lastBlock (sha1_ctx_t *state, void* block, uint16_t length);
|
||||
void sha1_lastBlock (sha1_ctx_t *state, void* block, uint16_t length_b);
|
||||
|
||||
void sha1_ctx2hash (sha1_hash_t *dest, sha1_ctx_t *state);
|
||||
void sha1 (sha1_hash_t *dest, void* msg, uint32_t length);
|
||||
//uint32_t change_endian32(uint32_t x);
|
||||
|
||||
void sha1 (sha1_hash_t *dest, void* msg, uint32_t length_b);
|
||||
|
||||
|
||||
|
||||
|
|
50
sha256-asm.h
50
sha256-asm.h
|
@ -1,50 +0,0 @@
|
|||
/* sha256-asm.h */
|
||||
/*
|
||||
This file is part of the Crypto-avr-lib/microcrypt-lib.
|
||||
Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de)
|
||||
|
||||
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
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/**
|
||||
* \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_*/
|
8
sha256.h
8
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);
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue