mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-05 08:31:51 +00:00
LibCrypto: Refactor HMAC
implementations with OpenSSL
This commit is contained in:
parent
c5d0af54d0
commit
80fe259dab
Notes:
github-actions[bot]
2025-03-02 14:12:54 +00:00
Author: https://github.com/devgianlu
Commit: 80fe259dab
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3749
Reviewed-by: https://github.com/konradekk
7 changed files with 153 additions and 123 deletions
|
@ -7781,21 +7781,21 @@ WebIDL::ExceptionOr<GC::Ref<CryptoKey>> X448::import_key(
|
|||
|
||||
static WebIDL::ExceptionOr<ByteBuffer> hmac_calculate_message_digest(JS::Realm& realm, GC::Ptr<KeyAlgorithm> hash, ReadonlyBytes key, ReadonlyBytes message)
|
||||
{
|
||||
auto calculate_digest = [&]<typename T>() -> ByteBuffer {
|
||||
::Crypto::Authentication::HMAC<T> hmac(key);
|
||||
auto digest = hmac.process(message);
|
||||
return MUST(ByteBuffer::copy(digest.bytes()));
|
||||
};
|
||||
auto hash_name = hash->name();
|
||||
if (hash_name == "SHA-1")
|
||||
return calculate_digest.operator()<::Crypto::Hash::SHA1>();
|
||||
if (hash_name == "SHA-256")
|
||||
return calculate_digest.operator()<::Crypto::Hash::SHA256>();
|
||||
if (hash_name == "SHA-384")
|
||||
return calculate_digest.operator()<::Crypto::Hash::SHA384>();
|
||||
if (hash_name == "SHA-512")
|
||||
return calculate_digest.operator()<::Crypto::Hash::SHA512>();
|
||||
return WebIDL::NotSupportedError::create(realm, "Invalid algorithm"_string);
|
||||
auto hash_kind = TRY([&] -> WebIDL::ExceptionOr<::Crypto::Hash::HashKind> {
|
||||
if (hash_name == "SHA-1")
|
||||
return ::Crypto::Hash::HashKind::SHA1;
|
||||
if (hash_name == "SHA-256")
|
||||
return ::Crypto::Hash::HashKind::SHA256;
|
||||
if (hash_name == "SHA-384")
|
||||
return ::Crypto::Hash::HashKind::SHA384;
|
||||
if (hash_name == "SHA-512")
|
||||
return ::Crypto::Hash::HashKind::SHA512;
|
||||
return WebIDL::NotSupportedError::create(realm, MUST(String::formatted("Invalid hash function '{}'", hash_name)));
|
||||
}());
|
||||
|
||||
::Crypto::Authentication::HMAC hmac(hash_kind, key);
|
||||
return hmac.process(message);
|
||||
}
|
||||
|
||||
static WebIDL::ExceptionOr<WebIDL::UnsignedLong> hmac_hash_block_size(JS::Realm& realm, HashAlgorithmIdentifier hash)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue