TianoCore EDK2 master
Loading...
Searching...
No Matches
MemLibWrapper.c File Reference
#include <Library/BaseLib.h>
#include <Library/DebugLib.h>
#include <Library/BaseMemoryLib.h>
#include "hal/base.h"
#include "hal/library/memlib.h"

Go to the source code of this file.

Functions

void libspdm_copy_mem (void *dst_buf, size_t dst_len, const void *src_buf, size_t src_len)
 
void libspdm_set_mem (void *buffer, size_t length, uint8_t value)
 
void libspdm_zero_mem (void *buffer, size_t length)
 
bool libspdm_consttime_is_mem_equal (const void *destination_buffer, const void *source_buffer, size_t length)
 

Detailed Description

EDKII Device Security library for SPDM device. It follows the SPDM Specification.

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

Definition in file MemLibWrapper.c.

Function Documentation

◆ libspdm_consttime_is_mem_equal()

bool libspdm_consttime_is_mem_equal ( const void *  destination_buffer,
const void *  source_buffer,
size_t  length 
)

Compares the contents of two buffers in const time.

This function compares length bytes of source_buffer to length bytes of destination_buffer. If all length bytes of the two buffers are identical, then 0 is returned. Otherwise, the value returned is the first mismatched byte in source_buffer subtracted from the first mismatched byte in destination_buffer.

If length > 0 and destination_buffer is NULL, then ASSERT(). If length > 0 and source_buffer is NULL, then ASSERT(). If length is greater than (MAX_ADDRESS - destination_buffer + 1), then ASSERT(). If length is greater than (MAX_ADDRESS - source_buffer + 1), then ASSERT().

Parameters
destination_bufferA pointer to the destination buffer to compare.
source_bufferA pointer to the source buffer to compare.
lengthThe number of bytes to compare.
Returns
0 All length bytes of the two buffers are identical.
Return values
Non-zeroThere is mismatched between source_buffer and destination_buffer.

Definition at line 166 of file MemLibWrapper.c.

◆ libspdm_copy_mem()

void libspdm_copy_mem ( void *  dst_buf,
size_t  dst_len,
const void *  src_buf,
size_t  src_len 
)

Copies bytes from a source buffer to a destination buffer.

This function copies "src_len" bytes from "src_buf" to "dst_buf".

Asserts and returns a non-zero value if any of the following are true: 1) "src_buf" or "dst_buf" are NULL. 2) "src_len" or "dst_len" is greater than (SIZE_MAX >> 1). 3) "src_len" is greater than "dst_len". 4) "src_buf" and "dst_buf" overlap.

If any of these cases fail, a non-zero value is returned. Additionally if "dst_buf" points to a non-NULL value and "dst_len" is valid, then "dst_len" bytes of "dst_buf" are zeroed.

This function follows the C11 cppreference description of memcpy_s. https://en.cppreference.com/w/c/string/byte/memcpy The cppreferece description does NOT allow the source or destination buffers to be NULL.

This function differs from the Microsoft and Safeclib memcpy_s implementations in that the Microsoft and Safeclib implementations allow for NULL source and destinations pointers when the number of bytes to copy (src_len) is zero.

In addition the Microsoft and Safeclib memcpy_s functions return different negative values on error. For best support, clients should generally check against zero for success or failure.

Parameters
dst_bufDestination buffer to copy to.
dst_lenMaximum length in bytes of the destination buffer.
src_bufSource buffer to copy from.
src_lenThe number of bytes to copy from the source buffer.
Returns
0 on success. non-zero on error.

Definition at line 53 of file MemLibWrapper.c.

◆ libspdm_set_mem()

void libspdm_set_mem ( void *  buffer,
size_t  length,
uint8_t  value 
)

Fills a target buffer with a byte value, and returns the target buffer.

This function fills length bytes of buffer with value, and returns buffer.

If length is greater than (MAX_ADDRESS - buffer + 1), then ASSERT().

Parameters
bufferThe memory to set.
lengthThe number of bytes to set.
valueThe value with which to fill length bytes of buffer.
Returns
buffer.

Definition at line 112 of file MemLibWrapper.c.

◆ libspdm_zero_mem()

void libspdm_zero_mem ( void *  buffer,
size_t  length 
)

Fills a target buffer with zeros, and returns the target buffer.

This function fills length bytes of buffer with zeros, and returns buffer.

If length > 0 and buffer is NULL, then ASSERT(). If length is greater than (MAX_ADDRESS - buffer + 1), then ASSERT().

Parameters
bufferThe pointer to the target buffer to fill with zeros.
lengthThe number of bytes in buffer to fill with zeros.
Returns
buffer.

Definition at line 136 of file MemLibWrapper.c.