[WebCrypto] Add support for ECDSA
authorjiewen_tan@apple.com <jiewen_tan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 17 Apr 2017 20:07:56 +0000 (20:07 +0000)
committerjiewen_tan@apple.com <jiewen_tan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 17 Apr 2017 20:07:56 +0000 (20:07 +0000)
commitf2e3842a276c616ce5f87d525523b20ca29bdc6f
tree57149392c5bbebcb8c0f144b2930ceb2ac24877b
parent64f0b40acea267671b95ab1447176b66524cbe4b
[WebCrypto] Add support for ECDSA
https://bugs.webkit.org/show_bug.cgi?id=170789
<rdar://problem/31588604>

Reviewed by Brent Fulgham.

LayoutTests/imported/w3c:

* web-platform-tests/WebCryptoAPI/generateKey/failures_ECDSA.worker-expected.txt:
* web-platform-tests/WebCryptoAPI/generateKey/successes_ECDSA.worker-expected.txt:
* web-platform-tests/WebCryptoAPI/generateKey/test_failures_ECDSA-expected.txt:
* web-platform-tests/WebCryptoAPI/generateKey/test_successes_ECDSA-expected.txt:
* web-platform-tests/WebCryptoAPI/import_export/ec_importKey.worker-expected.txt:
* web-platform-tests/WebCryptoAPI/import_export/test_ec_importKey-expected.txt:
* web-platform-tests/WebCryptoAPI/sign_verify/ecdsa.worker-expected.txt:
* web-platform-tests/WebCryptoAPI/sign_verify/hmac.worker-expected.txt:
* web-platform-tests/WebCryptoAPI/sign_verify/test_ecdsa-expected.txt:
* web-platform-tests/WebCryptoAPI/sign_verify/test_hmac-expected.txt:

Source/WebCore:

This patch implements ECDSA according to the spec: https://www.w3.org/TR/WebCryptoAPI/#ecdsa.
Supported operations include sign, verify, generateKey, importKey and exportKey.

Tests: crypto/subtle/ecdh-generate-export-key-pkcs8-p256.html
       crypto/subtle/ecdh-generate-export-key-pkcs8-p384.html
       crypto/subtle/ecdsa-generate-export-jwk-key.html
       crypto/subtle/ecdsa-generate-export-key-pkcs8.html
       crypto/subtle/ecdsa-generate-export-key-raw.html
       crypto/subtle/ecdsa-generate-export-key-spki.html
       crypto/subtle/ecdsa-generate-key-sign-verify-p256.html
       crypto/subtle/ecdsa-generate-key-sign-verify-p384.html
       crypto/subtle/ecdsa-generate-key.html
       crypto/subtle/ecdsa-import-jwk-private-key.html
       crypto/subtle/ecdsa-import-jwk-public-key-alg-256.html
       crypto/subtle/ecdsa-import-jwk-public-key-alg-384.html
       crypto/subtle/ecdsa-import-jwk-public-key.html
       crypto/subtle/ecdsa-import-key-sign-p256.html
       crypto/subtle/ecdsa-import-key-sign-p384.html
       crypto/subtle/ecdsa-import-key-verify-p256.html
       crypto/subtle/ecdsa-import-key-verify-p384.html
       crypto/subtle/ecdsa-import-pkcs8-key.html
       crypto/subtle/ecdsa-import-raw-key.html
       crypto/subtle/ecdsa-import-spki-key.html
       crypto/subtle/ecdsa-verify-malformed-parameters.html
       crypto/workers/subtle/ecdsa-import-key-sign.html
       crypto/workers/subtle/ecdsa-import-key-verify.html

