2024-10-20 04:56:45 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2023, stelar7 <dudedbz@gmail.com>
|
|
|
|
|
* Copyright (c) 2024, Ben Wiederhake <BenWiederhake.GitHub@gmx.de>
|
2025-02-16 17:38:58 +01:00
|
|
|
* Copyright (c) 2025, Altomani Gianluca <altomanigianluca@gmail.com>
|
2024-10-20 04:56:45 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2025-02-16 17:38:58 +01:00
|
|
|
#include <LibCrypto/Hash/HashManager.h>
|
2024-10-20 04:56:45 +02:00
|
|
|
|
|
|
|
|
namespace Crypto::Hash {
|
|
|
|
|
|
|
|
|
|
class HKDF {
|
|
|
|
|
public:
|
2025-02-16 17:38:58 +01:00
|
|
|
HKDF(HashKind hash_kind);
|
2024-10-20 04:56:45 +02:00
|
|
|
|
2025-02-16 17:38:58 +01:00
|
|
|
~HKDF()
|
2024-10-20 04:56:45 +02:00
|
|
|
{
|
2025-02-16 17:38:58 +01:00
|
|
|
EVP_KDF_free(m_kdf);
|
2024-10-20 04:56:45 +02:00
|
|
|
}
|
|
|
|
|
|
2025-02-16 17:38:58 +01:00
|
|
|
// Note: The output is different for a salt of length zero and an absent salt,
|
|
|
|
|
// so Optional<ReadonlyBytes> really is the correct type.
|
|
|
|
|
ErrorOr<ByteBuffer> derive_key(Optional<ReadonlyBytes> maybe_salt, ReadonlyBytes input_keying_material, ReadonlyBytes info, u32 key_length_bytes);
|
|
|
|
|
|
2024-10-20 04:56:45 +02:00
|
|
|
private:
|
2025-02-16 17:38:58 +01:00
|
|
|
EVP_KDF* m_kdf;
|
|
|
|
|
HashKind m_hash_kind;
|
2024-10-20 04:56:45 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|