9#include "InternalCryptLib.h"
10#include <openssl/evp.h>
11#include <openssl/kdf.h>
44 EVP_PKEY_CTX *pHkdfCtx;
48 (KeySize > INT_MAX) || (SaltSize > INT_MAX) || (InfoSize > INT_MAX) || (OutSize > INT_MAX))
53 pHkdfCtx = EVP_PKEY_CTX_new_id (EVP_PKEY_HKDF,
NULL);
54 if (pHkdfCtx ==
NULL) {
58 Result = EVP_PKEY_derive_init (pHkdfCtx) > 0;
60 Result = EVP_PKEY_CTX_set_hkdf_md (pHkdfCtx, Md) > 0;
64 Result = EVP_PKEY_CTX_set1_hkdf_salt (pHkdfCtx, Salt, (UINT32)SaltSize) > 0;
68 Result = EVP_PKEY_CTX_set1_hkdf_key (pHkdfCtx, Key, (UINT32)KeySize) > 0;
72 Result = EVP_PKEY_CTX_add1_hkdf_info (pHkdfCtx, Info, (UINT32)InfoSize) > 0;
76 Result = EVP_PKEY_derive (pHkdfCtx, Out, &OutSize) > 0;
79 EVP_PKEY_CTX_free (pHkdfCtx);
111 EVP_PKEY_CTX *pHkdfCtx;
114 if ((Key ==
NULL) || (Salt ==
NULL) || (PrkOut ==
NULL) ||
115 (KeySize > INT_MAX) || (SaltSize > INT_MAX) ||
116 (PrkOutSize > INT_MAX))
121 pHkdfCtx = EVP_PKEY_CTX_new_id (EVP_PKEY_HKDF,
NULL);
122 if (pHkdfCtx ==
NULL) {
126 Result = EVP_PKEY_derive_init (pHkdfCtx) > 0;
128 Result = EVP_PKEY_CTX_set_hkdf_md (pHkdfCtx, Md) > 0;
133 EVP_PKEY_CTX_hkdf_mode (
135 EVP_PKEY_HKDEF_MODE_EXTRACT_ONLY
140 Result = EVP_PKEY_CTX_set1_hkdf_salt (
148 Result = EVP_PKEY_CTX_set1_hkdf_key (
156 Result = EVP_PKEY_derive (pHkdfCtx, PrkOut, &PrkOutSize) > 0;
159 EVP_PKEY_CTX_free (pHkdfCtx);
191 EVP_PKEY_CTX *pHkdfCtx;
195 (PrkSize > INT_MAX) || (InfoSize > INT_MAX) || (OutSize > INT_MAX))
200 pHkdfCtx = EVP_PKEY_CTX_new_id (EVP_PKEY_HKDF,
NULL);
201 if (pHkdfCtx ==
NULL) {
205 Result = EVP_PKEY_derive_init (pHkdfCtx) > 0;
207 Result = EVP_PKEY_CTX_set_hkdf_md (pHkdfCtx, Md) > 0;
211 Result = EVP_PKEY_CTX_hkdf_mode (pHkdfCtx, EVP_PKEY_HKDEF_MODE_EXPAND_ONLY) > 0;
215 Result = EVP_PKEY_CTX_set1_hkdf_key (pHkdfCtx, Prk, (UINT32)PrkSize) > 0;
219 Result = EVP_PKEY_CTX_add1_hkdf_info (pHkdfCtx, Info, (UINT32)InfoSize) > 0;
223 Result = EVP_PKEY_derive (pHkdfCtx, Out, &OutSize) > 0;
226 EVP_PKEY_CTX_free (pHkdfCtx);
260 return HkdfMdExtractAndExpand (EVP_sha256 (), Key, KeySize, Salt, SaltSize, Info, InfoSize, Out, OutSize);
324 return HkdfMdExpand (EVP_sha256 (), Prk, PrkSize, Info, InfoSize, Out, OutSize);
356 return HkdfMdExtractAndExpand (EVP_sha384 (), Key, KeySize, Salt, SaltSize, Info, InfoSize, Out, OutSize);
420 return HkdfMdExpand (EVP_sha384 (), Prk, PrkSize, Info, InfoSize, Out, OutSize);
BOOLEAN EFIAPI HkdfSha256Extract(IN CONST UINT8 *Key, IN UINTN KeySize, IN CONST UINT8 *Salt, IN UINTN SaltSize, OUT UINT8 *PrkOut, UINTN PrkOutSize)
STATIC BOOLEAN HkdfMdExpand(IN CONST EVP_MD *Md, IN CONST UINT8 *Prk, IN UINTN PrkSize, IN CONST UINT8 *Info, IN UINTN InfoSize, OUT UINT8 *Out, IN UINTN OutSize)
BOOLEAN EFIAPI HkdfSha384ExtractAndExpand(IN CONST UINT8 *Key, IN UINTN KeySize, IN CONST UINT8 *Salt, IN UINTN SaltSize, IN CONST UINT8 *Info, IN UINTN InfoSize, OUT UINT8 *Out, IN UINTN OutSize)
STATIC BOOLEAN HkdfMdExtractAndExpand(IN CONST EVP_MD *Md, IN CONST UINT8 *Key, IN UINTN KeySize, IN CONST UINT8 *Salt, IN UINTN SaltSize, IN CONST UINT8 *Info, IN UINTN InfoSize, OUT UINT8 *Out, IN UINTN OutSize)
BOOLEAN EFIAPI HkdfSha384Extract(IN CONST UINT8 *Key, IN UINTN KeySize, IN CONST UINT8 *Salt, IN UINTN SaltSize, OUT UINT8 *PrkOut, UINTN PrkOutSize)
STATIC BOOLEAN HkdfMdExtract(IN CONST EVP_MD *Md, IN CONST UINT8 *Key, IN UINTN KeySize, IN CONST UINT8 *Salt, IN UINTN SaltSize, OUT UINT8 *PrkOut, UINTN PrkOutSize)
BOOLEAN EFIAPI HkdfSha256Expand(IN CONST UINT8 *Prk, IN UINTN PrkSize, IN CONST UINT8 *Info, IN UINTN InfoSize, OUT UINT8 *Out, IN UINTN OutSize)
BOOLEAN EFIAPI HkdfSha256ExtractAndExpand(IN CONST UINT8 *Key, IN UINTN KeySize, IN CONST UINT8 *Salt, IN UINTN SaltSize, IN CONST UINT8 *Info, IN UINTN InfoSize, OUT UINT8 *Out, IN UINTN OutSize)
BOOLEAN EFIAPI HkdfSha384Expand(IN CONST UINT8 *Prk, IN UINTN PrkSize, IN CONST UINT8 *Info, IN UINTN InfoSize, OUT UINT8 *Out, IN UINTN OutSize)