Title: [256014] trunk
Revision
256014
Author
[email protected]
Date
2020-02-07 02:01:52 -0800 (Fri, 07 Feb 2020)

Log Message

[OpenSSL] Implement WebCrypto APIs for AES-CBC, AES-CFB and AES-GCM
https://bugs.webkit.org/show_bug.cgi?id=207176

Patch by Tomoki Imai <[email protected]> on 2020-02-07
Reviewed by Fujii Hironori.

Source/WebCore:

Add WebCrypto implementations for the following algorithms with OpenSSL.
- AES_CBC
- AES_CFB
- AES_GCM

Currently we don't have AES-KW implementation, because EVP API doesn't have AES-KW implementation.

Enabled WebCrypto LayoutTests for AES-CBC, AES-CFB and AES-GCM.

* crypto/openssl/CryptoAlgorithmAES_CBCOpenSSL.cpp:
(WebCore::aesAlgorithm): Added. Helper function to select which AES-CBC algorithm to be used by checking key size.
(WebCore::cryptEncrypt): Added. Helper function for platformEncrypt.
(WebCore::cryptDecrypt): Added. Helper function for platformDecrypt.
(WebCore::CryptoAlgorithmAES_CBC::platformEncrypt): Implemented
(WebCore::CryptoAlgorithmAES_CBC::platformDecrypt): Implemented
* crypto/openssl/CryptoAlgorithmAES_CFBOpenSSL.cpp:
(WebCore::aesAlgorithm): Added. Helper function to select which AES-CFB algorithm to be used by checking key size.
(WebCore::cryptEncrypt): Added. Helper function for platformEncrypt.
(WebCore::cryptDecrypt): Added. Helper function for platformDecrypt.
(WebCore::CryptoAlgorithmAES_CFB::platformEncrypt): Implemented
(WebCore::CryptoAlgorithmAES_CFB::platformDecrypt): Implemented
* crypto/openssl/CryptoAlgorithmAES_GCMOpenSSL.cpp:
(WebCore::aesAlgorithm): Added. Helper function to select which AES-GCM algorithm to be used by checking key size.
(WebCore::cryptEncrypt): Added. Helper function for platformEncrypt.
(WebCore::cryptDecrypt): Added. Helper function for platformDecrypt.
(WebCore::CryptoAlgorithmAES_GCM::platformEncrypt): Implemented
(WebCore::CryptoAlgorithmAES_GCM::platformDecrypt): Implemented
* crypto/openssl/CryptoAlgorithmRegistryOpenSSL.cpp:
(WebCore::CryptoAlgorithmRegistry::platformRegisterAlgorithms): Registered CryptoAlgorithmAES_CBC, CryptoAlgorithmAES_CFB,
and CryptoAlgorithmAES_GCM.
* crypto/openssl/OpenSSLCryptoUniquePtr.h: Added to make sure that EVP_CIPHER_CTX is freed.
(WebCore::OpenSSLCryptoPtrDeleter<EVP_CIPHER_CTX>::operator() const):

LayoutTests:

Enabled WebCrypto LayoutTests for AES-CBC, AES-CFB and AES-GCM along with the implementation.

* platform/wincairo/TestExpectations:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (256013 => 256014)


--- trunk/LayoutTests/ChangeLog	2020-02-07 09:39:02 UTC (rev 256013)
+++ trunk/LayoutTests/ChangeLog	2020-02-07 10:01:52 UTC (rev 256014)
@@ -1,3 +1,14 @@
+2020-02-07  Tomoki Imai  <[email protected]>
+
+        [OpenSSL] Implement WebCrypto APIs for AES-CBC, AES-CFB and AES-GCM
+        https://bugs.webkit.org/show_bug.cgi?id=207176
+
+        Reviewed by Fujii Hironori.
+
+        Enabled WebCrypto LayoutTests for AES-CBC, AES-CFB and AES-GCM along with the implementation.
+
+        * platform/wincairo/TestExpectations:
+
 2020-02-07  Patrick Griffis  <[email protected]>
 
         [GTK][WPE] Add same-site cookie support

Modified: trunk/LayoutTests/platform/wincairo/TestExpectations (256013 => 256014)


--- trunk/LayoutTests/platform/wincairo/TestExpectations	2020-02-07 09:39:02 UTC (rev 256013)
+++ trunk/LayoutTests/platform/wincairo/TestExpectations	2020-02-07 10:01:52 UTC (rev 256014)
@@ -215,8 +215,6 @@
 # SPEECH_SYNTHESIS is disabled
 fast/speechsynthesis [ Skip ]
 
-# SUBTLE_CRYPTO is disabled
-crypto/subtle/ [ Skip ]
 crypto/workers/subtle/ [ Skip ]
 crypto/crypto-key-algorithm-gc.html [ Skip ]
 crypto/crypto-key-usages-gc.html [ Skip ]
@@ -833,6 +831,334 @@
 webkit.org/b/206282 fast/text/stale-TextLayout-from-first-line.html [ ImageOnlyFailure ]
 
 #//////////////////////////////////////////////////////////////////////////////////////////