* CMakeLists.txt:
* DerivedSources.make:
* PlatformGTK.cmake:
* PlatformMac.cmake:
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/JSSubtleCryptoCustom.cpp:
(WebCore::normalizeCryptoAlgorithmParameters):
(WebCore::jsSubtleCryptoFunctionSignPromise):
(WebCore::jsSubtleCryptoFunctionVerifyPromise):
Add missing parameters.
* crypto/CommonCryptoUtilities.h:
* crypto/CryptoAlgorithm.cpp:
(WebCore::CryptoAlgorithm::sign):
(WebCore::CryptoAlgorithm::verify):
* crypto/CryptoAlgorithm.h:
Add missing parameters.
* crypto/CryptoAlgorithmParameters.h:
* crypto/algorithms/CryptoAlgorithmECDSA.cpp: Added.
(WebCore::CryptoAlgorithmECDSA::create):
(WebCore::CryptoAlgorithmECDSA::identifier):
(WebCore::CryptoAlgorithmECDSA::sign):
(WebCore::CryptoAlgorithmECDSA::verify):
(WebCore::CryptoAlgorithmECDSA::generateKey):
(WebCore::CryptoAlgorithmECDSA::importKey):
(WebCore::CryptoAlgorithmECDSA::exportKey):
* crypto/algorithms/CryptoAlgorithmECDSA.h: Added.
* crypto/algorithms/CryptoAlgorithmHMAC.cpp:
(WebCore::CryptoAlgorithmHMAC::sign):
(WebCore::CryptoAlgorithmHMAC::verify):
* crypto/algorithms/CryptoAlgorithmHMAC.h:
Add missing parameters.
* crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp:
(WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::sign):
(WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::verify):
* crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.h:
Add missing parameters.
* crypto/gcrypt/CryptoAlgorithmECDSAGCrypt.cpp: Added.
(WebCore::CryptoAlgorithmECDSA::platformSign):
(WebCore::CryptoAlgorithmECDSA::platformVerify):
* crypto/mac/CommonCryptoDERUtilities.cpp: Added.
(WebCore::bytesUsedToEncodedLength):
(WebCore::extraBytesNeededForEncodedLength):
(WebCore::addEncodedASN1Length):
(WebCore::bytesNeededForEncodedLength):
* crypto/mac/CommonCryptoDERUtilities.h:
(WebCore::bytesUsedToEncodedLength): Deleted.
(WebCore::extraBytesNeededForEncodedLength): Deleted.
(WebCore::addEncodedASN1Length): Deleted.
(WebCore::bytesNeededForEncodedLength): Deleted.
Move implementations to a .cpp file.
* crypto/mac/CryptoAlgorithmECDSAMac.cpp: Added.
(WebCore::cryptoDigestAlgorithm):
(WebCore::signECDSA):
(WebCore::verifyECDSA):
(WebCore::CryptoAlgorithmECDSA::platformSign):
(WebCore::CryptoAlgorithmECDSA::platformVerify):
* crypto/mac/CryptoAlgorithmRegistryMac.cpp:
(WebCore::CryptoAlgorithmRegistry::platformRegisterAlgorithms):
* crypto/parameters/CryptoAlgorithmEcdsaParams.h: Added.
* crypto/parameters/EcdsaParams.idl: Added.

LayoutTests:

