haikuwebkit/LayoutTests/crypto/subtle/aes-ctr-import-key-wrap-jwk...

43 lines
1.2 KiB
HTML
Raw Permalink Normal View History

[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. Canonical link: https://commits.webkit.org/187481@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@215051 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-04-06 18:56:33 +00:00
<!DOCTYPE html>
<html>
<head>
<script src="../../resources/js-test-pre.js"></script>
<script src="../resources/common.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script>
description("Test wrapping a JWK key with AES-CTR using an imported key");
jsTestIsAsync = true;
var extractable = true;
var rawKey = asciiToUint8Array("jnOw99oOZFLIEPMr");
var aesCtrParams = {
name: "aes-ctr",
counter: asciiToUint8Array("jnOw99oOZFLIEPMr"),
length: 8,
}
var expectWrappedKey = "96be4de93c08cec8b53046ba31deedd35ab9dead0c86fe41b66cca58a6ba2ced4a55915a1991450dcffd50a533b041cf2b981a53c4136682a0f809e801af10a5bd54cac4e3bb7b345405b73e0bfe51141b23f33d714f81ed7067af";
crypto.subtle.importKey("raw", rawKey, "aes-ctr", extractable, ["wrapKey"]).then(function(result) {
wrappingKey = result;
return crypto.subtle.importKey("raw", rawKey, "aes-cbc", extractable, ["encrypt"]);
}).then(function(result) {
key = result;
return crypto.subtle.wrapKey("jwk", key, wrappingKey, aesCtrParams);
}).then(function(result) {
wrappedKey = result;
shouldBe("bytesToHexString(wrappedKey)", "expectWrappedKey");
finishJSTest();
});
</script>
<script src="../../resources/js-test-post.js"></script>
</body>