Commit 9ec6e0ca authored by eroman@chromium.org's avatar eroman@chromium.org

[webcrypto] Add length parameter to HmacKeyAlgorithm. (blink)

Matches a planned change to the spec:
https://www.w3.org/Bugs/Public/show_bug.cgi?id=25094

Chromium side of this change: https://codereview.chromium.org/203303006/

BUG=245025

Review URL: https://codereview.chromium.org/204013006

git-svn-id: svn://svn.chromium.org/blink/trunk@169567 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 26fbefcc
...@@ -9,31 +9,37 @@ PASS tmpKey.type is 'secret' ...@@ -9,31 +9,37 @@ PASS tmpKey.type is 'secret'
PASS tmpKey.extractable is false PASS tmpKey.extractable is false
PASS tmpKey.algorithm.name is 'HMAC' PASS tmpKey.algorithm.name is 'HMAC'
PASS tmpKey.algorithm.hash.name is 'SHA-1' PASS tmpKey.algorithm.hash.name is 'SHA-1'
PASS tmpKey.algorithm.length is 0
PASS tmpKey.usages.join(',') is 'sign,verify' PASS tmpKey.usages.join(',') is 'sign,verify'
PASS tmpKey.type is 'secret' PASS tmpKey.type is 'secret'
PASS tmpKey.extractable is false PASS tmpKey.extractable is false
PASS tmpKey.algorithm.name is 'HMAC' PASS tmpKey.algorithm.name is 'HMAC'
PASS tmpKey.algorithm.hash.name is 'SHA-256' PASS tmpKey.algorithm.hash.name is 'SHA-256'
PASS tmpKey.algorithm.length is 0
PASS tmpKey.usages.join(',') is 'sign,verify' PASS tmpKey.usages.join(',') is 'sign,verify'
PASS tmpKey.type is 'secret' PASS tmpKey.type is 'secret'
PASS tmpKey.extractable is false PASS tmpKey.extractable is false
PASS tmpKey.algorithm.name is 'HMAC' PASS tmpKey.algorithm.name is 'HMAC'
PASS tmpKey.algorithm.hash.name is 'SHA-1' PASS tmpKey.algorithm.hash.name is 'SHA-1'
PASS tmpKey.algorithm.length is 80
PASS tmpKey.usages.join(',') is 'sign,verify' PASS tmpKey.usages.join(',') is 'sign,verify'
PASS tmpKey.type is 'secret' PASS tmpKey.type is 'secret'
PASS tmpKey.extractable is false PASS tmpKey.extractable is false
PASS tmpKey.algorithm.name is 'HMAC' PASS tmpKey.algorithm.name is 'HMAC'
PASS tmpKey.algorithm.hash.name is 'SHA-1' PASS tmpKey.algorithm.hash.name is 'SHA-1'
PASS tmpKey.algorithm.length is 640
PASS tmpKey.usages.join(',') is 'sign,verify' PASS tmpKey.usages.join(',') is 'sign,verify'
PASS tmpKey.type is 'secret' PASS tmpKey.type is 'secret'
PASS tmpKey.extractable is false PASS tmpKey.extractable is false
PASS tmpKey.algorithm.name is 'HMAC' PASS tmpKey.algorithm.name is 'HMAC'
PASS tmpKey.algorithm.hash.name is 'SHA-256' PASS tmpKey.algorithm.hash.name is 'SHA-256'
PASS tmpKey.algorithm.length is 320
PASS tmpKey.usages.join(',') is 'sign,verify' PASS tmpKey.usages.join(',') is 'sign,verify'
PASS tmpKey.type is 'secret' PASS tmpKey.type is 'secret'
PASS tmpKey.extractable is false PASS tmpKey.extractable is false
PASS tmpKey.algorithm.name is 'HMAC' PASS tmpKey.algorithm.name is 'HMAC'
PASS tmpKey.algorithm.hash.name is 'SHA-256' PASS tmpKey.algorithm.hash.name is 'SHA-256'
PASS tmpKey.algorithm.length is 592
PASS tmpKey.usages.join(',') is 'sign,verify' PASS tmpKey.usages.join(',') is 'sign,verify'
PASS: Mac should be [fbdb1d1b18aa6c08324b7d64b71fb76370690e1d] and was PASS: Mac should be [fbdb1d1b18aa6c08324b7d64b71fb76370690e1d] and was
PASS: Mac should be [b613679a0814d9ec772f95d778c35fc5ff1697c493715653c6c712144292c5ad] and was PASS: Mac should be [b613679a0814d9ec772f95d778c35fc5ff1697c493715653c6c712144292c5ad] and was
......
...@@ -94,6 +94,7 @@ function runSuccessTestCase(testCase) ...@@ -94,6 +94,7 @@ function runSuccessTestCase(testCase)
shouldBe("tmpKey.extractable", "false") shouldBe("tmpKey.extractable", "false")
shouldBe("tmpKey.algorithm.name", "'HMAC'") shouldBe("tmpKey.algorithm.name", "'HMAC'")
shouldBe("tmpKey.algorithm.hash.name", "'" + testCase.algorithm + "'") shouldBe("tmpKey.algorithm.hash.name", "'" + testCase.algorithm + "'")
shouldEvaluateTo("tmpKey.algorithm.length", keyData.length * 8);
shouldBe("tmpKey.usages.join(',')", "'sign,verify'") shouldBe("tmpKey.usages.join(',')", "'sign,verify'")
// (2) Sign. // (2) Sign.
......
...@@ -48,6 +48,11 @@ KeyAlgorithm* HmacKeyAlgorithm::hash() ...@@ -48,6 +48,11 @@ KeyAlgorithm* HmacKeyAlgorithm::hash()
return m_hash.get(); return m_hash.get();
} }
unsigned HmacKeyAlgorithm::length()
{
return m_algorithm.hmacParams()->lengthBits();
}
void HmacKeyAlgorithm::trace(Visitor* visitor) void HmacKeyAlgorithm::trace(Visitor* visitor)
{ {
KeyAlgorithm::trace(visitor); KeyAlgorithm::trace(visitor);
......
...@@ -40,6 +40,7 @@ public: ...@@ -40,6 +40,7 @@ public:
static PassRefPtrWillBeRawPtr<HmacKeyAlgorithm> create(const blink::WebCryptoKeyAlgorithm&); static PassRefPtrWillBeRawPtr<HmacKeyAlgorithm> create(const blink::WebCryptoKeyAlgorithm&);
KeyAlgorithm* hash(); KeyAlgorithm* hash();
unsigned length();
virtual void trace(Visitor*) OVERRIDE; virtual void trace(Visitor*) OVERRIDE;
......
...@@ -32,4 +32,5 @@ ...@@ -32,4 +32,5 @@
NoInterfaceObject NoInterfaceObject
] interface HmacKeyAlgorithm : KeyAlgorithm { ] interface HmacKeyAlgorithm : KeyAlgorithm {
readonly attribute KeyAlgorithm hash; readonly attribute KeyAlgorithm hash;
readonly attribute unsigned long length;
}; };
...@@ -35,6 +35,9 @@ ...@@ -35,6 +35,9 @@
#include "WebCryptoAlgorithm.h" #include "WebCryptoAlgorithm.h"
#include "WebVector.h" #include "WebVector.h"
// FIXME: Delete this once the chromium side has picked up the API change.
#define WEBCRYPTO_HMAC_KEY_HAS_LENGTH 1
namespace blink { namespace blink {
enum WebCryptoKeyAlgorithmParamsType { enum WebCryptoKeyAlgorithmParamsType {
...@@ -77,8 +80,9 @@ private: ...@@ -77,8 +80,9 @@ private:
class WebCryptoHmacKeyAlgorithmParams : public WebCryptoKeyAlgorithmParams { class WebCryptoHmacKeyAlgorithmParams : public WebCryptoKeyAlgorithmParams {
public: public:
explicit WebCryptoHmacKeyAlgorithmParams(const WebCryptoAlgorithm& hash) WebCryptoHmacKeyAlgorithmParams(const WebCryptoAlgorithm& hash, unsigned lengthBits)
: m_hash(hash) : m_hash(hash)
, m_lengthBits(lengthBits)
{ {
} }
...@@ -87,6 +91,11 @@ public: ...@@ -87,6 +91,11 @@ public:
return m_hash; return m_hash;
} }
unsigned lengthBits() const
{
return m_lengthBits;
}
virtual WebCryptoKeyAlgorithmParamsType type() const virtual WebCryptoKeyAlgorithmParamsType type() const
{ {
return WebCryptoKeyAlgorithmParamsTypeHmac; return WebCryptoKeyAlgorithmParamsTypeHmac;
...@@ -94,6 +103,7 @@ public: ...@@ -94,6 +103,7 @@ public:
private: private:
WebCryptoAlgorithm m_hash; WebCryptoAlgorithm m_hash;
unsigned m_lengthBits;
}; };
class WebCryptoRsaKeyAlgorithmParams : public WebCryptoKeyAlgorithmParams { class WebCryptoRsaKeyAlgorithmParams : public WebCryptoKeyAlgorithmParams {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment