1 /**
2  *  Copyright Notice:
3  *  Copyright 2021-2022 DMTF. All rights reserved.
4  *  License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
5  **/
6 
7 /**
8  * Provides memory copy, fill, and comparison.
9  **/
10 
11 #ifndef MEMLIB_H
12 #define MEMLIB_H
13 
14 #include "hal/base.h"
15 
16 /**
17  * Copies bytes from a source buffer to a destination buffer.
18  *
19  * This function copies src_len bytes from src_buf to dst_buf. The following properties are required
20  * of the caller:
21  * - dst_buf and src_buf are non-NULL.
22  * - src_len is less than or equal to dst_len.
23  * - The source and destination buffers do not overlap.
24  *
25  * The implementer of this function is free to check that these properties hold and take action,
26  * such as assertion handling, if the properties are violated.
27  *
28  * @param    dst_buf   Destination buffer to copy to.
29  * @param    dst_len   Size, in bytes, of the destination buffer.
30  * @param    src_buf   Source buffer to copy from.
31  * @param    src_len   The number of bytes to copy from the source buffer.
32  **/
33 void libspdm_copy_mem(void *dst_buf, size_t dst_len,
34                       const void *src_buf, size_t src_len);
35 
36 /**
37  * Fills a target buffer with a byte value.
38  *
39  * @param  buffer    The memory to set.
40  * @param  length    The number of bytes to set.
41  * @param  value     The value with which to fill length bytes of buffer.
42  **/
43 void libspdm_set_mem(void *buffer, size_t length, uint8_t value);
44 
45 /**
46  * Fills a target buffer with zeros.
47  *
48  * @param  buffer      The pointer to the target buffer to fill with zeros.
49  * @param  length      The number of bytes in buffer to fill with zeros.
50  **/
51 void libspdm_zero_mem(void *buffer, size_t length);
52 
53 /**
54  * Compares the contents of two buffers in constant time.
55  *
56  * For a given length, the time to complete the comparison is always the same regardless of the
57  * contents of the two buffers.
58  *
59  * @param  destination_buffer  A pointer to the destination buffer to compare.
60  * @param  source_buffer       A pointer to the source buffer to compare.
61  * @param  length              The number of bytes to compare.
62  *
63  * @return true   The contents of the two buffers are the same.
64  * @retval false  The contents of the two buffers are not the same.
65  **/
66 bool libspdm_consttime_is_mem_equal(const void *destination_buffer,
67                                     const void *source_buffer, size_t length);
68 
69 #endif /* MEMLIB_H */
70