]> git.cryptolib.org Git - avr-crypto-lib.git/blobdiff - sha1/sha1.c
fixing bug in SHA1-C
[avr-crypto-lib.git] / sha1 / sha1.c
index 38126df744ebbd648cdb5009f001e4ae7570fbdf..4712e149bd70b51c61cfab3fd3c53cc68ebf94fb 100644 (file)
@@ -1,7 +1,7 @@
 /* sha1.c */
 /*
     This file is part of the AVR-Crypto-Lib.
-    Copyright (C) 2008  Daniel Otte (daniel.otte@rub.de)
+    Copyright (C) 2008, 2009  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
 #include <string.h> /* memcpy & co */
 #include <stdint.h>
 #include "config.h"
-#undef DEBUG
-//#define DEBUG UART
 #include "debug.h"
 #include "sha1.h"
 
+#ifdef DEBUG
+#  undef DEBUG
+#endif
+
+
 #define LITTLE_ENDIAN
 
 /********************************************************************************************************/
@@ -206,12 +209,12 @@ void sha1_lastBlock(sha1_ctx_t *state, const void* block, uint16_t length){
 void sha1_ctx2hash (sha1_hash_t *dest, sha1_ctx_t *state){
 #if defined LITTLE_ENDIAN
        uint8_t i;
-       for(i=0; i<8; ++i){
+       for(i=0; i<5; ++i){
                ((uint32_t*)dest)[i] = change_endian32(state->h[i]);
        }
 #elif BIG_ENDIAN
        if (dest != state->h)
-               memcpy(dest, state->h, SHA256_HASH_BITS/8);
+               memcpy(dest, state->h, SHA1_HASH_BITS/8);
 #else
 # error unsupported endian type!
 #endif