TianoCore EDK2 master
Loading...
Searching...
No Matches
CryptHmac.c File Reference
#include "InternalCryptLib.h"
#include <openssl/hmac.h>

Go to the source code of this file.

Functions

STATIC VOID * HmacMdNew (VOID)
 
STATIC VOID HmacMdFree (IN VOID *HmacMdCtx)
 
STATIC BOOLEAN HmacMdSetKey (IN CONST EVP_MD *Md, OUT VOID *HmacMdContext, IN CONST UINT8 *Key, IN UINTN KeySize)
 
STATIC BOOLEAN HmacMdDuplicate (IN CONST VOID *HmacMdContext, OUT VOID *NewHmacMdContext)
 
STATIC BOOLEAN HmacMdUpdate (IN OUT VOID *HmacMdContext, IN CONST VOID *Data, IN UINTN DataSize)
 
STATIC BOOLEAN HmacMdFinal (IN OUT VOID *HmacMdContext, OUT UINT8 *HmacValue)
 
STATIC BOOLEAN HmacMdAll (IN CONST EVP_MD *Md, IN CONST VOID *Data, IN UINTN DataSize, IN CONST UINT8 *Key, IN UINTN KeySize, OUT UINT8 *HmacValue)
 
VOID *EFIAPI HmacSha256New (VOID)
 
VOID EFIAPI HmacSha256Free (IN VOID *HmacSha256Ctx)
 
BOOLEAN EFIAPI HmacSha256SetKey (OUT VOID *HmacSha256Context, IN CONST UINT8 *Key, IN UINTN KeySize)
 
BOOLEAN EFIAPI HmacSha256Duplicate (IN CONST VOID *HmacSha256Context, OUT VOID *NewHmacSha256Context)
 
BOOLEAN EFIAPI HmacSha256Update (IN OUT VOID *HmacSha256Context, IN CONST VOID *Data, IN UINTN DataSize)
 
BOOLEAN EFIAPI HmacSha256Final (IN OUT VOID *HmacSha256Context, OUT UINT8 *HmacValue)
 
BOOLEAN EFIAPI HmacSha256All (IN CONST VOID *Data, IN UINTN DataSize, IN CONST UINT8 *Key, IN UINTN KeySize, OUT UINT8 *HmacValue)
 
VOID *EFIAPI HmacSha384New (VOID)
 
VOID EFIAPI HmacSha384Free (IN VOID *HmacSha384Ctx)
 
BOOLEAN EFIAPI HmacSha384SetKey (OUT VOID *HmacSha384Context, IN CONST UINT8 *Key, IN UINTN KeySize)
 
BOOLEAN EFIAPI HmacSha384Duplicate (IN CONST VOID *HmacSha384Context, OUT VOID *NewHmacSha384Context)
 
BOOLEAN EFIAPI HmacSha384Update (IN OUT VOID *HmacSha384Context, IN CONST VOID *Data, IN UINTN DataSize)
 
BOOLEAN EFIAPI HmacSha384Final (IN OUT VOID *HmacSha384Context, OUT UINT8 *HmacValue)
 
BOOLEAN EFIAPI HmacSha384All (IN CONST VOID *Data, IN UINTN DataSize, IN CONST UINT8 *Key, IN UINTN KeySize, OUT UINT8 *HmacValue)
 

Detailed Description

HMAC-SHA256/SHA384 Wrapper Implementation over OpenSSL.

Copyright (c) 2016 - 2022, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file CryptHmac.c.

Function Documentation

◆ HmacMdAll()

STATIC BOOLEAN HmacMdAll ( IN CONST EVP_MD *  Md,
IN CONST VOID *  Data,
IN UINTN  DataSize,
IN CONST UINT8 *  Key,
IN UINTN  KeySize,
OUT UINT8 *  HmacValue 
)

Computes the HMAC-MD digest of a input data buffer.

This function performs the HMAC-MD digest of a given data buffer, and places the digest value into the specified memory.

If this interface is not supported, then return FALSE.

Parameters
[in]MdMessage Digest.
[in]DataPointer to the buffer containing the data to be digested.
[in]DataSizeSize of Data buffer in bytes.
[in]KeyPointer to the user-supplied key.
[in]KeySizeKey size in bytes.
[out]HmacValuePointer to a buffer that receives the HMAC-MD digest value.
Return values
TRUEHMAC-MD digest computation succeeded.
FALSEHMAC-MD digest computation failed.
FALSEThis interface is not supported.

Definition at line 244 of file CryptHmac.c.

◆ HmacMdDuplicate()

STATIC BOOLEAN HmacMdDuplicate ( IN CONST VOID *  HmacMdContext,
OUT VOID *  NewHmacMdContext 
)

