we don't need SHA384
authorRonnie Sahlberg <ronniesahlberg@gmail.com>
Thu, 26 Sep 2019 05:13:03 +0000 (22:13 -0700)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Thu, 26 Sep 2019 05:13:03 +0000 (22:13 -0700)
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
lib/sha.h
lib/sha384-512.c
lib/usha.c

index 2851c65eb2221956e9bd983e510f3eda836b3514..038a4686bd527b14b2644b5ac2ce7475dc6c804f 100644 (file)
--- a/lib/sha.h
+++ b/lib/sha.h
   #define USE_SHA224 0
 #endif
 
+#ifndef USE_SHA384
+  #define USE_SHA384 0
+#endif
+
 /*
  *  Description:
  *      This file implements the Secure Hash Signature Standard
@@ -75,15 +79,20 @@ enum
   SHA224HashSize = 28,
   SHA224HashSizeBits = 224,
 #endif
-  SHA256_Message_Block_Size = 64, SHA384_Message_Block_Size = 128,
+#if defined(USE_SHA384) && USE_SHA384
+  SHA384_Message_Block_Size = 128,  
+  SHA384HashSize = 48,
+  SHA384HashSizeBits = 384,
+#endif
+  SHA256_Message_Block_Size = 64,
   SHA512_Message_Block_Size = 128,
   USHA_Max_Message_Block_Size = SHA512_Message_Block_Size,
 
   SHA256HashSize = 32,
-  SHA384HashSize = 48, SHA512HashSize = 64,
+  SHA512HashSize = 64,
   USHAMaxHashSize = SHA512HashSize,
 
-  SHA256HashSizeBits = 256, SHA384HashSizeBits = 384,
+  SHA256HashSizeBits = 256,
   SHA512HashSizeBits = 512, USHAMaxHashSizeBits = SHA512HashSizeBits
 };
 
@@ -98,7 +107,11 @@ typedef enum SHAversion
 #if defined(USE_SHA224) && USE_SHA224
   SHA224,
 #endif
-  SHA256, SHA384, SHA512
+  SHA256,
+#if defined(USE_SHA384) && USE_SHA384
+  SHA384,
+#endif
+  SHA512
 } SHAversion;
 
 #if defined(USE_SHA1) && USE_SHA1
@@ -170,11 +183,13 @@ typedef struct SHA512Context
 typedef struct SHA256Context SHA224Context;
 #endif
 
+#if defined(USE_SHA384) && USE_SHA384
 /*
  *  This structure will hold context information for the SHA-384
  *  hashing operation. It uses the SHA-512 structure for computation.
  */
 typedef struct SHA512Context SHA384Context;