* crypto/subtle/ec-generate-key-malformed-parameters-expected.txt:
* crypto/subtle/ec-generate-key-malformed-parameters.html:
* crypto/subtle/ec-import-key-malformed-parameters-expected.txt:
* crypto/subtle/ec-import-key-malformed-parameters.html:
* crypto/subtle/ecdh-generate-export-key-pkcs8-p256-expected.txt: Renamed from LayoutTests/crypto/subtle/ecdh-generate-export-pkcs8-p256-expected.txt.
* crypto/subtle/ecdh-generate-export-key-pkcs8-p256.html: Renamed from LayoutTests/crypto/subtle/ecdh-generate-export-pkcs8-p256.html.
* crypto/subtle/ecdh-generate-export-key-pkcs8-p384-expected.txt: Renamed from LayoutTests/crypto/subtle/ecdh-generate-export-pkcs8-p384-expected.txt.
* crypto/subtle/ecdh-generate-export-key-pkcs8-p384.html: Renamed from LayoutTests/crypto/subtle/ecdh-generate-export-pkcs8-p384.html.
* crypto/subtle/ecdsa-generate-export-jwk-key-expected.txt: Added.
* crypto/subtle/ecdsa-generate-export-jwk-key.html: Added.
* crypto/subtle/ecdsa-generate-export-key-pkcs8-expected.txt: Added.
* crypto/subtle/ecdsa-generate-export-key-pkcs8.html: Added.
* crypto/subtle/ecdsa-generate-export-key-raw-expected.txt: Added.
* crypto/subtle/ecdsa-generate-export-key-raw.html: Added.
* crypto/subtle/ecdsa-generate-export-key-spki-expected.txt: Added.
* crypto/subtle/ecdsa-generate-export-key-spki.html: Added.
* crypto/subtle/ecdsa-generate-key-expected.txt: Added.
* crypto/subtle/ecdsa-generate-key-sign-verify-p256-expected.txt: Added.
* crypto/subtle/ecdsa-generate-key-sign-verify-p256.html: Added.
* crypto/subtle/ecdsa-generate-key-sign-verify-p384-expected.txt: Added.
* crypto/subtle/ecdsa-generate-key-sign-verify-p384.html: Added.
* crypto/subtle/ecdsa-generate-key.html: Added.
* crypto/subtle/ecdsa-import-jwk-private-key-expected.txt: Added.
* crypto/subtle/ecdsa-import-jwk-private-key.html: Added.
* crypto/subtle/ecdsa-import-jwk-public-key-alg-256-expected.txt: Added.
* crypto/subtle/ecdsa-import-jwk-public-key-alg-256.html: Added.
* crypto/subtle/ecdsa-import-jwk-public-key-alg-384-expected.txt: Added.
* crypto/subtle/ecdsa-import-jwk-public-key-alg-384.html: Added.
* crypto/subtle/ecdsa-import-jwk-public-key-expected.txt: Added.
* crypto/subtle/ecdsa-import-jwk-public-key.html: Added.
* crypto/subtle/ecdsa-import-key-sign-p256-expected.txt: Added.
* crypto/subtle/ecdsa-import-key-sign-p256.html: Added.
* crypto/subtle/ecdsa-import-key-sign-p384-expected.txt: Added.
* crypto/subtle/ecdsa-import-key-sign-p384.html: Added.
* crypto/subtle/ecdsa-import-key-verify-p256-expected.txt: Added.
* crypto/subtle/ecdsa-import-key-verify-p256.html: Added.
* crypto/subtle/ecdsa-import-key-verify-p384-expected.txt: Added.
* crypto/subtle/ecdsa-import-key-verify-p384.html: Added.
* crypto/subtle/ecdsa-import-pkcs8-key-expected.txt: Added.
* crypto/subtle/ecdsa-import-pkcs8-key.html: Added.
* crypto/subtle/ecdsa-import-raw-key-expected.txt: Added.
* crypto/subtle/ecdsa-import-raw-key.html: Added.
* crypto/subtle/ecdsa-import-spki-key-expected.txt: Added.
* crypto/subtle/ecdsa-import-spki-key.html: Added.
* crypto/subtle/ecdsa-verify-malformed-parameters-expected.txt: Added.
* crypto/subtle/ecdsa-verify-malformed-parameters.html: Added.
* crypto/workers/subtle/ecdsa-import-key-sign-expected.txt: Added.
* crypto/workers/subtle/ecdsa-import-key-sign.html: Added.
* crypto/workers/subtle/ecdsa-import-key-verify-expected.txt: Added.
* crypto/workers/subtle/ecdsa-import-key-verify.html: Added.
* crypto/workers/subtle/resources/ecdsa-import-key-sign.js: Added.
* crypto/workers/subtle/resources/ecdsa-import-key-verify.js: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@215423 268f45cc-cd09-0410-ab3c-d52691b4dbfc
88 files changed:
LayoutTests/ChangeLog
LayoutTests/crypto/subtle/ec-generate-key-malformed-parameters-expected.txt
LayoutTests/crypto/subtle/ec-generate-key-malformed-parameters.html
LayoutTests/crypto/subtle/ec-import-key-malformed-parameters-expected.txt
LayoutTests/crypto/subtle/ec-import-key-malformed-parameters.html
LayoutTests/crypto/subtle/ecdh-generate-export-key-pkcs8-p256-expected.txt [moved from LayoutTests/crypto/subtle/ecdh-generate-export-pkcs8-p256-expected.txt with 100% similarity]
LayoutTests/crypto/subtle/ecdh-generate-export-key-pkcs8-p256.html [moved from LayoutTests/crypto/subtle/ecdh-generate-export-pkcs8-p256.html with 100% similarity]
LayoutTests/crypto/subtle/ecdh-generate-export-key-pkcs8-p384-expected.txt [moved from LayoutTests/crypto/subtle/ecdh-generate-export-pkcs8-p384-expected.txt with 100% similarity]
LayoutTests/crypto/subtle/ecdh-generate-export-key-pkcs8-p384.html [moved from LayoutTests/crypto/subtle/ecdh-generate-export-pkcs8-p384.html with 100% similarity]
LayoutTests/crypto/subtle/ecdsa-generate-export-jwk-key-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdsa-generate-export-jwk-key.html [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdsa-generate-export-key-pkcs8-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdsa-generate-export-key-pkcs8.html [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdsa-generate-export-key-raw-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdsa-generate-export-key-raw.html [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdsa-generate-export-key-spki-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdsa-generate-export-key-spki.html [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdsa-generate-key-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdsa-generate-key-sign-verify-p256-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdsa-generate-key-sign-verify-p256.html [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdsa-generate-key-sign-verify-p384-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdsa-generate-key-sign-verify-p384.html [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdsa-generate-key.html [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdsa-import-jwk-private-key-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdsa-import-jwk-private-key.html [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdsa-import-jwk-public-key-alg-256-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdsa-import-jwk-public-key-alg-256.html [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdsa-import-jwk-public-key-alg-384-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdsa-import-jwk-public-key-alg-384.html [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdsa-import-jwk-public-key-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdsa-import-jwk-public-key.html [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdsa-import-key-sign-p256-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdsa-import-key-sign-p256.html [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdsa-import-key-sign-p384-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdsa-import-key-sign-p384.html [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdsa-import-key-verify-p256-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdsa-import-key-verify-p256.html [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdsa-import-key-verify-p384-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdsa-import-key-verify-p384.html [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdsa-import-pkcs8-key-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdsa-import-pkcs8-key.html [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdsa-import-raw-key-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdsa-import-raw-key.html [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdsa-import-spki-key-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdsa-import-spki-key.html [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdsa-verify-malformed-parameters-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/ecdsa-verify-malformed-parameters.html [new file with mode: 0644]
LayoutTests/crypto/workers/subtle/ecdsa-import-key-sign-expected.txt [new file with mode: 0644]
LayoutTests/crypto/workers/subtle/ecdsa-import-key-sign.html [new file with mode: 0644]
LayoutTests/crypto/workers/subtle/ecdsa-import-key-verify-expected.txt [new file with mode: 0644]
LayoutTests/crypto/workers/subtle/ecdsa-import-key-verify.html [new file with mode: 0644]
LayoutTests/crypto/workers/subtle/resources/ecdsa-import-key-sign.js [new file with mode: 0644]
LayoutTests/crypto/workers/subtle/resources/ecdsa-import-key-verify.js [new file with mode: 0644]
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/WebCryptoAPI/generateKey/failures_ECDSA.worker-expected.txt
LayoutTests/imported/w3c/web-platform-tests/WebCryptoAPI/generateKey/successes_ECDSA.worker-expected.txt
LayoutTests/imported/w3c/web-platform-tests/WebCryptoAPI/generateKey/test_failures_ECDSA-expected.txt
LayoutTests/imported/w3c/web-platform-tests/WebCryptoAPI/generateKey/test_successes_ECDSA-expected.txt
LayoutTests/imported/w3c/web-platform-tests/WebCryptoAPI/import_export/ec_importKey.worker-expected.txt
LayoutTests/imported/w3c/web-platform-tests/WebCryptoAPI/import_export/test_ec_importKey-expected.txt
LayoutTests/imported/w3c/web-platform-tests/WebCryptoAPI/sign_verify/ecdsa.worker-expected.txt
LayoutTests/imported/w3c/web-platform-tests/WebCryptoAPI/sign_verify/hmac.worker-expected.txt
LayoutTests/imported/w3c/web-platform-tests/WebCryptoAPI/sign_verify/test_ecdsa-expected.txt
LayoutTests/imported/w3c/web-platform-tests/WebCryptoAPI/sign_verify/test_hmac-expected.txt
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/DerivedSources.make
Source/WebCore/PlatformGTK.cmake
Source/WebCore/PlatformMac.cmake
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/bindings/js/JSSubtleCryptoCustom.cpp
Source/WebCore/crypto/CommonCryptoUtilities.h
Source/WebCore/crypto/CryptoAlgorithm.cpp
Source/WebCore/crypto/CryptoAlgorithm.h
Source/WebCore/crypto/CryptoAlgorithmParameters.h
Source/WebCore/crypto/algorithms/CryptoAlgorithmECDSA.cpp [new file with mode: 0644]
Source/WebCore/crypto/algorithms/CryptoAlgorithmECDSA.h [new file with mode: 0644]
Source/WebCore/crypto/algorithms/CryptoAlgorithmHMAC.cpp
Source/WebCore/crypto/algorithms/CryptoAlgorithmHMAC.h
Source/WebCore/crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp
Source/WebCore/crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.h
Source/WebCore/crypto/gcrypt/CryptoAlgorithmECDSAGCrypt.cpp [new file with mode: 0644]
Source/WebCore/crypto/mac/CommonCryptoDERUtilities.cpp [new file with mode: 0644]
Source/WebCore/crypto/mac/CommonCryptoDERUtilities.h
Source/WebCore/crypto/mac/CryptoAlgorithmECDSAMac.cpp [new file with mode: 0644]
Source/WebCore/crypto/mac/CryptoAlgorithmRegistryMac.cpp
Source/WebCore/crypto/parameters/CryptoAlgorithmEcdsaParams.h [new file with mode: 0644]
Source/WebCore/crypto/parameters/EcdsaParams.idl [new file with mode: 0644]