[WebCrypto] Implement SubtleCrypto::DeriveKey method
authorjiewen_tan@apple.com <jiewen_tan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 9 Mar 2017 05:50:31 +0000 (05:50 +0000)
committerjiewen_tan@apple.com <jiewen_tan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 9 Mar 2017 05:50:31 +0000 (05:50 +0000)
commit24b497d0df317797a5ef7bca997b9eb7ed9e5ea3
tree19d673b86310b30aebff3a181d1f80215790430c
parent3c8eea3c488828126e028bd8566e0d3eabfde65a
[WebCrypto] Implement SubtleCrypto::DeriveKey method
https://bugs.webkit.org/show_bug.cgi?id=169386
<rdar://problem/23789585>

Reviewed by Brent Fulgham.

Source/WebCore:

This patch does following few things:
1. It implements SubtleCrypto::DeriveKey method according to the spec:
https://www.w3.org/TR/WebCryptoAPI/#SubtleCrypto-method-deriveKey.
2. It implements getKeyLength operations for AES-CBC, AES-KW, AES-CFB,
AES-GCM, and HMAC, which is needed by the SubtleCrypto::DeriveKey method.
3. It enables ECDH DeriveKey operation.
4. It replaces unigned long with size_t in all the crypto codes.

Tests: crypto/subtle/derive-key-malformed-parameters.html
       crypto/subtle/ecdh-import-key-derive-aes-key.html
       crypto/subtle/ecdh-import-key-derive-hmac-key-custom-length.html
       crypto/subtle/unwrap-key-malformed-parameters.html
       crypto/subtle/wrap-key-malformed-parameters.html
       crypto/workers/subtle/ecdh-import-key-derive-key.html

* CMakeLists.txt:
* DerivedSources.make:
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/JSSubtleCryptoCustom.cpp:
(WebCore::normalizeCryptoAlgorithmParameters):
(WebCore::jsSubtleCryptoFunctionEncryptPromise):
(WebCore::jsSubtleCryptoFunctionDecryptPromise):
(WebCore::jsSubtleCryptoFunctionSignPromise):
(WebCore::jsSubtleCryptoFunctionVerifyPromise):
(WebCore::jsSubtleCryptoFunctionDigestPromise):
(WebCore::jsSubtleCryptoFunctionDeriveKeyPromise):
(WebCore::jsSubtleCryptoFunctionDeriveBitsPromise):
Remove unnecessary return statement from callbacks.
* crypto/CryptoAlgorithm.cpp:
(WebCore::CryptoAlgorithm::deriveBits):
(WebCore::CryptoAlgorithm::getKeyLength):
* crypto/CryptoAlgorithm.h:
* crypto/CryptoAlgorithmParameters.h:
* crypto/algorithms/CryptoAlgorithmAES_CBC.cpp:
(WebCore::CryptoAlgorithmAES_CBC::generateKey):
(WebCore::CryptoAlgorithmAES_CBC::getKeyLength):
* crypto/algorithms/CryptoAlgorithmAES_CBC.h:
* crypto/algorithms/CryptoAlgorithmAES_CFB.cpp:
(WebCore::CryptoAlgorithmAES_CFB::generateKey):
(WebCore::CryptoAlgorithmAES_CFB::getKeyLength):
* crypto/algorithms/CryptoAlgorithmAES_CFB.h:
* crypto/algorithms/CryptoAlgorithmAES_GCM.cpp:
(WebCore::CryptoAlgorithmAES_GCM::generateKey):
(WebCore::CryptoAlgorithmAES_GCM::getKeyLength):
* crypto/algorithms/CryptoAlgorithmAES_GCM.h:
* crypto/algorithms/CryptoAlgorithmAES_KW.cpp:
(WebCore::CryptoAlgorithmAES_KW::generateKey):
(WebCore::CryptoAlgorithmAES_KW::getKeyLength):
* crypto/algorithms/CryptoAlgorithmAES_KW.h:
* crypto/algorithms/CryptoAlgorithmECDH.cpp:
(WebCore::CryptoAlgorithmECDH::deriveBits):
* crypto/algorithms/CryptoAlgorithmECDH.h:
* crypto/algorithms/CryptoAlgorithmHMAC.cpp:
(WebCore::CryptoAlgorithmHMAC::getKeyLength):
* crypto/algorithms/CryptoAlgorithmHMAC.h:
* crypto/keys/CryptoKeyAES.cpp:
(WebCore::CryptoKeyAES::getKeyLength):
* crypto/keys/CryptoKeyAES.h:
* crypto/keys/CryptoKeyHMAC.cpp:
(WebCore::getKeyLengthFromHash):
(WebCore::CryptoKeyHMAC::generate):
(WebCore::CryptoKeyHMAC::getKeyLength):
* crypto/keys/CryptoKeyHMAC.h:
* crypto/mac/CryptoAlgorithmECDHMac.cpp:
(WebCore::CryptoAlgorithmECDH::platformDeriveBits):
* crypto/parameters/AesKeyParams.idl: Renamed from Source/WebCore/crypto/parameters/AesKeyGenParams.idl.
* crypto/parameters/CryptoAlgorithmAesKeyParams.h: Renamed from Source/WebCore/crypto/parameters/CryptoAlgorithmAesKeyGenParams.h.
Rename AesKeyGenParams to AesKeyParams to represent a unified dictionary for AesKeyGenParams and AesDerivedKeyParams.
* crypto/parameters/CryptoAlgorithmHmacKeyParams.h:
* crypto/parameters/CryptoAlgorithmRsaKeyGenParams.h:

LayoutTests:

* crypto/subtle/aes-generate-key-malformed-parameters-expected.txt:
* crypto/subtle/derive-key-malformed-parameters-expected.txt: Added.
* crypto/subtle/derive-key-malformed-parameters.html: Added.
* crypto/subtle/deriveKey-malformed-parameters-expected.txt: Removed.
* crypto/subtle/deriveKey-malformed-parameters.html: Removed.
* crypto/subtle/ecdh-import-key-derive-aes-key-expected.txt: Added.
* crypto/subtle/ecdh-import-key-derive-aes-key.html: Added.
* crypto/subtle/ecdh-import-key-derive-hmac-key-custom-length-expected.txt: Added.
* crypto/subtle/ecdh-import-key-derive-hmac-key-custom-length.html: Added.
* crypto/subtle/unwrap-key-malformed-parameters-expected.txt: Renamed from LayoutTests/crypto/subtle/unwrapKey-malformed-parameters-expected.txt.
* crypto/subtle/unwrap-key-malformed-parameters.html: Renamed from LayoutTests/crypto/subtle/unwrapKey-malformed-parameters.html.
* crypto/subtle/wrap-key-malformed-parameters-expected.txt: Renamed from LayoutTests/crypto/subtle/wrapKey-malformed-parameters-expected.txt.
* crypto/subtle/wrap-key-malformed-parameters.html: Renamed from LayoutTests/crypto/subtle/wrapKey-malformed-parameters.html.
A bit renaming.
* crypto/workers/subtle/ecdh-import-key-derive-key-expected.txt: Added.
* crypto/workers/subtle/ecdh-import-key-derive-key.html: Added.
* crypto/workers/subtle/resources/ecdh-import-key-derive-key.js: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@213628 268f45cc-cd09-0410-ab3c-d52691b4dbfc
46 files changed:
LayoutTests/ChangeLog
LayoutTests/crypto/subtle/aes-generate-key-malformed-parameters-expected.txt
LayoutTests/crypto/subtle/derive-key-malformed-parameters-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/derive-key-malformed-parameters.html [new file with mode: 0644]
LayoutTests/crypto/subtle/deriveKey-malformed-parameters-expected.txt [deleted file]
LayoutTests/crypto/subtle/deriveKey-malformed-parameters.html [deleted file]
LayoutTests/crypto/subtle/ecdh-import-key-derive-aes-key-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdh-import-key-derive-aes-key.html [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdh-import-key-derive-hmac-key-custom-length-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdh-import-key-derive-hmac-key-custom-length.html [new file with mode: 0644]
LayoutTests/crypto/subtle/unwrap-key-malformed-parameters-expected.txt [moved from LayoutTests/crypto/subtle/unwrapKey-malformed-parameters-expected.txt with 100% similarity]
LayoutTests/crypto/subtle/unwrap-key-malformed-parameters.html [moved from LayoutTests/crypto/subtle/unwrapKey-malformed-parameters.html with 100% similarity]
LayoutTests/crypto/subtle/wrap-key-malformed-parameters-expected.txt [moved from LayoutTests/crypto/subtle/wrapKey-malformed-parameters-expected.txt with 100% similarity]
LayoutTests/crypto/subtle/wrap-key-malformed-parameters.html [moved from LayoutTests/crypto/subtle/wrapKey-malformed-parameters.html with 100% similarity]
LayoutTests/crypto/workers/subtle/ecdh-import-key-derive-key-expected.txt [new file with mode: 0644]
LayoutTests/crypto/workers/subtle/ecdh-import-key-derive-key.html [new file with mode: 0644]
LayoutTests/crypto/workers/subtle/resources/ecdh-import-key-derive-key.js [new file with mode: 0644]
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/DerivedSources.make
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/bindings/js/JSSubtleCryptoCustom.cpp
Source/WebCore/crypto/CryptoAlgorithm.cpp
Source/WebCore/crypto/CryptoAlgorithm.h
Source/WebCore/crypto/CryptoAlgorithmParameters.h
Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_CBC.cpp
Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_CBC.h
Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_CFB.cpp
Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_CFB.h
Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_GCM.cpp
Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_GCM.h
Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_KW.cpp
Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_KW.h
Source/WebCore/crypto/algorithms/CryptoAlgorithmECDH.cpp
Source/WebCore/crypto/algorithms/CryptoAlgorithmECDH.h
Source/WebCore/crypto/algorithms/CryptoAlgorithmHMAC.cpp
Source/WebCore/crypto/algorithms/CryptoAlgorithmHMAC.h
Source/WebCore/crypto/keys/CryptoKeyAES.cpp
Source/WebCore/crypto/keys/CryptoKeyAES.h
Source/WebCore/crypto/keys/CryptoKeyHMAC.cpp
Source/WebCore/crypto/keys/CryptoKeyHMAC.h
Source/WebCore/crypto/mac/CryptoAlgorithmECDHMac.cpp
Source/WebCore/crypto/parameters/AesKeyParams.idl [moved from Source/WebCore/crypto/parameters/AesKeyGenParams.idl with 83% similarity]
Source/WebCore/crypto/parameters/CryptoAlgorithmAesKeyParams.h [moved from Source/WebCore/crypto/parameters/CryptoAlgorithmAesKeyGenParams.h with 87% similarity]
Source/WebCore/crypto/parameters/CryptoAlgorithmHmacKeyParams.h
Source/WebCore/crypto/parameters/CryptoAlgorithmRsaKeyGenParams.h