Makes a copy of an existing HMAC-MD context.

If HmacMdContext is NULL, then return FALSE. If NewHmacMdContext is NULL, then return FALSE.

Parameters
[in]HmacMdContextPointer to HMAC-MD context being copied.
[out]NewHmacMdContextPointer to new HMAC-MD context.
Return values
TRUEHMAC-MD context copy succeeded.
FALSEHMAC-MD context copy failed.

Definition at line 102 of file CryptHmac.c.

◆ HmacMdFinal()

STATIC BOOLEAN HmacMdFinal ( IN OUT VOID *  HmacMdContext,
OUT UINT8 *  HmacValue 
)

Completes computation of the HMAC-MD digest value.

This function completes HMAC-MD hash computation and retrieves the digest value into the specified memory. After this function has been called, the HMAC-MD context cannot be used again. HMAC-MD context should be initialized by HmacMdNew(), and should not be finalized by HmacMdFinal(). Behavior with invalid HMAC-MD context is undefined.

If HmacMdContext is NULL, then return FALSE. If HmacValue is NULL, then return FALSE.

Parameters
[in,out]HmacMdContextPointer to the HMAC-MD context.
[out]HmacValuePointer to a buffer that receives the HMAC-MD digest value.
Return values
TRUEHMAC-MD digest computation succeeded.
FALSEHMAC-MD digest computation failed.

Definition at line 193 of file CryptHmac.c.

◆ HmacMdFree()

STATIC VOID HmacMdFree ( IN VOID *  HmacMdCtx)

Release the specified HMAC_CTX context.

Parameters
[in]HmacMdCtxPointer to the HMAC_CTX context to be released.

Definition at line 39 of file CryptHmac.c.

◆ HmacMdNew()

STATIC VOID * HmacMdNew ( VOID  )

Allocates and initializes one HMAC_CTX context for subsequent HMAC-MD use.

Returns
Pointer to the HMAC_CTX context that has been initialized. If the allocations fails, HmacMdNew() returns NULL.

Definition at line 21 of file CryptHmac.c.

◆ HmacMdSetKey()

STATIC BOOLEAN HmacMdSetKey ( IN CONST EVP_MD *  Md,
OUT VOID *  HmacMdContext,
IN CONST UINT8 *  Key,
IN UINTN  KeySize 
)

Set user-supplied key for subsequent use. It must be done before any calling to HmacMdUpdate().

If HmacMdContext is NULL, then return FALSE.

Parameters
[in]MdMessage Digest.
[out]HmacMdContextPointer to HMAC-MD context.
[in]KeyPointer to the user-supplied key.
[in]KeySizeKey size in bytes.
Return values
TRUEThe Key is set successfully.
FALSEThe Key is set unsuccessfully.

Definition at line 66 of file CryptHmac.c.

◆ HmacMdUpdate()

STATIC BOOLEAN HmacMdUpdate ( IN OUT VOID *  HmacMdContext,
IN CONST VOID *  Data,
IN UINTN  DataSize 
)

Digests the input data and updates HMAC-MD context.

This function performs HMAC-MD digest on a data buffer of the specified size. It can be called multiple times to compute the digest of long or discontinuous data streams. HMAC-MD context should be initialized by HmacMdNew(), and should not be finalized by HmacMdFinal(). Behavior with invalid context is undefined.

If HmacMdContext is NULL, then return FALSE.

Parameters
[in,out]HmacMdContextPointer to the HMAC-MD context.
[in]DataPointer to the buffer containing the data to be digested.
[in]DataSizeSize of Data buffer in bytes.
Return values
TRUEHMAC-MD data digest succeeded.
FALSEHMAC-MD data digest failed.

Definition at line 141 of file CryptHmac.c.

◆ HmacSha256All()

BOOLEAN EFIAPI HmacSha256All ( IN CONST VOID *  Data,
IN UINTN  DataSize,
IN CONST UINT8 *  Key,
IN UINTN  KeySize,
OUT UINT8 *  HmacValue 
)

Computes the HMAC-SHA256 digest of a input data buffer.

This function performs the HMAC-SHA256 digest of a given data buffer, and places the digest value into the specified memory.

If this interface is not supported, then return FALSE.

Parameters
[in]DataPointer to the buffer containing the data to be digested.
[in]DataSizeSize of Data buffer in bytes.
[in]KeyPointer to the user-supplied key.
[in]KeySizeKey size in bytes.
[out]HmacValuePointer to a buffer that receives the HMAC-SHA256 digest value (32 bytes).
Return values
TRUEHMAC-SHA256 digest computation succeeded.
FALSEHMAC-SHA256 digest computation failed.
FALSEThis interface is not supported.

Definition at line 448 of file CryptHmac.c.

