diff --git a/Userland/Libraries/LibWeb/Crypto/CryptoAlgorithms.cpp b/Userland/Libraries/LibWeb/Crypto/CryptoAlgorithms.cpp index e8169644085..3947995b2fe 100644 --- a/Userland/Libraries/LibWeb/Crypto/CryptoAlgorithms.cpp +++ b/Userland/Libraries/LibWeb/Crypto/CryptoAlgorithms.cpp @@ -1757,6 +1757,18 @@ WebIDL::ExceptionOr> AesCtr::decrypt(Algorithm return JS::ArrayBuffer::create(m_realm, plaintext); } +WebIDL::ExceptionOr AesGcm::get_key_length(AlgorithmParams const& params) +{ + // 1. If the length member of normalizedDerivedKeyAlgorithm is not 128, 192 or 256, then throw a OperationError. + auto const& normalized_algorithm = static_cast(params); + auto length = normalized_algorithm.length; + if (length != 128 && length != 192 && length != 256) + return WebIDL::OperationError::create(m_realm, "Invalid key length"_string); + + // 2. Return the length member of normalizedDerivedKeyAlgorithm. + return JS::Value(length); +} + // https://w3c.github.io/webcrypto/#hkdf-operations WebIDL::ExceptionOr> HKDF::import_key(AlgorithmParams const&, Bindings::KeyFormat format, CryptoKey::InternalKeyData key_data, bool extractable, Vector const& key_usages) { diff --git a/Userland/Libraries/LibWeb/Crypto/CryptoAlgorithms.h b/Userland/Libraries/LibWeb/Crypto/CryptoAlgorithms.h index 1722adf4b2c..8ee818eda3b 100644 --- a/Userland/Libraries/LibWeb/Crypto/CryptoAlgorithms.h +++ b/Userland/Libraries/LibWeb/Crypto/CryptoAlgorithms.h @@ -362,6 +362,19 @@ private: } }; +class AesGcm : public AlgorithmMethods { +public: + virtual WebIDL::ExceptionOr get_key_length(AlgorithmParams const&) override; + + static NonnullOwnPtr create(JS::Realm& realm) { return adopt_own(*new AesGcm(realm)); } + +private: + explicit AesGcm(JS::Realm& realm) + : AlgorithmMethods(realm) + { + } +}; + class HKDF : public AlgorithmMethods { public: virtual WebIDL::ExceptionOr> import_key(AlgorithmParams const&, Bindings::KeyFormat, CryptoKey::InternalKeyData, bool, Vector const&) override; diff --git a/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.cpp b/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.cpp index 0c08e0d7b96..9c7ac62dd22 100644 --- a/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.cpp +++ b/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.cpp @@ -784,6 +784,9 @@ SupportedAlgorithmsMap supported_algorithms() define_an_algorithm("get key length"_string, "AES-CTR"_string); define_an_algorithm("generateKey"_string, "AES-CTR"_string); + // https://w3c.github.io/webcrypto/#aes-gcm-registration + define_an_algorithm("get key length"_string, "AES-GCM"_string); + // https://w3c.github.io/webcrypto/#hkdf define_an_algorithm("importKey"_string, "HKDF"_string); define_an_algorithm("deriveBits"_string, "HKDF"_string);