we dont need sha1
authorRonnie Sahlberg <ronniesahlberg@gmail.com>
Thu, 26 Sep 2019 05:07:15 +0000 (22:07 -0700)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Thu, 26 Sep 2019 05:07:15 +0000 (22:07 -0700)
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
lib/sha.h
lib/sha1.c
lib/usha.c

index e001fed4c2f15af3c421b148efc7f49cec2df8d3..2851c65eb2221956e9bd983e510f3eda836b3514 100644 (file)
--- a/lib/sha.h
+++ b/lib/sha.h
@@ -3,6 +3,10 @@
 #ifndef _SHA_H_
 #define _SHA_H_
 
+#ifndef USE_SHA1
+  #define USE_SHA1 0
+#endif
+
 #ifndef USE_SHA224
   #define USE_SHA224 0
 #endif
@@ -61,21 +65,24 @@ enum
  */
 enum
 {
+#if defined(USE_SHA1) && USE_SHA1
+  SHA1_Message_Block_Size = 64,
+  SHA1HashSize = 20,
+  SHA1HashSizeBits = 160,
+#endif
 #if defined(USE_SHA224) && USE_SHA224
   SHA224_Message_Block_Size = 64,
   SHA224HashSize = 28,
   SHA224HashSizeBits = 224,
 #endif
-  SHA1_Message_Block_Size = 64,
   SHA256_Message_Block_Size = 64, SHA384_Message_Block_Size = 128,
   SHA512_Message_Block_Size = 128,
   USHA_Max_Message_Block_Size = SHA512_Message_Block_Size,
 
-  SHA1HashSize = 20, SHA256HashSize = 32,
+  SHA256HashSize = 32,
   SHA384HashSize = 48, SHA512HashSize = 64,
   USHAMaxHashSize = SHA512HashSize,
 
-  SHA1HashSizeBits = 160,
   SHA256HashSizeBits = 256, SHA384HashSizeBits = 384,
   SHA512HashSizeBits = 512, USHAMaxHashSizeBits = SHA512HashSizeBits
 };
@@ -85,12 +92,16 @@ enum
  */
 typedef enum SHAversion
 {
+#if defined(USE_SHA1) && USE_SHA1
+  SHA1,
+#endif
 #if defined(USE_SHA224) && USE_SHA224
   SHA224,
 #endif
-  SHA1, SHA256, SHA384, SHA512
+  SHA256, SHA384, SHA512
 } SHAversion;
 
+#if defined(USE_SHA1) && USE_SHA1
 /*
  *  This structure will hold context information for the SHA-1
  *  hashing operation.
@@ -109,6 +120,7 @@ typedef struct SHA1Context
   int Computed;                        /* Is the digest computed? */
   int Corrupted;               /* Is the digest corrupted? */
 } SHA1Context;