+# crypto
+#//////////////////////////////////////////////////////////////////////////////////////////
+# AES-CTR is not supported.
+crypto/subtle/aes-ctr-encrypt-malformed-parameters.html [ Skip ]
+crypto/subtle/aes-ctr-generate-export-key-jwk-length-128.html [ Skip ]
+crypto/subtle/aes-ctr-generate-export-key-jwk-length-192.html [ Skip ]
+crypto/subtle/aes-ctr-generate-export-key-jwk-length-256.html [ Skip ]
+crypto/subtle/aes-ctr-generate-export-raw-key.html [ Skip ]
+crypto/subtle/aes-ctr-generate-key-encrypt-decrypt.html [ Skip ]
+crypto/subtle/aes-ctr-generate-key.html [ Skip ]
+crypto/subtle/aes-ctr-import-jwk-key-length-128.html [ Skip ]
+crypto/subtle/aes-ctr-import-jwk-key-length-192.html [ Skip ]
+crypto/subtle/aes-ctr-import-jwk-key-length-256.html [ Skip ]
+crypto/subtle/aes-ctr-import-key-decrypt.html [ Skip ]
+crypto/subtle/aes-ctr-import-key-encrypt.html [ Skip ]
+crypto/subtle/aes-ctr-import-key-unwrap-jwk-key.html [ Skip ]
+crypto/subtle/aes-ctr-import-key-unwrap-raw-key.html [ Skip ]
+crypto/subtle/aes-ctr-import-key-wrap-jwk-key.html [ Skip ]
+crypto/subtle/aes-ctr-import-key-wrap-raw-key.html [ Skip ]
+crypto/subtle/aes-ctr-import-raw-key.html [ Skip ]
+
+# AES-KW is not supported.
+crypto/subtle/aes-generate-key-malformed-parameters.html [ Skip ]
+crypto/subtle/aes-kw-wrap-key-malformed-parameters.html [ Skip ]
+crypto/subtle/aes-kw-generate-export-key-jwk-length-128.html [ Skip ]
+crypto/subtle/aes-kw-generate-export-key-jwk-length-192.html [ Skip ]
+crypto/subtle/aes-kw-generate-export-key-jwk-length-256.html [ Skip ]
+crypto/subtle/aes-kw-generate-export-raw-key.html [ Skip ]
+crypto/subtle/aes-kw-generate-key.html [ Skip ]
+crypto/subtle/aes-kw-generate-key-wrap-key-unwrap-key.html [ Skip ]
+crypto/subtle/aes-kw-import-jwk-key-length-128.html [ Skip ]
+crypto/subtle/aes-kw-import-jwk-key-length-192.html [ Skip ]
+crypto/subtle/aes-kw-import-jwk-key-length-256.html [ Skip ]
+crypto/subtle/aes-kw-import-key-unwrap-raw-key.html [ Skip ]
+crypto/subtle/aes-kw-import-key-wrap-raw-key.html [ Skip ]
+crypto/subtle/aes-kw-import-raw-key.html [ Skip ]
+
+# Crypts other than AES are not supported.
+crypto/subtle/aes-cbc-import-key-unwrap-jwk-rsa-key-private.html [ Skip ]
+crypto/subtle/aes-cbc-import-key-unwrap-jwk-rsa-key-public.html [ Skip ]
+crypto/subtle/aes-cbc-import-key-unwrap-pkcs8-key.html [ Skip ]
+crypto/subtle/aes-cbc-import-key-unwrap-spki-key.html [ Skip ]
+crypto/subtle/aes-cbc-import-key-wrap-jwk-rsa-key-private.html [ Skip ]
+crypto/subtle/aes-cbc-import-key-wrap-jwk-rsa-key-public.html [ Skip ]
+crypto/subtle/aes-cbc-import-key-wrap-pkcs8-key.html [ Skip ]
+crypto/subtle/aes-cbc-import-key-wrap-spki-key.html [ Skip ]
+crypto/subtle/aes-export-key-malformed-parameters.html [ Skip ]
+crypto/subtle/aes-gcm-import-key-unwrap-ec-raw-key.html [ Skip ]
+crypto/subtle/aes-import-key-malformed-parameters.html [ Skip ]
+crypto/subtle/decrypt-malformed-parameters.html [ Skip ]
+crypto/subtle/derive-bits-malformed-parameters.html [ Skip ]
+crypto/subtle/derive-key-malformed-parameters.html [ Skip ]
+crypto/subtle/digest-malformed-parameters.html [ Skip ]
+crypto/subtle/ecdh-derive-bits-length-limits.html [ Skip ]
+crypto/subtle/ecdh-derive-bits-malformed-parametrs.html [ Skip ]
+crypto/subtle/ecdh-generate-export-jwk-key-p256.html [ Skip ]
+crypto/subtle/ecdh-generate-export-jwk-key-p384.html [ Skip ]
+crypto/subtle/ecdh-generate-export-jwk-key-p521.html [ Skip ]
+crypto/subtle/ecdh-generate-export-key-pkcs8-p256.html [ Skip ]
+crypto/subtle/ecdh-generate-export-key-pkcs8-p384.html [ Skip ]
+crypto/subtle/ecdh-generate-export-key-pkcs8-p521.html [ Skip ]
+crypto/subtle/ecdh-generate-export-key-raw-p256.html [ Skip ]
+crypto/subtle/ecdh-generate-export-key-raw-p384.html [ Skip ]
+crypto/subtle/ecdh-generate-export-key-raw-p521.html [ Skip ]
+crypto/subtle/ecdh-generate-export-key-spki-p256.html [ Skip ]
+crypto/subtle/ecdh-generate-export-key-spki-p384.html [ Skip ]
+crypto/subtle/ecdh-generate-export-key-spki-p521.html [ Skip ]
+crypto/subtle/ecdh-generate-key-derive-bits.html [ Skip ]
+crypto/subtle/ecdh-generate-key-extractable.html [ Skip ]
+crypto/subtle/ecdh-generate-key-p256.html [ Skip ]
+crypto/subtle/ecdh-generate-key-p384.html [ Skip ]
+crypto/subtle/ecdh-generate-key-p521.html [ Skip ]
+crypto/subtle/ecdh-generate-key-single-usage.html [ Skip ]
+crypto/subtle/ecdh-import-jwk-key-minimum.html [ Skip ]
+crypto/subtle/ecdh-import-jwk-private-key-p256.html [ Skip ]
+crypto/subtle/ecdh-import-jwk-private-key-p384.html [ Skip ]
+crypto/subtle/ecdh-import-jwk-private-key-p521.html [ Skip ]
+crypto/subtle/ecdh-import-jwk-public-key-p256.html [ Skip ]
+crypto/subtle/ecdh-import-jwk-public-key-p384.html [ Skip ]
+crypto/subtle/ecdh-import-jwk-public-key-p521.html [ Skip ]
+crypto/subtle/ecdh-import-key-derive-aes-key.html [ Skip ]
+crypto/subtle/ecdh-import-key-derive-bits-custom-length.html [ Skip ]
+crypto/subtle/ecdh-import-key-derive-bits-null-length.html [ Skip ]
+crypto/subtle/ecdh-import-key-derive-hkdf-key.html [ Skip ]
+crypto/subtle/ecdh-import-key-derive-hmac-key-custom-length.html [ Skip ]
+crypto/subtle/ecdh-import-key-derive-pbkdf2-key.html [ Skip ]
+crypto/subtle/ecdh-import-pkcs8-key-p256.html [ Skip ]
+crypto/subtle/ecdh-import-pkcs8-key-p256-validate-ecprivatekey-parameters-publickey.html [ Skip ]
+crypto/subtle/ecdh-import-pkcs8-key-p384.html [ Skip ]
+crypto/subtle/ecdh-import-pkcs8-key-p384-validate-ecprivatekey-parameters-publickey.html [ Skip ]
+crypto/subtle/ecdh-import-pkcs8-key-p521.html [ Skip ]
+crypto/subtle/ecdh-import-pkcs8-key-p521-validate-ecprivatekey-parameters-publickey.html [ Skip ]
+crypto/subtle/ecdh-import-raw-key-p256.html [ Skip ]
+crypto/subtle/ecdh-import-raw-key-p384.html [ Skip ]
+crypto/subtle/ecdh-import-raw-key-p521.html [ Skip ]
+crypto/subtle/ecdh-import-spki-key-ecdh-identifier.html [ Skip ]
+crypto/subtle/ecdh-import-spki-key-p256.html [ Skip ]
+crypto/subtle/ecdh-import-spki-key-p384.html [ Skip ]
+crypto/subtle/ecdh-import-spki-key-p521.html [ Skip ]
+crypto/subtle/ecdsa-generate-export-import-jwk-sign-verify.html [ Skip ]
+crypto/subtle/ecdsa-generate-export-jwk-key.html [ Skip ]
+crypto/subtle/ecdsa-generate-export-key-pkcs8.html [ Skip ]
+crypto/subtle/ecdsa-generate-export-key-raw.html [ Skip ]
+crypto/subtle/ecdsa-generate-export-key-spki.html [ Skip ]
+crypto/subtle/ecdsa-generate-key.html [ Skip ]
+crypto/subtle/ecdsa-generate-key-sign-verify-p256.html [ Skip ]
+crypto/subtle/ecdsa-generate-key-sign-verify-p384.html [ Skip ]
+crypto/subtle/ecdsa-generate-key-sign-verify-p521.html [ Skip ]
+crypto/subtle/ecdsa-import-jwk-private-key.html [ Skip ]
+crypto/subtle/ecdsa-import-jwk-public-key.html [ Skip ]
+crypto/subtle/ecdsa-import-jwk-public-key-alg-256.html [ Skip ]
+crypto/subtle/ecdsa-import-jwk-public-key-alg-384.html [ Skip ]
+crypto/subtle/ecdsa-import-jwk-public-key-alg-521.html [ Skip ]
+crypto/subtle/ecdsa-import-key-sign-p256.html [ Skip ]
+crypto/subtle/ecdsa-import-key-sign-p384.html [ Skip ]
+crypto/subtle/ecdsa-import-key-sign-p521.html [ Skip ]
+crypto/subtle/ecdsa-import-key-verify-p256.html [ Skip ]
+crypto/subtle/ecdsa-import-key-verify-p384.html [ Skip ]
+crypto/subtle/ecdsa-import-key-verify-p521.html [ Skip ]
+crypto/subtle/ecdsa-import-pkcs8-key.html [ Skip ]
+crypto/subtle/ecdsa-import-pkcs8-key-p256-validate-ecprivatekey-parameters-publickey.html [ Skip ]
+crypto/subtle/ecdsa-import-pkcs8-key-p384-validate-ecprivatekey-parameters-publickey.html [ Skip ]
+crypto/subtle/ecdsa-import-pkcs8-key-p521-validate-ecprivatekey-parameters-publickey.html [ Skip ]
+crypto/subtle/ecdsa-import-raw-key.html [ Skip ]
+crypto/subtle/ecdsa-import-spki-key.html [ Skip ]
+crypto/subtle/ecdsa-verify-malformed-parameters.html [ Skip ]
+crypto/subtle/ec-export-key-malformed-parameters.html [ Skip ]
+crypto/subtle/ec-generate-key-malformed-parameters.html [ Skip ]
+crypto/subtle/ec-import-jwk-key-export-jwk-key-private.html [ Skip ]
+crypto/subtle/ec-import-jwk-key-export-jwk-key-public.html [ Skip ]
+crypto/subtle/ec-import-jwk-key-export-pkcs8-key.html [ Skip ]
+crypto/subtle/ec-import-jwk-key-export-raw-key.html [ Skip ]
+crypto/subtle/ec-import-jwk-key-export-spki-key.html [ Skip ]
+crypto/subtle/ec-import-key-malformed-parameters.html [ Skip ]
+crypto/subtle/ec-import-pkcs8-key-export-jwk-key.html [ Skip ]
+crypto/subtle/ec-import-pkcs8-key-export-pkcs8-key-p256.html [ Skip ]
+crypto/subtle/ec-import-pkcs8-key-export-pkcs8-key-p384.html [ Skip ]
+crypto/subtle/ec-import-pkcs8-key-export-pkcs8-key-p521.html [ Skip ]
+crypto/subtle/ec-import-raw-key-export-jwk-key.html [ Skip ]
+crypto/subtle/ec-import-raw-key-export-raw-key.html [ Skip ]
+crypto/subtle/ec-import-raw-key-export-spki-key.html [ Skip ]
+crypto/subtle/ec-import-spki-key-export-jwk-key.html [ Skip ]
+crypto/subtle/ec-import-spki-key-export-raw-key.html [ Skip ]
+crypto/subtle/ec-import-spki-key-export-spki-key-p256.html [ Skip ]
+crypto/subtle/ec-import-spki-key-export-spki-key-p384.html [ Skip ]
+crypto/subtle/ec-import-spki-key-export-spki-key-p521.html [ Skip ]
+crypto/subtle/encrypt-malformed-parameters.html [ Skip ]
+crypto/subtle/export-key-malformed-parameters.html [ Skip ]
+crypto/subtle/gc.html [ Skip ]
+crypto/subtle/gc-2.html [ Skip ]
+crypto/subtle/gc-3.html [ Skip ]
+crypto/subtle/generate-key-malformed-parameters.html [ Skip ]
+crypto/subtle/hkdf-derive-bits-length-limits.html [ Skip ]
+crypto/subtle/hkdf-derive-bits-malformed-parametrs.html [ Skip ]
+crypto/subtle/hkdf-import-key.html [ Skip ]
+crypto/subtle/hkdf-import-key-derive-bits.html [ Skip ]
+crypto/subtle/hkdf-import-key-derive-hmac-key.html [ Skip ]
+crypto/subtle/hkdf-import-key-malformed-parameters.html [ Skip ]
+crypto/subtle/hmac-export-key-malformed-parameters.html [ Skip ]
+crypto/subtle/hmac-generate-export-key-jwk-sha1.html [ Skip ]
+crypto/subtle/hmac-generate-export-key-jwk-sha224.html [ Skip ]
+crypto/subtle/hmac-generate-export-key-jwk-sha256.html [ Skip ]
+crypto/subtle/hmac-generate-export-key-jwk-sha384.html [ Skip ]
+crypto/subtle/hmac-generate-export-key-jwk-sha512.html [ Skip ]
+crypto/subtle/hmac-generate-export-raw-key.html [ Skip ]
+crypto/subtle/hmac-generate-key-customized-length.html [ Skip ]
+crypto/subtle/hmac-generate-key-hash-object.html [ Skip ]
+crypto/subtle/hmac-generate-key-malformed-parameters.html [ Skip ]
+crypto/subtle/hmac-generate-key-sha1.html [ Skip ]
+crypto/subtle/hmac-generate-key-sha224.html [ Skip ]
+crypto/subtle/hmac-generate-key-sha256.html [ Skip ]
+crypto/subtle/hmac-generate-key-sha384.html [ Skip ]
+crypto/subtle/hmac-generate-key-sha512.html [ Skip ]
+crypto/subtle/hmac-generate-key-sign-verify.html [ Skip ]
+crypto/subtle/hmac-import-jwk-key-export-jwk-key.html [ Skip ]
+crypto/subtle/hmac-import-jwk-key-export-raw-key.html [ Skip ]
+crypto/subtle/hmac-import-jwk-key-minimum.html [ Skip ]
+crypto/subtle/hmac-import-jwk-key-non-extractable.html [ Skip ]
+crypto/subtle/hmac-import-jwk-key-sha1.html [ Skip ]
+crypto/subtle/hmac-import-jwk-key-sha224.html [ Skip ]
+crypto/subtle/hmac-import-jwk-key-sha256.html [ Skip ]
+crypto/subtle/hmac-import-jwk-key-sha384.html [ Skip ]
+crypto/subtle/hmac-import-jwk-key-sha512.html [ Skip ]
+crypto/subtle/hmac-import-key-malformed-parameters.html [ Skip ]
+crypto/subtle/hmac-import-key-sign-sha1.html [ Skip ]
+crypto/subtle/hmac-import-key-sign-sha224.html [ Skip ]
+crypto/subtle/hmac-import-key-sign-sha256.html [ Skip ]
+crypto/subtle/hmac-import-key-sign-sha384.html [ Skip ]
+crypto/subtle/hmac-import-key-sign-sha512.html [ Skip ]
+crypto/subtle/hmac-import-key-verify-sha1.html [ Skip ]
+crypto/subtle/hmac-import-key-verify-sha224.html [ Skip ]
+crypto/subtle/hmac-import-key-verify-sha256.html [ Skip ]
+crypto/subtle/hmac-import-key-verify-sha384.html [ Skip ]
+crypto/subtle/hmac-import-key-verify-sha512.html [ Skip ]
+crypto/subtle/hmac-import-raw-key.html [ Skip ]
+crypto/subtle/hmac-import-raw-key-customized-length.html [ Skip ]
+crypto/subtle/hmac-import-raw-key-export-jwk-key.html [ Skip ]
+crypto/subtle/hmac-import-raw-key-export-raw-key.html [ Skip ]
+crypto/subtle/import-key-malformed-parameters.html [ Skip ]
+crypto/subtle/pbkdf2-derive-bits-malformed-parametrs.html [ Skip ]
+crypto/subtle/pbkdf2-import-key.html [ Skip ]
+crypto/subtle/pbkdf2-import-key-derive-bits.html [ Skip ]
+crypto/subtle/pbkdf2-import-key-derive-hmac-key.html [ Skip ]
+crypto/subtle/pbkdf2-import-key-malformed-parameters.html [ Skip ]
+crypto/subtle/rsaes-pkcs1-v1_5-generate-export-key-jwk.html [ Skip ]
+crypto/subtle/rsaes-pkcs1-v1_5-generate-export-key-pkcs8.html [ Skip ]
+crypto/subtle/rsaes-pkcs1-v1_5-generate-export-key-spki.html [ Skip ]
+crypto/subtle/rsaes-pkcs1-v1_5-generate-key.html [ Skip ]
+crypto/subtle/rsaes-pkcs1-v1_5-generate-key-encrypt-decrypt.html [ Skip ]
+crypto/subtle/rsaes-pkcs1-v1_5-generate-key-extractable.html [ Skip ]
+crypto/subtle/rsaes-pkcs1-v1_5-import-jwk-private-key.html [ Skip ]
+crypto/subtle/rsaes-pkcs1-v1_5-import-jwk-public-key.html [ Skip ]
+crypto/subtle/rsaes-pkcs1-v1_5-import-jwk-public-key-empty-usages.html [ Skip ]
+crypto/subtle/rsaes-pkcs1-v1_5-import-jwk-public-key-leading-zero.html [ Skip ]
+crypto/subtle/rsaes-pkcs1-v1_5-import-jwk-public-key-minimum.html [ Skip ]
+crypto/subtle/rsaes-pkcs1-v1_5-import-jwk-public-key-non-extractable.html [ Skip ]
+crypto/subtle/rsaes-pkcs1-v1_5-import-key-decrypt.html [ Skip ]
+crypto/subtle/rsaes-pkcs1-v1_5-import-key-encrypt.html [ Skip ]
+crypto/subtle/rsaes-pkcs1-v1_5-import-pkcs8-key.html [ Skip ]
+crypto/subtle/rsaes-pkcs1-v1_5-import-spki-key.html [ Skip ]
+crypto/subtle/rsaes-pkcs1-v1_5-import-spki-key-empty-usages.html [ Skip ]
+crypto/subtle/rsa-export-key-malformed-parameters.html [ Skip ]
+crypto/subtle/rsa-generate-key-malformed-parameters.html [ Skip ]
+crypto/subtle/rsa-import-jwk-key-export-jwk-key-private.html [ Skip ]
+crypto/subtle/rsa-import-jwk-key-export-jwk-key-public.html [ Skip ]
+crypto/subtle/rsa-import-jwk-key-export-pkcs8-key.html [ Skip ]
+crypto/subtle/rsa-import-jwk-key-export-spki-key.html [ Skip ]
+crypto/subtle/rsa-import-key-malformed-parameters.html [ Skip ]
+crypto/subtle/rsa-import-pkcs8-key-export-jwk-key.html [ Skip ]
+crypto/subtle/rsa-import-pkcs8-key-export-pkcs8-key.html [ Skip ]
+crypto/subtle/rsa-import-spki-key-export-jwk-key.html [ Skip ]
+crypto/subtle/rsa-import-spki-key-export-spki-key.html [ Skip ]
+crypto/subtle/rsa-import-spki-small-key.html [ Skip ]
+crypto/subtle/rsa-indexeddb.html [ Skip ]
+crypto/subtle/rsa-indexeddb-non-exportable.html [ Skip ]
+crypto/subtle/rsa-indexeddb-non-exportable-private.html [ Skip ]
+crypto/subtle/rsa-indexeddb-private.html [ Skip ]
+crypto/subtle/rsa-oaep-decrypt-malformed-parameters.html [ Skip ]
+crypto/subtle/rsa-oaep-encrypt-malformed-parameters.html [ Skip ]
+crypto/subtle/rsa-oaep-generate-export-key-jwk-sha1.html [ Skip ]
+crypto/subtle/rsa-oaep-generate-export-key-jwk-sha224.html [ Skip ]
+crypto/subtle/rsa-oaep-generate-export-key-jwk-sha256.html [ Skip ]
+crypto/subtle/rsa-oaep-generate-export-key-jwk-sha384.html [ Skip ]
+crypto/subtle/rsa-oaep-generate-export-key-jwk-sha512.html [ Skip ]
+crypto/subtle/rsa-oaep-generate-export-key-pkcs8.html [ Skip ]
+crypto/subtle/rsa-oaep-generate-export-key-spki.html [ Skip ]
+crypto/subtle/rsa-oaep-generate-key.html [ Skip ]
+crypto/subtle/rsa-oaep-generate-key-encrypt-decrypt.html [ Skip ]
+crypto/subtle/rsa-oaep-generate-key-encrypt-decrypt-label.html [ Skip ]
+crypto/subtle/rsa-oaep-import-jwk-private-key.html [ Skip ]
+crypto/subtle/rsa-oaep-import-jwk-public-key-empty-usages.html [ Skip ]
+crypto/subtle/rsa-oaep-import-jwk-public-key-sha1.html [ Skip ]
+crypto/subtle/rsa-oaep-import-jwk-public-key-sha224.html [ Skip ]
+crypto/subtle/rsa-oaep-import-jwk-public-key-sha256.html [ Skip ]
+crypto/subtle/rsa-oaep-import-jwk-public-key-sha384.html [ Skip ]
+crypto/subtle/rsa-oaep-import-jwk-public-key-sha512.html [ Skip ]
+crypto/subtle/rsa-oaep-import-key-decrypt.html [ Skip ]
+crypto/subtle/rsa-oaep-import-key-decrypt-label.html [ Skip ]
+crypto/subtle/rsa-oaep-import-key-encrypt.html [ Skip ]
+crypto/subtle/rsa-oaep-import-key-encrypt-label.html [ Skip ]
+crypto/subtle/rsa-oaep-import-key-unwrap-jwk-oct-key.html [ Skip ]
+crypto/subtle/rsa-oaep-import-key-wrap-jwk-oct-key.html [ Skip ]
+crypto/subtle/rsa-oaep-import-pkcs8-key.html [ Skip ]
+crypto/subtle/rsa-oaep-import-spki-key.html [ Skip ]
+crypto/subtle/rsa-oaep-import-spki-key-empty-usages.html [ Skip ]
+crypto/subtle/rsa-oaep-plaintext-length.html [ Skip ]
+crypto/subtle/rsa-pss-generate-export-key-jwk-sha1.html [ Skip ]
+crypto/subtle/rsa-pss-generate-export-key-jwk-sha224.html [ Skip ]
+crypto/subtle/rsa-pss-generate-export-key-jwk-sha256.html [ Skip ]
+crypto/subtle/rsa-pss-generate-export-key-jwk-sha384.html [ Skip ]
+crypto/subtle/rsa-pss-generate-export-key-jwk-sha512.html [ Skip ]
+crypto/subtle/rsa-pss-generate-export-key-pkcs8.html [ Skip ]
+crypto/subtle/rsa-pss-generate-export-key-spki.html [ Skip ]
+crypto/subtle/rsa-pss-generate-key.html [ Skip ]
+crypto/subtle/rsa-pss-import-jwk-private-key.html [ Skip ]
+crypto/subtle/rsa-pss-import-jwk-public-key-empty-usages.html [ Skip ]
+crypto/subtle/rsa-pss-import-jwk-public-key-sha1.html [ Skip ]
+crypto/subtle/rsa-pss-import-jwk-public-key-sha224.html [ Skip ]
+crypto/subtle/rsa-pss-import-jwk-public-key-sha256.html [ Skip ]
+crypto/subtle/rsa-pss-import-jwk-public-key-sha384.html [ Skip ]
+crypto/subtle/rsa-pss-import-jwk-public-key-sha512.html [ Skip ]
+crypto/subtle/rsa-pss-import-key-sign.html [ Skip ]
+crypto/subtle/rsa-pss-import-key-sign-large-salt.html [ Skip ]
+crypto/subtle/rsa-pss-import-key-verify.html [ Skip ]
+crypto/subtle/rsa-pss-import-pkcs8-key.html [ Skip ]
+crypto/subtle/rsa-pss-import-spki-key.html [ Skip ]
+crypto/subtle/rsa-pss-import-spki-key-empty-usages.html [ Skip ]
+crypto/subtle/rsassa-pkcs1-v1_5-generate-export-key-jwk-sha1.html [ Skip ]
+crypto/subtle/rsassa-pkcs1-v1_5-generate-export-key-jwk-sha224.html [ Skip ]
+crypto/subtle/rsassa-pkcs1-v1_5-generate-export-key-jwk-sha256.html [ Skip ]
+crypto/subtle/rsassa-pkcs1-v1_5-generate-export-key-jwk-sha384.html [ Skip ]
+crypto/subtle/rsassa-pkcs1-v1_5-generate-export-key-jwk-sha512.html [ Skip ]
+crypto/subtle/rsassa-pkcs1-v1_5-generate-export-key-pkcs8.html [ Skip ]
+crypto/subtle/rsassa-pkcs1-v1_5-generate-export-key-spki.html [ Skip ]
+crypto/subtle/rsassa-pkcs1-v1_5-generate-key.html [ Skip ]
+crypto/subtle/rsassa-pkcs1-v1_5-generate-key-sign-verify.html [ Skip ]
+crypto/subtle/rsassa-pkcs1-v1_5-generate-key-with-leading-zeroes-in-exponent.html [ Skip ]
+crypto/subtle/rsassa-pkcs1-v1_5-import-jwk-private-key.html [ Skip ]
+crypto/subtle/rsassa-pkcs1-v1_5-import-jwk-public-key-empty-usages.html [ Skip ]
+crypto/subtle/rsassa-pkcs1-v1_5-import-jwk-public-key-sha1.html [ Skip ]
+crypto/subtle/rsassa-pkcs1-v1_5-import-jwk-public-key-sha224.html [ Skip ]
+crypto/subtle/rsassa-pkcs1-v1_5-import-jwk-public-key-sha256.html [ Skip ]
+crypto/subtle/rsassa-pkcs1-v1_5-import-jwk-public-key-sha384.html [ Skip ]
+crypto/subtle/rsassa-pkcs1-v1_5-import-jwk-public-key-sha512.html [ Skip ]
+crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha1.html [ Skip ]
+crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha224.html [ Skip ]
+crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha256.html [ Skip ]
+crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha384.html [ Skip ]
+crypto/subtle/rsassa-pkcs1-v1_5-import-key-sign-sha512.html [ Skip ]
+crypto/subtle/rsassa-pkcs1-v1_5-import-key-verify-sha1.html [ Skip ]
+crypto/subtle/rsassa-pkcs1-v1_5-import-key-verify-sha224.html [ Skip ]
+crypto/subtle/rsassa-pkcs1-v1_5-import-key-verify-sha256.html [ Skip ]
+crypto/subtle/rsassa-pkcs1-v1_5-import-key-verify-sha384.html [ Skip ]
+crypto/subtle/rsassa-pkcs1-v1_5-import-key-verify-sha512.html [ Skip ]
+crypto/subtle/rsassa-pkcs1-v1_5-import-pkcs8-key.html [ Skip ]
+crypto/subtle/rsassa-pkcs1-v1_5-import-spki-key.html [ Skip ]
+crypto/subtle/rsassa-pkcs1-v1_5-import-spki-key-empty-usages.html [ Skip ]
+crypto/subtle/sha1-digest.html [ Skip ]
+crypto/subtle/sha224-digest.html [ Skip ]
+crypto/subtle/sha256-digest.html [ Skip ]
+crypto/subtle/sha384-digest.html [ Skip ]
+crypto/subtle/sha512-digest.html [ Skip ]
+crypto/subtle/sign-malformed-parameters.html [ Skip ]
+crypto/subtle/unwrap-key-malformed-parameters.html [ Skip ]
+crypto/subtle/verify-malformed-parameters.html [ Skip ]
+crypto/subtle/wrap-key-malformed-parameters.html [ Skip ]
+
+#//////////////////////////////////////////////////////////////////////////////////////////
 # http
 #//////////////////////////////////////////////////////////////////////////////////////////
 

Modified: trunk/Source/WebCore/ChangeLog (256013 => 256014)


--- trunk/Source/WebCore/ChangeLog	2020-02-07 09:39:02 UTC (rev 256013)
+++ trunk/Source/WebCore/ChangeLog	2020-02-07 10:01:52 UTC (rev 256014)
@@ -1,3 +1,43 @@
+2020-02-07  Tomoki Imai  <[email protected]>
+
+        [OpenSSL] Implement WebCrypto APIs for AES-CBC, AES-CFB and AES-GCM
+        https://bugs.webkit.org/show_bug.cgi?id=207176
+
+        Reviewed by Fujii Hironori.
+
+        Add WebCrypto implementations for the following algorithms with OpenSSL.
+        - AES_CBC
+        - AES_CFB
+        - AES_GCM
+
+        Currently we don't have AES-KW implementation, because EVP API doesn't have AES-KW implementation.
+
+        Enabled WebCrypto LayoutTests for AES-CBC, AES-CFB and AES-GCM.
+
+        * crypto/openssl/CryptoAlgorithmAES_CBCOpenSSL.cpp:
+        (WebCore::aesAlgorithm): Added. Helper function to select which AES-CBC algorithm to be used by checking key size.
+        (WebCore::cryptEncrypt): Added. Helper function for platformEncrypt.
+        (WebCore::cryptDecrypt): Added. Helper function for platformDecrypt.
+        (WebCore::CryptoAlgorithmAES_CBC::platformEncrypt): Implemented
+        (WebCore::CryptoAlgorithmAES_CBC::platformDecrypt): Implemented
+        * crypto/openssl/CryptoAlgorithmAES_CFBOpenSSL.cpp:
+        (WebCore::aesAlgorithm): Added. Helper function to select which AES-CFB algorithm to be used by checking key size.
+        (WebCore::cryptEncrypt): Added. Helper function for platformEncrypt.
+        (WebCore::cryptDecrypt): Added. Helper function for platformDecrypt.
+        (WebCore::CryptoAlgorithmAES_CFB::platformEncrypt): Implemented
+        (WebCore::CryptoAlgorithmAES_CFB::platformDecrypt): Implemented
+        * crypto/openssl/CryptoAlgorithmAES_GCMOpenSSL.cpp:
+        (WebCore::aesAlgorithm): Added. Helper function to select which AES-GCM algorithm to be used by checking key size.
+        (WebCore::cryptEncrypt): Added. Helper function for platformEncrypt.
+        (WebCore::cryptDecrypt): Added. Helper function for platformDecrypt.
+        (WebCore::CryptoAlgorithmAES_GCM::platformEncrypt): Implemented
+        (WebCore::CryptoAlgorithmAES_GCM::platformDecrypt): Implemented
+        * crypto/openssl/CryptoAlgorithmRegistryOpenSSL.cpp:
+        (WebCore::CryptoAlgorithmRegistry::platformRegisterAlgorithms): Registered CryptoAlgorithmAES_CBC, CryptoAlgorithmAES_CFB,
+        and CryptoAlgorithmAES_GCM.
+        * crypto/openssl/OpenSSLCryptoUniquePtr.h: Added to make sure that EVP_CIPHER_CTX is freed.
+        (WebCore::OpenSSLCryptoPtrDeleter<EVP_CIPHER_CTX>::operator() const):
+
 2020-02-07  Patrick Griffis  <[email protected]>
 
         [GTK][WPE] Add same-site cookie support

