mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-21 02:22:51 +00:00
LibWeb: Use correct default key size for HMAC
When the default key size was requested it was expressed in bytes (instead of bits) and from the digest size instead of the block size.
This commit is contained in:
parent
f5d3d6a7d4
commit
819178a49e
Notes:
github-actions[bot]
2025-01-02 10:38:40 +00:00
Author: https://github.com/devgianlu
Commit: 819178a49e
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3092
2 changed files with 103 additions and 104 deletions
|
@ -6111,13 +6111,13 @@ static WebIDL::ExceptionOr<WebIDL::UnsignedLong> hmac_hash_block_size(JS::Realm&
|
|||
{
|
||||
auto hash_name = TRY(hash.name(realm.vm()));
|
||||
if (hash_name == "SHA-1")
|
||||
return ::Crypto::Hash::SHA1::digest_size();
|
||||
return ::Crypto::Hash::SHA1::block_size();
|
||||
if (hash_name == "SHA-256")
|
||||
return ::Crypto::Hash::SHA256::digest_size();
|
||||
return ::Crypto::Hash::SHA256::block_size();
|
||||
if (hash_name == "SHA-384")
|
||||
return ::Crypto::Hash::SHA384::digest_size();
|
||||
return ::Crypto::Hash::SHA384::block_size();
|
||||
if (hash_name == "SHA-512")
|
||||
return ::Crypto::Hash::SHA512::digest_size();
|
||||
return ::Crypto::Hash::SHA512::block_size();
|
||||
return WebIDL::NotSupportedError::create(realm, MUST(String::formatted("Invalid hash function '{}'", hash_name)));
|
||||
}
|
||||
|
||||
|
@ -6166,7 +6166,7 @@ WebIDL::ExceptionOr<Variant<GC::Ref<CryptoKey>, GC::Ref<CryptoKeyPair>>> HMAC::g
|
|||
if (!normalized_algorithm.length.has_value()) {
|
||||
// Let length be the block size in bits of the hash function identified by the hash member
|
||||
// of normalizedAlgorithm.
|
||||
length = TRY(hmac_hash_block_size(m_realm, normalized_algorithm.hash));
|
||||
length = TRY(hmac_hash_block_size(m_realm, normalized_algorithm.hash)) * 8;
|
||||
}
|
||||
|
||||
// Otherwise, if the length member of normalizedAlgorithm is non-zero:
|
||||
|
@ -6488,7 +6488,7 @@ WebIDL::ExceptionOr<JS::Value> HMAC::get_key_length(AlgorithmParams const& param
|
|||
if (!normalized_derived_key_algorithm.length.has_value()) {
|
||||
// Let length be the block size in bits of the hash function identified by the hash member of
|
||||
// normalizedDerivedKeyAlgorithm.
|
||||
length = TRY(hmac_hash_block_size(m_realm, normalized_derived_key_algorithm.hash));
|
||||
length = TRY(hmac_hash_block_size(m_realm, normalized_derived_key_algorithm.hash)) * 8;
|
||||
}
|
||||
|
||||
// Otherwise, if the length member of normalizedDerivedKeyAlgorithm is non-zero:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue