5 #include "sw/device/lib/crypto/drivers/entropy.h"
6 #include "sw/device/lib/crypto/drivers/kmac.h"
7 #include "sw/device/lib/crypto/impl/integrity.h"
14 #include "sw/device/lib/testing/test_framework/check.h"
21 #include "kdf_testvectors.h"
32 status_t get_kmac_mode(kdf_test_operation_t test_operation,
34 switch (test_operation) {
35 case kKdfTestOperationKmac128:
36 *mode = kOtcryptoKmacModeKmac128;
38 case kKdfTestOperationKmac256:
39 *mode = kOtcryptoKmacModeKmac256;
42 LOG_INFO(
"Invalid test operation is given for KDF-KMAC");
43 return INVALID_ARGUMENT();
51 static status_t run_test_vector(
void) {
54 size_t km_num_words = current_test_vector->expected_output.len;
55 uint32_t km_buffer[2 * km_num_words];
58 TRY(get_kmac_mode(current_test_vector->test_operation, &mode));
65 .key_mode = kOtcryptoKeyModeKdfKmac128,
66 .key_length = km_num_words *
sizeof(uint32_t),
68 .security_level = kOtcryptoKeySecurityLevelLow,
72 .keyblob_length =
sizeof(km_buffer),
80 current_test_vector->label,
81 current_test_vector->context,
82 keying_material.config.key_length, &keying_material));
88 uint32_t km_share0[km_num_words];
89 uint32_t km_share1[km_num_words];
96 uint32_t actual_output[km_num_words];
97 for (
size_t i = 0; i <
ARRAYSIZE(actual_output); i++) {
98 actual_output[i] = km_share0[i] ^ km_share1[i];
100 TRY_CHECK_ARRAYS_EQ(actual_output, current_test_vector->expected_output.data,
105 OTTF_DEFINE_TEST_CONFIG();
107 LOG_INFO(
"Testing cryptolib KDF-KMAC driver.");
110 CHECK_STATUS_OK(entropy_complex_init());
111 CHECK_STATUS_OK(kmac_hwip_default_configure());
114 for (
size_t i = 0; i <
ARRAYSIZE(kKdfTestVectors); i++) {
115 current_test_vector = &kKdfTestVectors[i];
116 LOG_INFO(
"Running test %d of %d, test vector identifier: %s", i + 1,
118 current_test_vector->vector_identifier);
121 return status_ok(test_result);