[WebCrypto] Add support for AES-CTR
authorjiewen_tan@apple.com <jiewen_tan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 6 Apr 2017 18:56:33 +0000 (18:56 +0000)
committerjiewen_tan@apple.com <jiewen_tan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 6 Apr 2017 18:56:33 +0000 (18:56 +0000)
commitb365b7590c18924da61b2c7bbb5769eb182fbeaa
treeb2cb2ac398439e9e467e06f8459878b298de6e95
parent58ac786dff87cc9f9fb581b54e853d02aeda2202
[WebCrypto] Add support for AES-CTR
https://bugs.webkit.org/show_bug.cgi?id=169761
<rdar://problem/31331321>

Reviewed by Brent Fulgham.

LayoutTests/imported/w3c:

* web-platform-tests/WebCryptoAPI/derive_bits_keys/pbkdf2.worker-expected.txt:
* web-platform-tests/WebCryptoAPI/derive_bits_keys/test_pbkdf2-expected.txt:
* web-platform-tests/WebCryptoAPI/encrypt_decrypt/aes_cbc.worker-expected.txt:
* web-platform-tests/WebCryptoAPI/encrypt_decrypt/aes_ctr.worker-expected.txt:
* web-platform-tests/WebCryptoAPI/encrypt_decrypt/test_aes_cbc-expected.txt:
* web-platform-tests/WebCryptoAPI/encrypt_decrypt/test_aes_ctr-expected.txt:
* web-platform-tests/WebCryptoAPI/generateKey/failures_AES-CTR.worker-expected.txt:
* web-platform-tests/WebCryptoAPI/generateKey/successes_AES-CTR.worker-expected.txt:
* web-platform-tests/WebCryptoAPI/generateKey/test_aes-ctr-expected.txt:
* web-platform-tests/WebCryptoAPI/generateKey/test_failures_AES-CTR-expected.txt:
* web-platform-tests/WebCryptoAPI/generateKey/test_successes_AES-CTR-expected.txt:
* web-platform-tests/WebCryptoAPI/import_export/symmetric_importKey.worker-expected.txt:
* web-platform-tests/WebCryptoAPI/import_export/test_symmetric_importKey-expected.txt:

Source/WebCore:

This patch adds support for AES-CTR. Operations of AES-CTR include: encrypt, decrypt, generateKey,
importKey, exportKey, wrapKey, and unwrapKey. This implementation follows the latest WebCryptoAPI
spec: https://www.w3.org/TR/WebCryptoAPI/#aes-ctr.

Tests: crypto/subtle/aes-ctr-encrypt-malformed-parameters.html
       crypto/subtle/aes-ctr-encrypt-overflow.html
       crypto/subtle/aes-ctr-generate-export-key-jwk-length-128.html
       crypto/subtle/aes-ctr-generate-export-key-jwk-length-192.html
       crypto/subtle/aes-ctr-generate-export-key-jwk-length-256.html
       crypto/subtle/aes-ctr-generate-export-raw-key.html
       crypto/subtle/aes-ctr-generate-key-encrypt-decrypt.html
       crypto/subtle/aes-ctr-generate-key.html
       crypto/subtle/aes-ctr-import-jwk-key-length-128.html
       crypto/subtle/aes-ctr-import-jwk-key-length-192.html
       crypto/subtle/aes-ctr-import-jwk-key-length-256.html
       crypto/subtle/aes-ctr-import-key-decrypt.html
       crypto/subtle/aes-ctr-import-key-encrypt.html
       crypto/subtle/aes-ctr-import-key-unwrap-jwk-key.html
       crypto/subtle/aes-ctr-import-key-unwrap-raw-key.html
       crypto/subtle/aes-ctr-import-key-wrap-jwk-key.html
       crypto/subtle/aes-ctr-import-key-wrap-raw-key.html
       crypto/subtle/aes-ctr-import-raw-key.html
       crypto/workers/subtle/aes-ctr-import-key-decrypt.html
       crypto/workers/subtle/aes-ctr-import-key-encrypt.html
       crypto/workers/subtle/aes-ctr-import-key-unwrap-key.html
       crypto/workers/subtle/aes-ctr-import-key-wrap-key.html

* CMakeLists.txt:
* DerivedSources.make:
* PlatformGTK.cmake:
* PlatformMac.cmake:
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/JSSubtleCryptoCustom.cpp:
(WebCore::normalizeCryptoAlgorithmParameters):
* crypto/CryptoAlgorithmParameters.h:
* crypto/algorithms/CryptoAlgorithmAES_CTR.cpp: Added.
(WebCore::usagesAreInvalidForCryptoAlgorithmAES_CTR):
(WebCore::parametersAreValid):
(WebCore::CryptoAlgorithmAES_CTR::create):
(WebCore::CryptoAlgorithmAES_CTR::identifier):
(WebCore::CryptoAlgorithmAES_CTR::encrypt):
(WebCore::CryptoAlgorithmAES_CTR::decrypt):
(WebCore::CryptoAlgorithmAES_CTR::generateKey):
(WebCore::CryptoAlgorithmAES_CTR::importKey):
(WebCore::CryptoAlgorithmAES_CTR::exportKey):
(WebCore::CryptoAlgorithmAES_CTR::getKeyLength):
* crypto/algorithms/CryptoAlgorithmAES_CTR.h: Added.
* crypto/gcrypt/CryptoAlgorithmAES_CTRGCrypt.cpp: Added.
(WebCore::CryptoAlgorithmAES_CTR::platformEncrypt):
(WebCore::CryptoAlgorithmAES_CTR::platformDecrypt):
* crypto/mac/CryptoAlgorithmAES_CTRMac.cpp: Added.
(WebCore::bigIntegerToSize):
(WebCore::transformAES_CTR):
(WebCore::CryptoAlgorithmAES_CTR::platformEncrypt):
(WebCore::CryptoAlgorithmAES_CTR::platformDecrypt):
* crypto/mac/CryptoAlgorithmRegistryMac.cpp:
(WebCore::CryptoAlgorithmRegistry::platformRegisterAlgorithms):
* crypto/parameters/AesCtrParams.idl: Added.
* crypto/parameters/CryptoAlgorithmAesCtrParams.h: Added.

LayoutTests:

* crypto/subtle/aes-ctr-encrypt-malformed-parameters-expected.txt: Added.
* crypto/subtle/aes-ctr-encrypt-malformed-parameters.html: Added.
* crypto/subtle/aes-ctr-generate-export-key-jwk-length-128-expected.txt: Added.
* crypto/subtle/aes-ctr-generate-export-key-jwk-length-128.html: Added.
* crypto/subtle/aes-ctr-generate-export-key-jwk-length-192-expected.txt: Added.
* crypto/subtle/aes-ctr-generate-export-key-jwk-length-192.html: Added.
* crypto/subtle/aes-ctr-generate-export-key-jwk-length-256-expected.txt: Added.
* crypto/subtle/aes-ctr-generate-export-key-jwk-length-256.html: Added.
* crypto/subtle/aes-ctr-generate-export-raw-key-expected.txt: Added.
* crypto/subtle/aes-ctr-generate-export-raw-key.html: Added.
* crypto/subtle/aes-ctr-generate-key-encrypt-decrypt-expected.txt: Added.
* crypto/subtle/aes-ctr-generate-key-encrypt-decrypt.html: Added.
* crypto/subtle/aes-ctr-generate-key-expected.txt: Added.
* crypto/subtle/aes-ctr-generate-key.html: Added.
* crypto/subtle/aes-ctr-import-jwk-key-length-128-expected.txt: Added.
* crypto/subtle/aes-ctr-import-jwk-key-length-128.html: Added.
* crypto/subtle/aes-ctr-import-jwk-key-length-192-expected.txt: Added.
* crypto/subtle/aes-ctr-import-jwk-key-length-192.html: Added.
* crypto/subtle/aes-ctr-import-jwk-key-length-256-expected.txt: Added.
* crypto/subtle/aes-ctr-import-jwk-key-length-256.html: Added.
* crypto/subtle/aes-ctr-import-key-decrypt-expected.txt: Added.
* crypto/subtle/aes-ctr-import-key-decrypt.html: Added.
* crypto/subtle/aes-ctr-import-key-encrypt-expected.txt: Added.
* crypto/subtle/aes-ctr-import-key-encrypt.html: Added.
* crypto/subtle/aes-ctr-import-key-unwrap-jwk-key-expected.txt: Added.
* crypto/subtle/aes-ctr-import-key-unwrap-jwk-key.html: Added.
* crypto/subtle/aes-ctr-import-key-unwrap-raw-key-expected.txt: Added.
* crypto/subtle/aes-ctr-import-key-unwrap-raw-key.html: Added.
* crypto/subtle/aes-ctr-import-key-wrap-jwk-key-expected.txt: Added.
* crypto/subtle/aes-ctr-import-key-wrap-jwk-key.html: Added.
* crypto/subtle/aes-ctr-import-key-wrap-raw-key-expected.txt: Added.
* crypto/subtle/aes-ctr-import-key-wrap-raw-key.html: Added.
* crypto/subtle/aes-ctr-import-raw-key-expected.txt: Added.
* crypto/subtle/aes-ctr-import-raw-key.html: Added.
* crypto/subtle/aes-generate-key-malformed-parameters-expected.txt:
* crypto/subtle/aes-generate-key-malformed-parameters.html:
* crypto/subtle/aes-import-key-malformed-parameters-expected.txt:
* crypto/subtle/aes-import-key-malformed-parameters.html:
* crypto/workers/subtle/aes-ctr-import-key-decrypt-expected.txt: Added.
* crypto/workers/subtle/aes-ctr-import-key-decrypt.html: Added.
* crypto/workers/subtle/aes-ctr-import-key-encrypt-expected.txt: Added.
* crypto/workers/subtle/aes-ctr-import-key-encrypt.html: Added.
* crypto/workers/subtle/aes-ctr-import-key-unwrap-key-expected.txt: Added.
* crypto/workers/subtle/aes-ctr-import-key-unwrap-key.html: Added.
* crypto/workers/subtle/aes-ctr-import-key-wrap-key-expected.txt: Added.
* crypto/workers/subtle/aes-ctr-import-key-wrap-key.html: Added.
* crypto/workers/subtle/resources/aes-ctr-import-key-decrypt.js: Added.
* crypto/workers/subtle/resources/aes-ctr-import-key-encrypt.js: Added.
* crypto/workers/subtle/resources/aes-ctr-import-key-unwrap-key.js: Added.
* crypto/workers/subtle/resources/aes-ctr-import-key-wrap-key.js: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@215051 268f45cc-cd09-0410-ab3c-d52691b4dbfc
80 files changed:
LayoutTests/ChangeLog
LayoutTests/crypto/subtle/aes-ctr-encrypt-malformed-parameters-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/aes-ctr-encrypt-malformed-parameters.html [new file with mode: 0644]
LayoutTests/crypto/subtle/aes-ctr-generate-export-key-jwk-length-128-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/aes-ctr-generate-export-key-jwk-length-128.html [new file with mode: 0644]
LayoutTests/crypto/subtle/aes-ctr-generate-export-key-jwk-length-192-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/aes-ctr-generate-export-key-jwk-length-192.html [new file with mode: 0644]
LayoutTests/crypto/subtle/aes-ctr-generate-export-key-jwk-length-256-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/aes-ctr-generate-export-key-jwk-length-256.html [new file with mode: 0644]
LayoutTests/crypto/subtle/aes-ctr-generate-export-raw-key-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/aes-ctr-generate-export-raw-key.html [new file with mode: 0644]
LayoutTests/crypto/subtle/aes-ctr-generate-key-encrypt-decrypt-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/aes-ctr-generate-key-encrypt-decrypt.html [new file with mode: 0644]
LayoutTests/crypto/subtle/aes-ctr-generate-key-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/aes-ctr-generate-key.html [new file with mode: 0644]
LayoutTests/crypto/subtle/aes-ctr-import-jwk-key-length-128-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/aes-ctr-import-jwk-key-length-128.html [new file with mode: 0644]
LayoutTests/crypto/subtle/aes-ctr-import-jwk-key-length-192-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/aes-ctr-import-jwk-key-length-192.html [new file with mode: 0644]
LayoutTests/crypto/subtle/aes-ctr-import-jwk-key-length-256-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/aes-ctr-import-jwk-key-length-256.html [new file with mode: 0644]
LayoutTests/crypto/subtle/aes-ctr-import-key-decrypt-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/aes-ctr-import-key-decrypt.html [new file with mode: 0644]
LayoutTests/crypto/subtle/aes-ctr-import-key-encrypt-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/aes-ctr-import-key-encrypt.html [new file with mode: 0644]
LayoutTests/crypto/subtle/aes-ctr-import-key-unwrap-jwk-key-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/aes-ctr-import-key-unwrap-jwk-key.html [new file with mode: 0644]
LayoutTests/crypto/subtle/aes-ctr-import-key-unwrap-raw-key-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/aes-ctr-import-key-unwrap-raw-key.html [new file with mode: 0644]
LayoutTests/crypto/subtle/aes-ctr-import-key-wrap-jwk-key-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/aes-ctr-import-key-wrap-jwk-key.html [new file with mode: 0644]
LayoutTests/crypto/subtle/aes-ctr-import-key-wrap-raw-key-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/aes-ctr-import-key-wrap-raw-key.html [new file with mode: 0644]
LayoutTests/crypto/subtle/aes-ctr-import-raw-key-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/aes-ctr-import-raw-key.html [new file with mode: 0644]
LayoutTests/crypto/subtle/aes-generate-key-malformed-parameters-expected.txt
LayoutTests/crypto/subtle/aes-generate-key-malformed-parameters.html
LayoutTests/crypto/subtle/aes-import-key-malformed-parameters-expected.txt
LayoutTests/crypto/subtle/aes-import-key-malformed-parameters.html
LayoutTests/crypto/workers/subtle/aes-ctr-import-key-decrypt-expected.txt [new file with mode: 0644]
LayoutTests/crypto/workers/subtle/aes-ctr-import-key-decrypt.html [new file with mode: 0644]
LayoutTests/crypto/workers/subtle/aes-ctr-import-key-encrypt-expected.txt [new file with mode: 0644]
LayoutTests/crypto/workers/subtle/aes-ctr-import-key-encrypt.html [new file with mode: 0644]
LayoutTests/crypto/workers/subtle/aes-ctr-import-key-unwrap-key-expected.txt [new file with mode: 0644]
LayoutTests/crypto/workers/subtle/aes-ctr-import-key-unwrap-key.html [new file with mode: 0644]
LayoutTests/crypto/workers/subtle/aes-ctr-import-key-wrap-key-expected.txt [new file with mode: 0644]
LayoutTests/crypto/workers/subtle/aes-ctr-import-key-wrap-key.html [new file with mode: 0644]
LayoutTests/crypto/workers/subtle/resources/aes-ctr-import-key-decrypt.js [new file with mode: 0644]
LayoutTests/crypto/workers/subtle/resources/aes-ctr-import-key-encrypt.js [new file with mode: 0644]
LayoutTests/crypto/workers/subtle/resources/aes-ctr-import-key-unwrap-key.js [new file with mode: 0644]
LayoutTests/crypto/workers/subtle/resources/aes-ctr-import-key-wrap-key.js [new file with mode: 0644]
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/WebCryptoAPI/derive_bits_keys/pbkdf2.worker-expected.txt
LayoutTests/imported/w3c/web-platform-tests/WebCryptoAPI/derive_bits_keys/test_pbkdf2-expected.txt
LayoutTests/imported/w3c/web-platform-tests/WebCryptoAPI/encrypt_decrypt/aes_cbc.worker-expected.txt
LayoutTests/imported/w3c/web-platform-tests/WebCryptoAPI/encrypt_decrypt/aes_ctr.worker-expected.txt
LayoutTests/imported/w3c/web-platform-tests/WebCryptoAPI/encrypt_decrypt/test_aes_cbc-expected.txt
LayoutTests/imported/w3c/web-platform-tests/WebCryptoAPI/encrypt_decrypt/test_aes_ctr-expected.txt
LayoutTests/imported/w3c/web-platform-tests/WebCryptoAPI/generateKey/failures_AES-CTR.worker-expected.txt
LayoutTests/imported/w3c/web-platform-tests/WebCryptoAPI/generateKey/successes_AES-CTR.worker-expected.txt
LayoutTests/imported/w3c/web-platform-tests/WebCryptoAPI/generateKey/test_aes-ctr-expected.txt
LayoutTests/imported/w3c/web-platform-tests/WebCryptoAPI/generateKey/test_failures_AES-CTR-expected.txt
LayoutTests/imported/w3c/web-platform-tests/WebCryptoAPI/generateKey/test_successes_AES-CTR-expected.txt
LayoutTests/imported/w3c/web-platform-tests/WebCryptoAPI/import_export/symmetric_importKey.worker-expected.txt
LayoutTests/imported/w3c/web-platform-tests/WebCryptoAPI/import_export/test_symmetric_importKey-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/CryptoAlgorithmParameters.h
Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_CTR.cpp [new file with mode: 0644]
Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_CTR.h [new file with mode: 0644]
Source/WebCore/crypto/gcrypt/CryptoAlgorithmAES_CTRGCrypt.cpp [new file with mode: 0644]
Source/WebCore/crypto/mac/CryptoAlgorithmAES_CTRMac.cpp [new file with mode: 0644]
Source/WebCore/crypto/mac/CryptoAlgorithmRegistryMac.cpp
Source/WebCore/crypto/parameters/AesCtrParams.idl [new file with mode: 0644]
Source/WebCore/crypto/parameters/CryptoAlgorithmAesCtrParams.h [new file with mode: 0644]