Modified: trunk/Source/WebCore/crypto/openssl/CryptoAlgorithmAES_CBCOpenSSL.cpp (256013 => 256014)


--- trunk/Source/WebCore/crypto/openssl/CryptoAlgorithmAES_CBCOpenSSL.cpp	2020-02-07 09:39:02 UTC (rev 256013)
+++ trunk/Source/WebCore/crypto/openssl/CryptoAlgorithmAES_CBCOpenSSL.cpp	2020-02-07 10:01:52 UTC (rev 256014)
@@ -30,22 +30,109 @@
 
 #include "CryptoAlgorithmAesCbcCfbParams.h"
 #include "CryptoKeyAES.h"
-#include "NotImplemented.h"
+#include "OpenSSLCryptoUniquePtr.h"
+#include <openssl/evp.h>
 
 namespace WebCore {
 
-ExceptionOr<Vector<uint8_t>> CryptoAlgorithmAES_CBC::platformEncrypt(const CryptoAlgorithmAesCbcCfbParams&, const CryptoKeyAES&, const Vector<uint8_t>&, Padding)
+static const EVP_CIPHER* aesAlgorithm(size_t keySize)
 {
-    notImplemented();
-    return Exception { NotSupportedError };
+    if (keySize * 8 == 128)
+        return EVP_aes_128_cbc();
+
+    if (keySize * 8 == 192)
+        return EVP_aes_192_cbc();
+
+    if (keySize * 8 == 256)
+        return EVP_aes_256_cbc();
+
+    return nullptr;
 }
 
-ExceptionOr<Vector<uint8_t>> CryptoAlgorithmAES_CBC::platformDecrypt(const CryptoAlgorithmAesCbcCfbParams&, const CryptoKeyAES&, const Vector<uint8_t>&, Padding)
+static Optional<Vector<uint8_t>> cryptEncrypt(const Vector<uint8_t>& key, const Vector<uint8_t>& iv, Vector<uint8_t>&& plainText)
 {
-    notImplemented();
-    return Exception { NotSupportedError };
+    const EVP_CIPHER* algorithm = aesAlgorithm(key.size());
+    if (!algorithm)
+        return WTF::nullopt;
+
+    EvpCipherCtxPtr ctx;
+    int len;
+
+    // Create and initialize the context
+    if (!(ctx = EvpCipherCtxPtr(EVP_CIPHER_CTX_new())))
+        return WTF::nullopt;
+
+    size_t plainSize = plainText.size();
+    const size_t cipherTextLen = roundUpToMultipleOf(EVP_CIPHER_block_size(algorithm), plainSize + 1);
+    Vector<uint8_t> cipherText(cipherTextLen);
+
+    // Initialize the encryption operation
+    if (1 != EVP_EncryptInit_ex(ctx.get(), algorithm, nullptr, key.data(), iv.data()))
+        return WTF::nullopt;
+
+    // Provide the message to be encrypted, and obtain the encrypted output
+    if (1 != EVP_EncryptUpdate(ctx.get(), cipherText.data(), &len, plainText.data(), plainSize))
+        return WTF::nullopt;
+
+    // Finalize the encryption. Further ciphertext bytes may be written at this stage
+    if (1 != EVP_EncryptFinal_ex(ctx.get(), cipherText.data() + len, &len))
+        return WTF::nullopt;
+
+    return cipherText;
 }
 
+static Optional<Vector<uint8_t>> cryptDecrypt(const Vector<uint8_t>& key, const Vector<uint8_t>& iv, const Vector<uint8_t>& cipherText)
+{
+    const EVP_CIPHER* algorithm = aesAlgorithm(key.size());
+    if (!algorithm)
+        return WTF::nullopt;
+
+    EvpCipherCtxPtr ctx;
+
+    size_t cipherSize = cipherText.size();
+    Vector<uint8_t> plainText(cipherSize);
+    int len;
+    int plainTextLen;
+
+    // Create and initialize the context
+    if (!(ctx = EvpCipherCtxPtr(EVP_CIPHER_CTX_new())))
+        return WTF::nullopt;
+
+    // Initialize the decryption operation
+    if (1 != EVP_DecryptInit_ex(ctx.get(), algorithm, nullptr, key.data(), iv.data()))
+        return WTF::nullopt;
+
+    // Provide the message to be decrypted, and obtain the plaintext output
+    if (1 != EVP_DecryptUpdate(ctx.get(), plainText.data(), &len, cipherText.data(), cipherSize))
+        return WTF::nullopt;
+    plainTextLen = len;
+
+    // Finalize the decryption. Further plaintext bytes may be written at this stage
+    if (1 != EVP_DecryptFinal_ex(ctx.get(), plainText.data() + len, &len))
+        return WTF::nullopt;
+    plainTextLen += len;
+
+    plainText.shrink(plainTextLen);
+
+    return plainText;
+}
+
+ExceptionOr<Vector<uint8_t>> CryptoAlgorithmAES_CBC::platformEncrypt(const CryptoAlgorithmAesCbcCfbParams& parameters, const CryptoKeyAES& key, const Vector<uint8_t>& plainText, Padding)
+{
+    auto output = cryptEncrypt(key.key(), parameters.ivVector(), Vector<uint8_t>(plainText));
+    if (!output)
+        return Exception { OperationError };
+    return WTFMove(*output);
+}
+
+ExceptionOr<Vector<uint8_t>> CryptoAlgorithmAES_CBC::platformDecrypt(const CryptoAlgorithmAesCbcCfbParams& parameters, const CryptoKeyAES& key, const Vector<uint8_t>& cipherText, Padding)
+{
+    auto output = cryptDecrypt(key.key(), parameters.ivVector(), cipherText);
+    if (!output)
+        return Exception { OperationError };
+    return WTFMove(*output);
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(WEB_CRYPTO)

Modified: trunk/Source/WebCore/crypto/openssl/CryptoAlgorithmAES_CFBOpenSSL.cpp (256013 => 256014)


--- trunk/Source/WebCore/crypto/openssl/CryptoAlgorithmAES_CFBOpenSSL.cpp	2020-02-07 09:39:02 UTC (rev 256013)
+++ trunk/Source/WebCore/crypto/openssl/CryptoAlgorithmAES_CFBOpenSSL.cpp	2020-02-07 10:01:52 UTC (rev 256014)
@@ -30,22 +30,106 @@
 
 #include "CryptoAlgorithmAesCbcCfbParams.h"
 #include "CryptoKeyAES.h"
-#include "NotImplemented.h"
+#include "OpenSSLCryptoUniquePtr.h"
+#include <openssl/evp.h>
 
 namespace WebCore {
 
-ExceptionOr<Vector<uint8_t>> CryptoAlgorithmAES_CFB::platformEncrypt(const CryptoAlgorithmAesCbcCfbParams&, const CryptoKeyAES&, const Vector<uint8_t>&)
+static const EVP_CIPHER* aesAlgorithm(size_t keySize)
 {
-    notImplemented();
-    return Exception { NotSupportedError };
+    if (keySize * 8 == 128)
+        return EVP_aes_128_cfb8();
+
+    if (keySize * 8 == 192)
+        return EVP_aes_192_cfb8();
+
+    if (keySize * 8 == 256)
+        return EVP_aes_256_cfb8();
+
+    return nullptr;
 }
 
-ExceptionOr<Vector<uint8_t>> CryptoAlgorithmAES_CFB::platformDecrypt(const CryptoAlgorithmAesCbcCfbParams&, const CryptoKeyAES&, const Vector<uint8_t>&)
+static Optional<Vector<uint8_t>> cryptEncrypt(const Vector<uint8_t>& key, const Vector<uint8_t>& iv, Vector<uint8_t>&& plainText)
 {
-    notImplemented();
-    return Exception { NotSupportedError };
+    const EVP_CIPHER* algorithm = aesAlgorithm(key.size());
+    if (!algorithm)
+        return WTF::nullopt;
+
+    EvpCipherCtxPtr ctx;
+
+    Vector<uint8_t> cipherText(plainText.size());
+    int len;
+
+    // Create and initialize the context
+    if (!(ctx = EvpCipherCtxPtr(EVP_CIPHER_CTX_new())))
+        return WTF::nullopt;
+
+    // Disable padding
+    if (1 != EVP_CIPHER_CTX_set_padding(ctx.get(), 0))
+        return WTF::nullopt;
+
+    // Initialize the encryption operation
+    if (1 != EVP_EncryptInit_ex(ctx.get(), algorithm, nullptr, key.data(), iv.data()))
+        return WTF::nullopt;
+
+    // Provide the message to be encrypted, and obtain the encrypted output
+    if (1 != EVP_EncryptUpdate(ctx.get(), cipherText.data(), &len, plainText.data(), plainText.size()))
+        return WTF::nullopt;
+
+    // Finalize the encryption. Further ciphertext bytes may be written at this stage
+    if (1 != EVP_EncryptFinal_ex(ctx.get(), cipherText.data() + len, &len))
+        return WTF::nullopt;
+
+    return cipherText;
 }
 
+static Optional<Vector<uint8_t>> cryptDecrypt(const Vector<uint8_t>& key, const Vector<uint8_t>& iv, const Vector<uint8_t>& cipherText)
+{
+    const EVP_CIPHER* algorithm = aesAlgorithm(key.size());
+    if (!algorithm)
+        return WTF::nullopt;
+
+    EvpCipherCtxPtr ctx;
+
+    size_t cipherSize = cipherText.size();
+    Vector<uint8_t> plainText(cipherSize);
+    int len;
+
+    // Create and initialize the context
+    if (!(ctx = EvpCipherCtxPtr(EVP_CIPHER_CTX_new())))
+        return WTF::nullopt;
+
+    // Initialize the decryption operation
+    if (1 != EVP_DecryptInit_ex(ctx.get(), algorithm, nullptr, key.data(), iv.data()))
+        return WTF::nullopt;
+
+    // Provide the message to be decrypted, and obtain the plaintext output
+    if (1 != EVP_DecryptUpdate(ctx.get(), plainText.data(), &len, cipherText.data(), cipherSize))
+        return WTF::nullopt;
+
+    // Finalize the decryption. Further plaintext bytes may be written at this stage
+    if (1 != EVP_DecryptFinal_ex(ctx.get(), plainText.data() + len, &len))
+        return WTF::nullopt;
+
+    return plainText;
+}
+
+ExceptionOr<Vector<uint8_t>> CryptoAlgorithmAES_CFB::platformEncrypt(const CryptoAlgorithmAesCbcCfbParams& parameters, const CryptoKeyAES& key, const Vector<uint8_t>& plainText)
+{
+    auto output = cryptEncrypt(key.key(), parameters.ivVector(), Vector<uint8_t>(plainText));
+    if (!output)
+        return Exception { OperationError };
+    return WTFMove(*output);
+}
+
+ExceptionOr<Vector<uint8_t>> CryptoAlgorithmAES_CFB::platformDecrypt(const CryptoAlgorithmAesCbcCfbParams& parameters, const CryptoKeyAES& key, const Vector<uint8_t>& cipherText)
+{
+    auto output = cryptDecrypt(key.key(), parameters.ivVector(), cipherText);
+    if (!output)
+        return Exception { OperationError };
+    return WTFMove(*output);
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(WEB_CRYPTO)

Modified: trunk/Source/WebCore/crypto/openssl/CryptoAlgorithmAES_GCMOpenSSL.cpp (256013 => 256014)


--- trunk/Source/WebCore/crypto/openssl/CryptoAlgorithmAES_GCMOpenSSL.cpp	2020-02-07 09:39:02 UTC (rev 256013)
+++ trunk/Source/WebCore/crypto/openssl/CryptoAlgorithmAES_GCMOpenSSL.cpp	2020-02-07 10:01:52 UTC (rev 256014)
@@ -30,22 +30,156 @@
 
 #include "CryptoAlgorithmAesGcmParams.h"
 #include "CryptoKeyAES.h"
-#include "NotImplemented.h"
+#include "OpenSSLCryptoUniquePtr.h"
+#include <openssl/evp.h>
 
 namespace WebCore {
 
-ExceptionOr<Vector<uint8_t>> CryptoAlgorithmAES_GCM::platformEncrypt(const CryptoAlgorithmAesGcmParams&, const CryptoKeyAES&, const Vector<uint8_t>&)
+static const EVP_CIPHER* aesAlgorithm(size_t keySize)
 {
-    notImplemented();
-    return Exception { NotSupportedError };
+    if (keySize * 8 == 128)
+        return EVP_aes_128_gcm();
+
+    if (keySize * 8 == 192)
+        return EVP_aes_192_gcm();
+
+    if (keySize * 8 == 256)
+        return EVP_aes_256_gcm();
+
+    return nullptr;
 }
 
-ExceptionOr<Vector<uint8_t>> CryptoAlgorithmAES_GCM::platformDecrypt(const CryptoAlgorithmAesGcmParams&, const CryptoKeyAES&, const Vector<uint8_t>&)
+static Optional<Vector<uint8_t>> cryptEncrypt(const Vector<uint8_t>& key, const Vector<uint8_t>& iv, const Vector<uint8_t>& plainText, const Vector<uint8_t>& additionalData, uint8_t tagLength)
 {
-    notImplemented();
-    return Exception { NotSupportedError };
+    const EVP_CIPHER* algorithm = aesAlgorithm(key.size());
+    if (!algorithm)
+        return WTF::nullopt;
+
+    EvpCipherCtxPtr ctx;
+    int len;
+
+    Vector<uint8_t> cipherText(plainText.size() + tagLength);
+    size_t tagOffset = plainText.size();
+
+    // Create and initialize the context
+    if (!(ctx = EvpCipherCtxPtr(EVP_CIPHER_CTX_new())))
+        return WTF::nullopt;
+
+    // Disable padding
+    if (1 != EVP_CIPHER_CTX_set_padding(ctx.get(), 0))
+        return WTF::nullopt;
+
+    // Initialize the encryption operation
+    if (1 != EVP_EncryptInit_ex(ctx.get(), algorithm, nullptr, nullptr, nullptr))
+        return WTF::nullopt;
+
+    // Set IV length
+    if (1 != EVP_CIPHER_CTX_ctrl(ctx.get(), EVP_CTRL_GCM_SET_IVLEN, iv.size(), nullptr))
+        return WTF::nullopt;
+
+    // Initialize key and IV
+    if (1 != EVP_EncryptInit_ex(ctx.get(), nullptr, nullptr, key.data(), iv.data()))
+        return WTF::nullopt;
+
+    // Provide any AAD data
+    if (additionalData.size() > 0) {
+        if (1 != EVP_EncryptUpdate(ctx.get(), nullptr, &len, additionalData.data(), additionalData.size()))
+            return WTF::nullopt;
+    }
+
+    // Provide the message to be encrypted, and obtain the encrypted output
+    if (1 != EVP_EncryptUpdate(ctx.get(), cipherText.data(), &len, plainText.data(), plainText.size()))
+        return WTF::nullopt;
+
+    // Finalize the encryption. Normally ciphertext bytes may be written at
+    // this stage, but this does not occur in GCM mode
+    if (1 != EVP_EncryptFinal_ex(ctx.get(), cipherText.data() + len, &len))
+        return WTF::nullopt;
+
+    // Get the tag
+    if (1 != EVP_CIPHER_CTX_ctrl(ctx.get(), EVP_CTRL_GCM_GET_TAG, tagLength, cipherText.data() + tagOffset))
+        return WTF::nullopt;
+
+    return cipherText;
 }
 
+static Optional<Vector<uint8_t>> cryptDecrypt(const Vector<uint8_t>& key, const Vector<uint8_t>& iv, const Vector<uint8_t>& cipherText, const Vector<uint8_t>& additionalData, uint8_t tagLength)
+{
+    const EVP_CIPHER* algorithm = aesAlgorithm(key.size());
+    if (!algorithm)
+        return WTF::nullopt;
+
+    EvpCipherCtxPtr ctx;
+    int len;
+    int plainTextLen;
+    int cipherTextLen = cipherText.size() - tagLength;
+
+    Vector<uint8_t> plainText(cipherText.size());
+    Vector<uint8_t> tag(tagLength);
+    memcpy(tag.data(), cipherText.data() + cipherTextLen, tagLength);
+
+    // Create and initialize the context
+    if (!(ctx = EvpCipherCtxPtr(EVP_CIPHER_CTX_new())))
+        return WTF::nullopt;
+
+    // Disable padding
+    if (1 != EVP_CIPHER_CTX_set_padding(ctx.get(), 0))
+        return WTF::nullopt;
+
+    // Initialize the encryption operation
+    if (1 != EVP_DecryptInit_ex(ctx.get(), algorithm, nullptr, nullptr, nullptr))
+        return WTF::nullopt;
+
+    // Set IV length
+    if (1 != EVP_CIPHER_CTX_ctrl(ctx.get(), EVP_CTRL_GCM_SET_IVLEN, iv.size(), nullptr))
+        return WTF::nullopt;
+
+    // Initialize key and IV
+    if (1 != EVP_DecryptInit_ex(ctx.get(), nullptr, nullptr, key.data(), iv.data()))
+        return WTF::nullopt;
+
+    // Provide any AAD data
+    if (additionalData.size() > 0) {
+        if (1 != EVP_DecryptUpdate(ctx.get(), nullptr, &len, additionalData.data(), additionalData.size()))
+            return WTF::nullopt;
+    }
+
+    // Set expected tag value
+    if (1 != EVP_CIPHER_CTX_ctrl(ctx.get(), EVP_CTRL_GCM_SET_TAG, tag.size(), tag.data()))
+        return WTF::nullopt;
+
+    // Provide the message to be encrypted, and obtain the encrypted output
+    if (1 != EVP_DecryptUpdate(ctx.get(), plainText.data(), &len, cipherText.data(), cipherTextLen))
+        return WTF::nullopt;
+    plainTextLen = len;
+
+    // Finalize the decryption
+    if (1 != EVP_DecryptFinal_ex(ctx.get(), plainText.data() + len, &len))
+        return WTF::nullopt;
+
+    plainTextLen += len;
+
+    plainText.shrink(plainTextLen);
+
+    return plainText;
+}
+
+ExceptionOr<Vector<uint8_t>> CryptoAlgorithmAES_GCM::platformEncrypt(const CryptoAlgorithmAesGcmParams& parameters, const CryptoKeyAES& key, const Vector<uint8_t>& plainText)
+{
+    auto output = cryptEncrypt(key.key(), parameters.ivVector(), plainText, parameters.additionalDataVector(), parameters.tagLength.valueOr(0) / 8);
+    if (!output)
+        return Exception { OperationError };
+    return WTFMove(*output);
+}
+
+ExceptionOr<Vector<uint8_t>> CryptoAlgorithmAES_GCM::platformDecrypt(const CryptoAlgorithmAesGcmParams& parameters, const CryptoKeyAES& key, const Vector<uint8_t>& cipherText)
+{
+    auto output = cryptDecrypt(key.key(), parameters.ivVector(), cipherText, parameters.additionalDataVector(), parameters.tagLength.valueOr(0) / 8);
+    if (!output)
+        return Exception { OperationError };
+    return WTFMove(*output);
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(WEB_CRYPTO)

Modified: trunk/Source/WebCore/crypto/openssl/CryptoAlgorithmRegistryOpenSSL.cpp (256013 => 256014)


--- trunk/Source/WebCore/crypto/openssl/CryptoAlgorithmRegistryOpenSSL.cpp	2020-02-07 09:39:02 UTC (rev 256013)
+++ trunk/Source/WebCore/crypto/openssl/CryptoAlgorithmRegistryOpenSSL.cpp	2020-02-07 10:01:52 UTC (rev 256014)
@@ -28,6 +28,9 @@
 
 #if ENABLE(WEB_CRYPTO)
 
+#include "CryptoAlgorithmAES_CBC.h"
+#include "CryptoAlgorithmAES_CFB.h"
+#include "CryptoAlgorithmAES_GCM.h"
 #include "CryptoAlgorithmSHA1.h"
 #include "CryptoAlgorithmSHA224.h"
 #include "CryptoAlgorithmSHA256.h"
@@ -38,6 +41,9 @@
 
 void CryptoAlgorithmRegistry::platformRegisterAlgorithms()
 {
+    registerAlgorithm<CryptoAlgorithmAES_CBC>();
+    registerAlgorithm<CryptoAlgorithmAES_CFB>();
+    registerAlgorithm<CryptoAlgorithmAES_GCM>();
     registerAlgorithm<CryptoAlgorithmSHA1>();
     registerAlgorithm<CryptoAlgorithmSHA224>();
     registerAlgorithm<CryptoAlgorithmSHA256>();

Added: trunk/Source/WebCore/crypto/openssl/OpenSSLCryptoUniquePtr.h (0 => 256014)


--- trunk/Source/WebCore/crypto/openssl/OpenSSLCryptoUniquePtr.h	                        (rev 0)
+++ trunk/Source/WebCore/crypto/openssl/OpenSSLCryptoUniquePtr.h	2020-02-07 10:01:52 UTC (rev 256014)
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2016 Igalia S.L.
+ * Copyright (C) 2020 Sony Interactive Entertainment Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include <memory>
+#include <openssl/evp.h>
+
+namespace WebCore {
+
+template <typename T>
+struct OpenSSLCryptoPtrDeleter {
+    void operator()(T* ptr) const = delete;
+};
+
+template <typename T>
+using OpenSSLCryptoPtr = std::unique_ptr<T, OpenSSLCryptoPtrDeleter<T>>;
+
+template <>
+struct OpenSSLCryptoPtrDeleter<EVP_CIPHER_CTX> {
+    void operator()(EVP_CIPHER_CTX* ptr) const
+    {
+        EVP_CIPHER_CTX_free(ptr);
+    }
+};
+
+using EvpCipherCtxPtr = OpenSSLCryptoPtr<EVP_CIPHER_CTX>;
+
+} // namespace WebCore
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to