+#endif
 
 /*
  *  This structure will hold context information for the SHA-256
@@ -173,7 +185,9 @@ typedef struct USHAContext
   int whichSha;                        /* which SHA is being used */
   union
   {
+#if defined(USE_SHA1) && USE_SHA1
     SHA1Context sha1Context;
+#endif
 #if defined(USE_SHA224) && USE_SHA224
     SHA224Context sha224Context;
 #endif
@@ -201,6 +215,7 @@ typedef struct HMACContext
  *  Function Prototypes
  */
 
+#if defined(USE_SHA1) && USE_SHA1
 /* SHA-1 */
 extern int SHA1Reset (SHA1Context *);
 extern int SHA1Input (SHA1Context *, const uint8_t * bytes,
@@ -208,6 +223,7 @@ extern int SHA1Input (SHA1Context *, const uint8_t * bytes,
 extern int SHA1FinalBits (SHA1Context *, const uint8_t bits,
                          unsigned int bitcount);
 extern int SHA1Result (SHA1Context *, uint8_t Message_Digest[SHA1HashSize]);
+#endif
 
 #if defined(USE_SHA224) && USE_SHA224
 /* SHA-224 */
index e96588ab834626296a1e4396ea338f303d8ce3d9..9ca4a8df9be3c19df8edf9d9eee10a4e7d2a5fdf 100644 (file)
@@ -38,6 +38,8 @@
 #include "sha.h"
 #include "sha-private.h"
 
+#if defined(USE_SHA1) && USE_SHA1
+
 /*
  *  Define the SHA1 circular left shift macro
  */
@@ -440,3 +442,5 @@ SHA1ProcessMessageBlock (SHA1Context * context)
 
   context->Message_Block_Index = 0;
 }
+
+#endif /* defined(USE_SHA1) && USE_SHA1 */
index 7b39cb2b798243e00e9102ccdc5d793d19d8703d..bc23a22fa47b08cfe2d83740631bbbc9ccdfe100 100644 (file)
@@ -32,12 +32,14 @@ USHAReset (USHAContext * ctx, enum SHAversion whichSha)
       ctx->whichSha = whichSha;
       switch (whichSha)
        {
+#if defined(USE_SHA1) && USE_SHA1
+       case SHA1:
+         return SHA1Reset ((SHA1Context *) & ctx->ctx);
+#endif
 #if defined(USE_SHA224) && USE_SHA224
        case SHA224:
          return SHA224Reset ((SHA224Context *) & ctx->ctx);
 #endif
-       case SHA1:
-         return SHA1Reset ((SHA1Context *) & ctx->ctx);
        case SHA256:
          return SHA256Reset ((SHA256Context *) & ctx->ctx);
        case SHA384:
@@ -81,12 +83,14 @@ USHAInput (USHAContext * ctx, const uint8_t * bytes, unsigned int bytecount)
     {
       switch (ctx->whichSha)
        {
+#if defined(USE_SHA1) && USE_SHA1
+       case SHA1:
+         return SHA1Input ((SHA1Context *) & ctx->ctx, bytes, bytecount);
+#endif
 #if defined(USE_SHA224) && USE_SHA224
        case SHA224:
          return SHA224Input ((SHA224Context *) & ctx->ctx, bytes, bytecount);
 #endif
-       case SHA1:
-         return SHA1Input ((SHA1Context *) & ctx->ctx, bytes, bytecount);
        case SHA256:
          return SHA256Input ((SHA256Context *) & ctx->ctx, bytes, bytecount);
        case SHA384:
@@ -129,13 +133,15 @@ USHAFinalBits (USHAContext * ctx, const uint8_t bits, unsigned int bitcount)
     {
       switch (ctx->whichSha)
        {
+#if defined(USE_SHA1) && USE_SHA1
+       case SHA1:
+         return SHA1FinalBits ((SHA1Context *) & ctx->ctx, bits, bitcount);
+#endif
 #if defined(USE_SHA224) && USE_SHA224
        case SHA224:
          return SHA224FinalBits ((SHA224Context *) & ctx->ctx, bits,
                                  bitcount);
 #endif
-       case SHA1:
-         return SHA1FinalBits ((SHA1Context *) & ctx->ctx, bits, bitcount);
        case SHA256:
          return SHA256FinalBits ((SHA256Context *) & ctx->ctx, bits,
                                  bitcount);
@@ -181,12 +187,14 @@ USHAResult (USHAContext * ctx, uint8_t Message_Digest[USHAMaxHashSize])
     {
       switch (ctx->whichSha)
        {
+#if defined(USE_SHA1) && USE_SHA1
+       case SHA1:
+         return SHA1Result ((SHA1Context *) & ctx->ctx, Message_Digest);
+#endif
 #if defined(USE_SHA224) && USE_SHA224
        case SHA224:
          return SHA224Result ((SHA224Context *) & ctx->ctx, Message_Digest);
 #endif
-       case SHA1:
-         return SHA1Result ((SHA1Context *) & ctx->ctx, Message_Digest);
        case SHA256:
          return SHA256Result ((SHA256Context *) & ctx->ctx, Message_Digest);
        case SHA384:
@@ -223,12 +231,14 @@ USHABlockSize (enum SHAversion whichSha)
 {
   switch (whichSha)
     {
+#if defined(USE_SHA1) && USE_SHA1
+    case SHA1:
+      return SHA1_Message_Block_Size;
+#endif
 #if defined(USE_SHA224) && USE_SHA224
     case SHA224:
       return SHA224_Message_Block_Size;
 #endif
-    case SHA1:
-      return SHA1_Message_Block_Size;
     case SHA256:
       return SHA256_Message_Block_Size;
     case SHA384:
@@ -259,12 +269,14 @@ USHAHashSize (enum SHAversion whichSha)
 {
   switch (whichSha)
     {
+#if defined(USE_SHA1) && USE_SHA1
+    case SHA1:
+      return SHA1HashSize;
+#endif
 #if defined(USE_SHA224) && USE_SHA224
     case SHA224:
       return SHA224HashSize;
 #endif
-    case SHA1:
-      return SHA1HashSize;
     case SHA256:
       return SHA256HashSize;
     case SHA384:
@@ -295,12 +307,14 @@ USHAHashSizeBits (enum SHAversion whichSha)
 {
   switch (whichSha)
     {
+#if defined(USE_SHA1) && USE_SHA1
+    case SHA1:
+      return SHA1HashSizeBits;
+#endif
 #if defined(USE_SHA224) && USE_SHA224
     case SHA224:
       return SHA224HashSizeBits;
 #endif
-    case SHA1:
-      return SHA1HashSizeBits;
     case SHA256:
       return SHA256HashSizeBits;
     case SHA384: