From 638c326719415e3d2af1241d0ba216b934c6e8e6 Mon Sep 17 00:00:00 2001 From: Tim Taubert Date: Sun, 8 Jun 2014 13:46:54 +0200 Subject: [PATCH] Bug 1022343 - Use the hash function's block size as the default length when generating keys r=rbarnes --- dom/crypto/WebCryptoTask.cpp | 16 +++++++++++----- dom/crypto/test/tests.js | 17 ++++++++++++++++- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/dom/crypto/WebCryptoTask.cpp b/dom/crypto/WebCryptoTask.cpp index a5bc950e0b69..94002a8ed691 100644 --- a/dom/crypto/WebCryptoTask.cpp +++ b/dom/crypto/WebCryptoTask.cpp @@ -1169,11 +1169,17 @@ public: } else { KeyAlgorithm hashAlg(global, hashName); switch (hashAlg.Mechanism()) { - case CKM_SHA_1: mLength = 128; break; - case CKM_SHA256: mLength = 256; break; - case CKM_SHA384: mLength = 384; break; - case CKM_SHA512: mLength = 512; break; - default: mLength = 0; break; + case CKM_SHA_1: + case CKM_SHA256: + mLength = 512; + break; + case CKM_SHA384: + case CKM_SHA512: + mLength = 1024; + break; + default: + mLength = 0; + break; } } diff --git a/dom/crypto/test/tests.js b/dom/crypto/test/tests.js index ac7422acd82b..8cdea6fd711a 100644 --- a/dom/crypto/test/tests.js +++ b/dom/crypto/test/tests.js @@ -332,7 +332,22 @@ TestArray.addTest( var alg = { name: "HMAC", hash: {name: "SHA-256"} }; crypto.subtle.generateKey(alg, true, ["sign", "verify"]).then( complete(that, function(x) { - return hasKeyFields(x) && x.algorithm.length == 256; + return hasKeyFields(x) && x.algorithm.length == 512; + }), + error(that) + ); + } +); + +// ----------------------------------------------------------------------------- +TestArray.addTest( + "Generate a 256-bit HMAC-SHA-512 key without specifying a key length", + function() { + var that = this; + var alg = { name: "HMAC", hash: {name: "SHA-512"} }; + crypto.subtle.generateKey(alg, true, ["sign", "verify"]).then( + complete(that, function(x) { + return hasKeyFields(x) && x.algorithm.length == 1024; }), error(that) );