Add tests
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
This commit is contained in:
parent
703f805f09
commit
21dfce7a5c
2 changed files with 64 additions and 0 deletions
23
tests/suites/test_suite_platform_util.data
Normal file
23
tests/suites/test_suite_platform_util.data
Normal file
|
@ -0,0 +1,23 @@
|
|||
Zeroize len 0, null
|
||||
mbedtls_platform_zeroize:0:1
|
||||
|
||||
Zeroize len 0, non-null
|
||||
mbedtls_platform_zeroize:0:0
|
||||
|
||||
Zeroize len 1
|
||||
mbedtls_platform_zeroize:1:0
|
||||
|
||||
Zeroize len 4
|
||||
mbedtls_platform_zeroize:1:0
|
||||
|
||||
Zeroize len 5
|
||||
mbedtls_platform_zeroize:1:0
|
||||
|
||||
Zeroize len 32
|
||||
mbedtls_platform_zeroize:32:0
|
||||
|
||||
Zeroize len 127
|
||||
mbedtls_platform_zeroize:127:0
|
||||
|
||||
Zeroize len 128
|
||||
mbedtls_platform_zeroize:128:0
|
41
tests/suites/test_suite_platform_util.function
Normal file
41
tests/suites/test_suite_platform_util.function
Normal file
|
@ -0,0 +1,41 @@
|
|||
/* BEGIN_HEADER */
|
||||
#include "mbedtls/platform_util.h"
|
||||
/* END_HEADER */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_platform_zeroize(int len, int null)
|
||||
{
|
||||
char buf[130];
|
||||
char *p = NULL;
|
||||
|
||||
TEST_ASSERT(len <= 128);
|
||||
|
||||
/* Write sentinel values */
|
||||
buf[0] = 2;
|
||||
buf[len + 1] = 2;
|
||||
|
||||
/* Write non-zero content */
|
||||
if (!null) {
|
||||
p = &buf[1];
|
||||
for (int i = 0; i < len; i++) {
|
||||
p[i] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Check content is non-zero */
|
||||
TEST_EQUAL(buf[0], 2);
|
||||
for (int i = 0; i < len; i++) {
|
||||
TEST_ASSERT(p[i] == 1);
|
||||
}
|
||||
TEST_EQUAL(buf[len + 1], 2);
|
||||
|
||||
mbedtls_platform_zeroize(p, len);
|
||||
|
||||
/* Check content is zero and sentinels un-changed */
|
||||
TEST_EQUAL(buf[0], 2);
|
||||
for (int i = 0; i < len; i++) {
|
||||
TEST_ASSERT(p[i] == 0);
|
||||
}
|
||||
TEST_EQUAL(buf[len + 1], 2);
|
||||
}
|
||||
/* END_CASE */
|
Loading…
Reference in a new issue