ソースを参照

Add RestorePos

Takashi Kojo 9 年 前
コミット
7ef85d1894
3 ファイル変更39 行追加11 行削除
  1. 12 10
      wolfcrypt/src/hash.c
  2. 21 1
      wolfcrypt/src/port/ti/ti-hash.c
  3. 6 0
      wolfssl/wolfcrypt/hash.h

+ 12 - 10
wolfcrypt/src/hash.c

@@ -27,16 +27,6 @@
 
 #if !defined(WOLFSSL_TI_HASH)
 
-#if !defined(NO_MD5)
-#include <wolfssl/wolfcrypt/md5.h>
-#endif
-#if !defined(NO_SHA)
-#include <wolfssl/wolfcrypt/sha.h>
-#endif
-#if !defined(NO_SHA256)
-#include <wolfssl/wolfcrypt/sha256.h>
-#endif
-
 #include <wolfssl/wolfcrypt/hash.h>
 
 #if !defined(NO_MD5)
@@ -46,6 +36,10 @@ void wc_Md5GetHash(Md5* md5, byte* hash)
     wc_Md5Final(md5, hash) ;
     *md5 = save ;
 }
+
+WOLFSSL_API void wc_Md5RestorePos(Md5* m1, Md5* m2) {
+    *m1 = *m2 ;
+}
 #endif
 
 #if !defined(NO_SHA)
@@ -57,6 +51,10 @@ int wc_ShaGetHash(Sha* sha, byte* hash)
     *sha = save ;
     return ret ;
 }
+
+WOLFSSL_API void wc_ShaRestorePos(Sha* s1, Sha* s2) {
+    *s1 = *s2 ;
+}
 #endif
 
 #if !defined(NO_SHA256)
@@ -68,6 +66,10 @@ int wc_Sha256GetHash(Sha256* sha256, byte* hash)
     *sha256 = save ;
     return ret ;
 }
+
+WOLFSSL_API void wc_Sha256RestorePos(Sha256* s1, Sha256* s2) {
+    *s1 = *s2 ;
+}
 #endif
 
 #endif

+ 21 - 1
wolfcrypt/src/port/ti/ti-hash.c

@@ -107,6 +107,10 @@ static int hashGetHash(wolfssl_TI_Hash *hash, byte* result, word32 algo, word32
     return 0 ;
 }
 
+static void hashRestorePos(wolfssl_TI_Hash *h1, wolfssl_TI_Hash *h2) {
+	h1->used = h2->used ;
+}
+
 static int hashFinal(wolfssl_TI_Hash *hash, byte* result, word32 algo, word32 hsize)
 {   
     hashGetHash(hash, result, algo, hsize) ;
@@ -166,7 +170,11 @@ WOLFSSL_API void wc_Md5Final(Md5* md5, byte* hash)
 
 WOLFSSL_API void wc_Md5GetHash(Md5* md5, byte* hash)
 {
-    hashGetHash(md5, hash, SHAMD5_ALGO_MD5, MD5_DIGEST_SIZE) ;
+    hashGetHash((wolfssl_TI_Hash *)md5, hash, SHAMD5_ALGO_MD5, MD5_DIGEST_SIZE) ;
+}
+
+WOLFSSL_API void wc_Md5RestorePos(Md5* m1, Md5* m2) {
+	hashRestorePos((wolfssl_TI_Hash *)m1, (wolfssl_TI_Hash *)m2) ;
 }
 
 WOLFSSL_API int wc_Md5Hash(const byte*data, word32 len, byte*hash)
@@ -200,6 +208,10 @@ WOLFSSL_API int wc_ShaGetHash(Sha* sha, byte* hash)
     return hashGetHash(sha, hash, SHAMD5_ALGO_SHA1, SHA_DIGEST_SIZE) ;
 }
 
+WOLFSSL_API void wc_ShaRestorePos(Sha* s1, Sha* s2) {
+	hashRestorePos((wolfssl_TI_Hash *)s1, (wolfssl_TI_Hash *)s2) ;
+}
+
 WOLFSSL_API int wc_ShaHash(const byte*data, word32 len, byte*hash)
 { 
     return hashHash(data, len, hash, SHAMD5_ALGO_SHA1, SHA_DIGEST_SIZE) ;
@@ -231,6 +243,10 @@ WOLFSSL_API int wc_Sha224GetHash(Sha224* sha224, byte* hash)
     return hashGetHash(sha224, hash, SHAMD5_ALGO_SHA224, SHA224_DIGEST_SIZE) ;
 }
 
+WOLFSSL_API void wc_Sha224RestorePos(Sha224* s1, Sha224* s2) {
+	hashRestorePos((wolfssl_TI_Hash *)s1, (wolfssl_TI_Hash *)s2) ;
+}
+
 WOLFSSL_API int wc_Sha224Hash(const byte* data, word32 len, byte*hash)
 { 
     return hashHash(data, len, hash, SHAMD5_ALGO_SHA224, SHA224_DIGEST_SIZE) ;
@@ -262,6 +278,10 @@ WOLFSSL_API int wc_Sha256GetHash(Sha256* sha256, byte* hash)
     return hashGetHash(sha256, hash, SHAMD5_ALGO_SHA256, SHA256_DIGEST_SIZE) ;
 }
 
+WOLFSSL_API void wc_Sha256RestorePos(Sha256* s1, Sha256* s2) {
+	hashRestorePos((wolfssl_TI_Hash *)s1, (wolfssl_TI_Hash *)s2) ;
+}
+
 WOLFSSL_API int wc_Sha256Hash(const byte* data, word32 len, byte*hash)
 {
     return hashHash(data, len, hash, SHAMD5_ALGO_SHA256, SHA256_DIGEST_SIZE) ;

+ 6 - 0
wolfssl/wolfcrypt/hash.h

@@ -23,13 +23,19 @@
 #define WOLF_CRYPT_HASH_H
 
 #ifndef NO_MD5
+#include <wolfssl/wolfcrypt/md5.h>
 WOLFSSL_API void wc_Md5GetHash(Md5*, byte*);
+WOLFSSL_API void wc_Md5RestorePos(Md5*, Md5*) ;
 #endif
 #ifndef NO_SHA
+#include <wolfssl/wolfcrypt/sha.h>
 WOLFSSL_API int wc_ShaGetHash(Sha*, byte*);
+WOLFSSL_API void wc_ShaRestorePos(Sha*, Sha*) ;
 #endif
 #ifndef NO_SHA256
+#include <wolfssl/wolfcrypt/sha256.h>
 WOLFSSL_API int wc_Sha256GetHash(Sha256*, byte*);
+WOLFSSL_API void wc_Sha256RestorePos(Sha256*, Sha256*) ;
 #endif
 
 #endif