◆ HmacSha256Duplicate()

BOOLEAN EFIAPI HmacSha256Duplicate ( IN CONST VOID *  HmacSha256Context,
OUT VOID *  NewHmacSha256Context 
)

Makes a copy of an existing HMAC-SHA256 context.

If HmacSha256Context is NULL, then return FALSE. If NewHmacSha256Context is NULL, then return FALSE.

Parameters
[in]HmacSha256ContextPointer to HMAC-SHA256 context being copied.
[out]NewHmacSha256ContextPointer to new HMAC-SHA256 context.
Return values
TRUEHMAC-SHA256 context copy succeeded.
FALSEHMAC-SHA256 context copy failed.

Definition at line 359 of file CryptHmac.c.

◆ HmacSha256Final()

BOOLEAN EFIAPI HmacSha256Final ( IN OUT VOID *  HmacSha256Context,
OUT UINT8 *  HmacValue 
)

Completes computation of the HMAC-SHA256 digest value.

This function completes HMAC-SHA256 hash computation and retrieves the digest value into the specified memory. After this function has been called, the HMAC-SHA256 context cannot be used again. HMAC-SHA256 context should be initialized by HmacSha256New(), and should not be finalized by HmacSha256Final(). Behavior with invalid HMAC-SHA256 context is undefined.

If HmacSha256Context is NULL, then return FALSE. If HmacValue is NULL, then return FALSE.

Parameters
[in,out]HmacSha256ContextPointer to the HMAC-SHA256 context.
[out]HmacValuePointer to a buffer that receives the HMAC-SHA256 digest value (32 bytes).
Return values
TRUEHMAC-SHA256 digest computation succeeded.
FALSEHMAC-SHA256 digest computation failed.

Definition at line 418 of file CryptHmac.c.

◆ HmacSha256Free()

VOID EFIAPI HmacSha256Free ( IN VOID *  HmacSha256Ctx)

Release the specified HMAC_CTX context.

Parameters
[in]HmacSha256CtxPointer to the HMAC_CTX context to be released.

Definition at line 312 of file CryptHmac.c.

◆ HmacSha256New()

VOID *EFIAPI HmacSha256New ( VOID  )

Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA256 use.

Returns
Pointer to the HMAC_CTX context that has been initialized. If the allocations fails, HmacSha256New() returns NULL.

Definition at line 297 of file CryptHmac.c.

◆ HmacSha256SetKey()

BOOLEAN EFIAPI HmacSha256SetKey ( OUT VOID *  HmacSha256Context,
IN CONST UINT8 *  Key,
IN UINTN  KeySize 
)

Set user-supplied key for subsequent use. It must be done before any calling to HmacSha256Update().

If HmacSha256Context is NULL, then return FALSE.

Parameters
[out]HmacSha256ContextPointer to HMAC-SHA256 context.
[in]KeyPointer to the user-supplied key.
[in]KeySizeKey size in bytes.
Return values
TRUEThe Key is set successfully.
FALSEThe Key is set unsuccessfully.

Definition at line 335 of file CryptHmac.c.

◆ HmacSha256Update()

BOOLEAN EFIAPI HmacSha256Update ( IN OUT VOID *  HmacSha256Context,
IN CONST VOID *  Data,
IN UINTN  DataSize 
)

Digests the input data and updates HMAC-SHA256 context.

This function performs HMAC-SHA256 digest on a data buffer of the specified size. It can be called multiple times to compute the digest of long or discontinuous data streams. HMAC-SHA256 context should be initialized by HmacSha256New(), and should not be finalized by HmacSha256Final(). Behavior with invalid context is undefined.

If HmacSha256Context is NULL, then return FALSE.

Parameters
[in,out]HmacSha256ContextPointer to the HMAC-SHA256 context.
[in]DataPointer to the buffer containing the data to be digested.
[in]DataSizeSize of Data buffer in bytes.
Return values
TRUEHMAC-SHA256 data digest succeeded.
FALSEHMAC-SHA256 data digest failed.

Definition at line 387 of file CryptHmac.c.

◆ HmacSha384All()

BOOLEAN EFIAPI HmacSha384All ( IN CONST VOID *  Data,
IN UINTN  DataSize,
IN CONST UINT8 *  Key,
IN UINTN  KeySize,
OUT UINT8 *  HmacValue 
)

Computes the HMAC-SHA384 digest of a input data buffer.

This function performs the HMAC-SHA384 digest of a given data buffer, and places the digest value into the specified memory.

If this interface is not supported, then return FALSE.