+#endif
 
 /*
  *  This structure holds context information for all SHA
@@ -192,7 +207,9 @@ typedef struct USHAContext
     SHA224Context sha224Context;
 #endif
     SHA256Context sha256Context;
+#if defined(USE_SHA384) && USE_SHA384
     SHA384Context sha384Context;
+#endif
     SHA512Context sha512Context;
   } ctx;
 } USHAContext;
@@ -245,6 +262,7 @@ extern int SHA256FinalBits (SHA256Context *, const uint8_t bits,
 extern int SHA256Result (SHA256Context *,
                         uint8_t Message_Digest[SHA256HashSize]);
 
+#if defined(USE_SHA384) && USE_SHA384
 /* SHA-384 */
 extern int SHA384Reset (SHA384Context *);
 extern int SHA384Input (SHA384Context *, const uint8_t * bytes,
@@ -253,6 +271,7 @@ extern int SHA384FinalBits (SHA384Context *, const uint8_t bits,
                            unsigned int bitcount);
 extern int SHA384Result (SHA384Context *,
                         uint8_t Message_Digest[SHA384HashSize]);
+#endif
 
 /* SHA-512 */
 extern int SHA512Reset (SHA512Context *);
index b9063aa268323b2bd2298a5a971004b45d6eaf38..504530ab8983cd549b2727ac88e89cee6c84e4f2 100644 (file)
@@ -300,12 +300,14 @@ static int SHA384_512Reset (SHA512Context * context, uint64_t H0[]);
 static int SHA384_512ResultN (SHA512Context * context,
                              uint8_t Message_Digest[], int HashSize);
 
+#if defined(USE_SHA384) && USE_SHA384
 /* Initial Hash Values: FIPS-180-2 sections 5.3.3 and 5.3.4 */
 static uint64_t SHA384_H0[] = {
   0xCBBB9D5DC1059ED8ll, 0x629A292A367CD507ll, 0x9159015A3070DD17ll,
   0x152FECD8F70E5939ll, 0x67332667FFC00B31ll, 0x8EB44A8768581511ll,
   0xDB0C2E0D64F98FA7ll, 0x47B5481DBEFA4FA4ll
 };
+#endif
 
 static uint64_t SHA512_H0[] = {
   0x6A09E667F3BCC908ll, 0xBB67AE8584CAA73Bll, 0x3C6EF372FE94F82Bll,
@@ -315,6 +317,7 @@ static uint64_t SHA512_H0[] = {
 
 #endif /* USE_32BIT_ONLY */
 
+#if defined(USE_SHA384) && USE_SHA384
 /*
  * SHA384Reset
  *
@@ -414,6 +417,7 @@ SHA384Result (SHA384Context * context, uint8_t Message_Digest[SHA384HashSize])
 {
   return SHA384_512ResultN (context, Message_Digest, SHA384HashSize);
 }
+#endif
 
 /*
  * SHA512Reset
index bc23a22fa47b08cfe2d83740631bbbc9ccdfe100..71f2a58a71818d43ed0d1e8111158f4b57282dcc 100644 (file)
@@ -42,8 +42,10 @@ USHAReset (USHAContext * ctx, enum SHAversion whichSha)
 #endif
        case SHA256:
          return SHA256Reset ((SHA256Context *) & ctx->ctx);
+#if defined(USE_SHA384) && USE_SHA384
        case SHA384:
          return SHA384Reset ((SHA384Context *) & ctx->ctx);
+#endif
        case SHA512:
          return SHA512Reset ((SHA512Context *) & ctx->ctx);
        default:
@@ -93,8 +95,10 @@ USHAInput (USHAContext * ctx, const uint8_t * bytes, unsigned int bytecount)
 #endif
        case SHA256:
          return SHA256Input ((SHA256Context *) & ctx->ctx, bytes, bytecount);
+#if defined(USE_SHA384) && USE_SHA384
        case SHA384:
          return SHA384Input ((SHA384Context *) & ctx->ctx, bytes, bytecount);
+#endif
        case SHA512:
          return SHA512Input ((SHA512Context *) & ctx->ctx, bytes, bytecount);
        default:
@@ -145,9 +149,11 @@ USHAFinalBits (USHAContext * ctx, const uint8_t bits, unsigned int bitcount)
        case SHA256:
          return SHA256FinalBits ((SHA256Context *) & ctx->ctx, bits,
                                  bitcount);
+#if defined(USE_SHA384) && USE_SHA384
        case SHA384:
          return SHA384FinalBits ((SHA384Context *) & ctx->ctx, bits,
                                  bitcount);
+#endif
        case SHA512:
          return SHA512FinalBits ((SHA512Context *) & ctx->ctx, bits,
                                  bitcount);
@@ -197,8 +203,10 @@ USHAResult (USHAContext * ctx, uint8_t Message_Digest[USHAMaxHashSize])
 #endif
        case SHA256:
          return SHA256Result ((SHA256Context *) & ctx->ctx, Message_Digest);
+#if defined(USE_SHA384) && USE_SHA384
        case SHA384:
          return SHA384Result ((SHA384Context *) & ctx->ctx, Message_Digest);
+#endif
        case SHA512:
          return SHA512Result ((SHA512Context *) & ctx->ctx, Message_Digest);
        default:
@@ -241,8 +249,10 @@ USHABlockSize (enum SHAversion whichSha)
 #endif
     case SHA256:
       return SHA256_Message_Block_Size;
+#if defined(USE_SHA384) && USE_SHA384
     case SHA384:
       return SHA384_Message_Block_Size;
+#endif
     default:
     case SHA512:
       return SHA512_Message_Block_Size;
@@ -279,8 +289,10 @@ USHAHashSize (enum SHAversion whichSha)
 #endif
     case SHA256:
       return SHA256HashSize;
+#if defined(USE_SHA384) && USE_SHA384
     case SHA384:
       return SHA384HashSize;
+#endif
     default:
     case SHA512:
       return SHA512HashSize;
@@ -317,8 +329,10 @@ USHAHashSizeBits (enum SHAversion whichSha)
 #endif
     case SHA256:
       return SHA256HashSizeBits;
+#if defined(USE_SHA384) && USE_SHA384
     case SHA384:
       return SHA384HashSizeBits;
+#endif
     default:
     case SHA512:
       return SHA512HashSizeBits;