Bug 1526302 - remove MD2 support from nsICryptoHash, clarifiy hash IDs must be synchronized with NSS hasht.h r=keeler
authorKai Engert <kaie@kuix.de>
Sat, 02 Mar 2019 15:37:30 +0000
changeset 520035 7f427fb15eae1d9addfa9e1db9a548235561ca4d
parent 520034 b62eba3cf3b6a42eca5dd050c440ecae0260c9ff
child 520036 1a37e28f12b1bf3fd880333f612243c56f290842
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskeeler
bugs1526302
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1526302 - remove MD2 support from nsICryptoHash, clarifiy hash IDs must be synchronized with NSS hasht.h r=keeler Differential Revision: https://phabricator.services.mozilla.com/D19150
security/manager/ssl/nsCryptoHash.cpp
security/manager/ssl/nsICryptoHash.idl
security/manager/ssl/tests/unit/test_hash_algorithms.js
--- a/security/manager/ssl/nsCryptoHash.cpp
+++ b/security/manager/ssl/nsCryptoHash.cpp
@@ -33,19 +33,16 @@ static const uint64_t STREAM_BUFFER_SIZE
 nsCryptoHash::nsCryptoHash() : mHashContext(nullptr), mInitialized(false) {}
 
 NS_IMPL_ISUPPORTS(nsCryptoHash, nsICryptoHash)
 
 NS_IMETHODIMP
 nsCryptoHash::Init(uint32_t algorithm) {
   HASH_HashType hashType;
   switch (algorithm) {
-    case nsICryptoHash::MD2:
-      hashType = HASH_AlgMD2;
-      break;
     case nsICryptoHash::MD5:
       hashType = HASH_AlgMD5;
       break;
     case nsICryptoHash::SHA1:
       hashType = HASH_AlgSHA1;
       break;
     case nsICryptoHash::SHA256:
       hashType = HASH_AlgSHA256;
@@ -80,18 +77,16 @@ nsCryptoHash::Init(uint32_t algorithm) {
 
   HASH_Begin(mHashContext.get());
   mInitialized = true;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsCryptoHash::InitWithString(const nsACString &aAlgorithm) {
-  if (aAlgorithm.LowerCaseEqualsLiteral("md2")) return Init(nsICryptoHash::MD2);
-
   if (aAlgorithm.LowerCaseEqualsLiteral("md5")) return Init(nsICryptoHash::MD5);
 
   if (aAlgorithm.LowerCaseEqualsLiteral("sha1"))
     return Init(nsICryptoHash::SHA1);
 
   if (aAlgorithm.LowerCaseEqualsLiteral("sha256"))
     return Init(nsICryptoHash::SHA256);
 
--- a/security/manager/ssl/nsICryptoHash.idl
+++ b/security/manager/ssl/nsICryptoHash.idl
@@ -11,20 +11,21 @@ interface nsIInputStream;
  */
 
 [builtinclass, scriptable, uuid(1e5b7c43-4688-45ce-92e1-77ed931e3bbe)]
 interface nsICryptoHash : nsISupports
 {
     /**
      * Hashing Algorithms.  These values are to be used by the
      * |init| method to indicate which hashing function to
-     * use.  These values map directly onto the values defined
-     * in mozilla/security/nss/lib/cryptohi/hasht.h.
+     * use.  These values must be identical to the values defined
+     * in security/nss/lib/util/hasht.h in type HASH_HashType.
+     * This allows us to use NSS mapping functions like
+     * HASH_GetHashOidTagByHashType with these values.
      */
-    const short MD2    = 1;  /* String value: "md2"    */
     const short MD5    = 2;  /* String value: "md5"    */
     const short SHA1   = 3;  /* String value: "sha1"   */
     const short SHA256 = 4;  /* String value: "sha256" */
     const short SHA384 = 5;  /* String value: "sha384" */
     const short SHA512 = 6;  /* String value: "sha512" */
 
     /**
      * Initialize the hashing object. This method may be
--- a/security/manager/ssl/tests/unit/test_hash_algorithms.js
+++ b/security/manager/ssl/tests/unit/test_hash_algorithms.js
@@ -4,28 +4,16 @@
 // of the supported algorithms.
 
 const messages = [
   "The quick brown fox jumps over the lazy dog",
   "",
 ];
 const ALGORITHMS = [
   {
-    initString: "md2",
-    initConstant: Ci.nsICryptoHash.MD2,
-    hexHashes: [
-      "03d85a0d629d2c442e987525319fc471",
-      "8350e5a3e24c153df2275c9f80692773",
-    ],
-    b64Hashes: [
-      "A9haDWKdLEQumHUlMZ/EcQ==",
-      "g1Dlo+JMFT3yJ1yfgGkncw==",
-    ],
-  },
-  {
     initString: "md5",
     initConstant: Ci.nsICryptoHash.MD5,
     hexHashes: [
       "9e107d9d372bb6826bd81d3542a419d6",
       "d41d8cd98f00b204e9800998ecf8427e",
     ],
     b64Hashes: [
       "nhB9nTcrtoJr2B01QqQZ1g==",