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

Go to the source code of this file.

Functions

STATIC VOID * HmacMdNew (VOID)
 
VOID HmacMdFree (IN VOID *HmacMdCtx)
 
STATIC BOOLEAN HmacMdSetKey (IN mbedtls_md_type_t MdType, OUT VOID *HmacMdContext, IN CONST UINT8 *Key, IN UINTN KeySize)
 
int HmacMdGetBlockSize (mbedtls_md_type_t MdType)
 
STATIC BOOLEAN HmacMdDuplicate (IN CONST mbedtls_md_type_t MdType, 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 mbedtls_md_type_t MdType, 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 Wrapper Implementation over MbedTLS.

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

Definition in file CryptHmac.c.

Function Documentation

◆ HmacMdAll()

STATIC BOOLEAN HmacMdAll ( IN mbedtls_md_type_t  MdType,
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]MdTypeMessage Digest Type.
[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 307 of file CryptHmac.c.

◆ HmacMdDuplicate()

STATIC BOOLEAN HmacMdDuplicate ( IN CONST mbedtls_md_type_t  MdType,
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]MdTypemessage digest Type.
[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 142 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 260 of file CryptHmac.c.

◆ HmacMdFree()

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 42 of file CryptHmac.c.

◆ HmacMdGetBlockSize()

int HmacMdGetBlockSize ( mbedtls_md_type_t  MdType)

Return block size in md_type.

Parameters
[in]MdTypemessage digest Type.
Return values
blocksizein md_type.

Definition at line 111 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, HmacShaMdNew() returns NULL.

Definition at line 21 of file CryptHmac.c.

◆ HmacMdSetKey()

STATIC BOOLEAN HmacMdSetKey ( IN mbedtls_md_type_t  MdType,
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]MdTypeMessage Digest Type.
[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 69 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 210 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 490 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 401 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 460 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 354 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 339 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 377 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 429 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 669 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 576 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 639 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 525 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 510 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 550 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 606 of file CryptHmac.c.