mirror of
https://github.com/Mbed-TLS/mbedtls-framework.git
synced 2026-07-28 06:47:46 +00:00
New helper function mbedtls_test_buffer_is_all_zero()
Signed-off-by: Gilles Peskine <[email protected]>
This commit is contained in:
@@ -166,6 +166,30 @@ const char *mbedtls_test_get_mutex_usage_error(void);
|
||||
void mbedtls_test_set_mutex_usage_error(const char *msg);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief Check whether the given buffer is all-bits-zero.
|
||||
*
|
||||
* \param[in] buf Pointer to the buffer to check.
|
||||
* \param size Buffer size in bytes.
|
||||
*
|
||||
* \retval 0 The given buffer has a nonzero byte.
|
||||
* \retval 1 The given buffer is all-bits-zero (this includes the case
|
||||
* of an empty buffer).
|
||||
*/
|
||||
int mbedtls_test_buffer_is_all_zero(const uint8_t *buf, size_t size);
|
||||
|
||||
/** Check whether the object at the given address is all-bits-zero.
|
||||
*
|
||||
* \param[in] ptr A pointer to the object to check.
|
||||
* This macro parameter may be evaluated more than once.
|
||||
*
|
||||
* \retval 0 The given object has a nonzero byte.
|
||||
* \retval 1 The given object is all-bits-zero (this includes the case
|
||||
* of an empty buffer).
|
||||
*/
|
||||
#define MBEDTLS_TEST_OBJECT_IS_ALL_ZERO(ptr) \
|
||||
(mbedtls_test_buffer_is_all_zero((const uint8_t *) (ptr), sizeof(*(ptr))))
|
||||
|
||||
#if defined(MBEDTLS_BIGNUM_C)
|
||||
|
||||
/**
|
||||
|
||||
@@ -265,6 +265,16 @@ void mbedtls_test_set_mutex_usage_error(const char *msg)
|
||||
}
|
||||
#endif // #if defined(MBEDTLS_TEST_MUTEX_USAGE)
|
||||
|
||||
int mbedtls_test_buffer_is_all_zero(const uint8_t *buf, size_t size)
|
||||
{
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
if (buf[i] != 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_BIGNUM_C)
|
||||
|
||||
unsigned mbedtls_test_get_case_uses_negative_0(void)
|
||||
|
||||
Reference in New Issue
Block a user