Parameters
[in]DataPointer to the buffer containing the data to be digested.
[in]DataSizeSize of Data buffer in bytes.
[in]KeyPointer to the user-supplied key.
[in]KeySizeKey size in bytes.
[out]HmacValuePointer to a buffer that receives the HMAC-SHA384 digest value (48 bytes).
Return values
TRUEHMAC-SHA384 digest computation succeeded.
FALSEHMAC-SHA384 digest computation failed.
FALSEThis interface is not supported.

Definition at line 627 of file CryptHmac.c.

◆ HmacSha384Duplicate()

BOOLEAN EFIAPI HmacSha384Duplicate ( IN CONST VOID *  HmacSha384Context,
OUT VOID *  NewHmacSha384Context 
)

Makes a copy of an existing HMAC-SHA384 context.

If HmacSha384Context is NULL, then return FALSE. If NewHmacSha384Context is NULL, then return FALSE. If this interface is not supported, then return FALSE.

Parameters
[in]HmacSha384ContextPointer to HMAC-SHA384 context being copied.
[out]NewHmacSha384ContextPointer to new HMAC-SHA384 context.
Return values
TRUEHMAC-SHA384 context copy succeeded.
FALSEHMAC-SHA384 context copy failed.
FALSEThis interface is not supported.

Definition at line 534 of file CryptHmac.c.

◆ HmacSha384Final()

BOOLEAN EFIAPI HmacSha384Final ( IN OUT VOID *  HmacSha384Context,
OUT UINT8 *  HmacValue 
)

Completes computation of the HMAC-SHA384 digest value.

This function completes HMAC-SHA384 hash computation and retrieves the digest value into the specified memory. After this function has been called, the HMAC-SHA384 context cannot be used again. HMAC-SHA384 context should be initialized by HmacSha384New(), and should not be finalized by HmacSha384Final(). Behavior with invalid HMAC-SHA384 context is undefined.

If HmacSha384Context is NULL, then return FALSE. If HmacValue is NULL, then return FALSE. If this interface is not supported, then return FALSE.

Parameters
[in,out]HmacSha384ContextPointer to the HMAC-SHA384 context.
[out]HmacValuePointer to a buffer that receives the HMAC-SHA384 digest value (48 bytes).
Return values
TRUEHMAC-SHA384 digest computation succeeded.
FALSEHMAC-SHA384 digest computation failed.
FALSEThis interface is not supported.

Definition at line 597 of file CryptHmac.c.

◆ HmacSha384Free()

VOID EFIAPI HmacSha384Free ( IN VOID *  HmacSha384Ctx)

Release the specified HMAC_CTX context.

Parameters
[in]HmacSha384CtxPointer to the HMAC_CTX context to be released.

Definition at line 483 of file CryptHmac.c.

◆ HmacSha384New()

VOID *EFIAPI HmacSha384New ( VOID  )

Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA384 use.

Returns
Pointer to the HMAC_CTX context that has been initialized. If the allocations fails, HmacSha384New() returns NULL.

Definition at line 468 of file CryptHmac.c.

◆ HmacSha384SetKey()

BOOLEAN EFIAPI HmacSha384SetKey ( OUT VOID *  HmacSha384Context,
IN CONST UINT8 *  Key,
IN UINTN  KeySize 
)

Set user-supplied key for subsequent use. It must be done before any calling to HmacSha384Update().

If HmacSha384Context is NULL, then return FALSE. If this interface is not supported, then return FALSE.

Parameters
[out]HmacSha384ContextPointer to HMAC-SHA384 context.
[in]KeyPointer to the user-supplied key.
[in]KeySizeKey size in bytes.
Return values
TRUEThe Key is set successfully.
FALSEThe Key is set unsuccessfully.
FALSEThis interface is not supported.

Definition at line 508 of file CryptHmac.c.

◆ HmacSha384Update()

BOOLEAN EFIAPI HmacSha384Update ( IN OUT VOID *  HmacSha384Context,
IN CONST VOID *  Data,
IN UINTN  DataSize 
)

Digests the input data and updates HMAC-SHA384 context.

This function performs HMAC-SHA384 digest on a data buffer of the specified size. It can be called multiple times to compute the digest of long or discontinuous data streams. HMAC-SHA384 context should be initialized by HmacSha384New(), and should not be finalized by HmacSha384Final(). Behavior with invalid context is undefined.

If HmacSha384Context is NULL, then return FALSE. If this interface is not supported, then return FALSE.

Parameters
[in,out]HmacSha384ContextPointer to the HMAC-SHA384 context.
[in]DataPointer to the buffer containing the data to be digested.
[in]DataSizeSize of Data buffer in bytes.
Return values
TRUEHMAC-SHA384 data digest succeeded.
FALSEHMAC-SHA384 data digest failed.
FALSEThis interface is not supported.

Definition at line 564 of file CryptHmac.c.