Explorar o código

cmCryptoHash: Add support for SHA-3 algorithms

Brad King %!s(int64=9) %!d(string=hai) anos
pai
achega
c326209fa3
Modificáronse 2 ficheiros con 29 adicións e 8 borrados
  1. 22 6
      Source/cmCryptoHash.cxx
  2. 7 2
      Source/cmCryptoHash.h

+ 22 - 6
Source/cmCryptoHash.cxx

@@ -9,12 +9,16 @@
 
 static unsigned int const cmCryptoHashAlgoToId[] = {
   /* clang-format needs this comment to break after the opening brace */
-  RHASH_MD5,    //
-  RHASH_SHA1,   //
-  RHASH_SHA224, //
-  RHASH_SHA256, //
-  RHASH_SHA384, //
-  RHASH_SHA512
+  RHASH_MD5,      //
+  RHASH_SHA1,     //
+  RHASH_SHA224,   //
+  RHASH_SHA256,   //
+  RHASH_SHA384,   //
+  RHASH_SHA512,   //
+  RHASH_SHA3_224, //
+  RHASH_SHA3_256, //
+  RHASH_SHA3_384, //
+  RHASH_SHA3_512
 };
 
 static int cmCryptoHash_rhash_library_initialized;
@@ -59,6 +63,18 @@ CM_AUTO_PTR<cmCryptoHash> cmCryptoHash::New(const char* algo)
   if (strcmp(algo, "SHA512") == 0) {
     return CM_AUTO_PTR<cmCryptoHash>(new cmCryptoHash(AlgoSHA512));
   }
+  if (strcmp(algo, "SHA3_224") == 0) {
+    return CM_AUTO_PTR<cmCryptoHash>(new cmCryptoHash(AlgoSHA3_224));
+  }
+  if (strcmp(algo, "SHA3_256") == 0) {
+    return CM_AUTO_PTR<cmCryptoHash>(new cmCryptoHash(AlgoSHA3_256));
+  }
+  if (strcmp(algo, "SHA3_384") == 0) {
+    return CM_AUTO_PTR<cmCryptoHash>(new cmCryptoHash(AlgoSHA3_384));
+  }
+  if (strcmp(algo, "SHA3_512") == 0) {
+    return CM_AUTO_PTR<cmCryptoHash>(new cmCryptoHash(AlgoSHA3_512));
+  }
   return CM_AUTO_PTR<cmCryptoHash>(CM_NULLPTR);
 }
 

+ 7 - 2
Source/cmCryptoHash.h

@@ -22,7 +22,11 @@ public:
     AlgoSHA224,
     AlgoSHA256,
     AlgoSHA384,
-    AlgoSHA512
+    AlgoSHA512,
+    AlgoSHA3_224,
+    AlgoSHA3_256,
+    AlgoSHA3_384,
+    AlgoSHA3_512
   };
 
   cmCryptoHash(Algo algo);
@@ -30,7 +34,8 @@ public:
 
   /// @brief Returns a new hash generator of the requested type
   /// @arg algo Hash type name. Supported hash types are
-  ///      MD5, SHA1, SHA224, SHA256, SHA384, SHA512
+  ///      MD5, SHA1, SHA224, SHA256, SHA384, SHA512,
+  ///      SHA3_224, SHA3_256, SHA3_384, SHA3_512
   /// @return A valid auto pointer if algo is supported or
   ///         an invalid/NULL pointer otherwise
   static CM_AUTO_PTR<cmCryptoHash> New(const char* algo);