TF-M Reference Manual  1.2.0
TrustedFirmware-M
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
attest_symmetric_s_interface_testsuite.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-2020, Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #include "attest_s_tests.h"
10 #include "attest.h"
11 #include "attest_tests_common.h"
13 #include "attest_token_test.h"
14 
15 /* Define test suite for attestation service tests */
16 /* List of tests */
17 static void tfm_attest_test_1001(struct test_result_t *ret);
18 #ifdef INCLUDE_TEST_CODE /* Remove them from release build */
19 static void tfm_attest_test_1002(struct test_result_t *ret);
20 static void tfm_attest_test_1003(struct test_result_t *ret);
21 static void tfm_attest_test_1004(struct test_result_t *ret);
22 static void tfm_attest_test_1005(struct test_result_t *ret);
23 #endif
24 
25 static struct test_t attestation_interface_tests[] = {
26  {&tfm_attest_test_1001, "TFM_ATTEST_TEST_1001",
27  "Symmetric key algorithm based Initial Attestation test", {0} },
28 #ifdef INCLUDE_TEST_CODE /* Remove them from release build */
29  {&tfm_attest_test_1002, "TFM_ATTEST_TEST_1002",
30  "Minimal token test of attest token", {0} },
31  {&tfm_attest_test_1003, "TFM_ATTEST_TEST_1003",
32  "Minimal token size test of attest token", {0} },
33  {&tfm_attest_test_1004, "TFM_ATTEST_TEST_1004",
34  "Short circuit tag test of attest token", {0} },
35  {&tfm_attest_test_1005, "TFM_ATTEST_TEST_1005",
36  "Negative test cases for initial attestation service", {0} },
37 #endif
38 };
39 
40 void
42 {
43  uint32_t list_size;
44 
45  list_size = (sizeof(attestation_interface_tests) /
46  sizeof(attestation_interface_tests[0]));
47 
48  set_testsuite("Symmetric key algorithm based Initial Attestation Service "
49  "secure interface tests (TFM_ATTEST_TEST_1XXX)",
50  attestation_interface_tests, list_size, p_test_suite);
51 }
52 
56 static void tfm_attest_test_1001(struct test_result_t *ret)
57 {
58  int32_t err;
59 
60  err = decode_test_symmetric_initial_attest();
61  if (err != 0) {
62  TEST_LOG("tfm_attest_test_1001() returned: %d\r\n", err);
63  TEST_FAIL("Attest token tfm_attest_test_1001() has failed");
64  return;
65  }
66 
67  ret->val = TEST_PASSED;
68 }
69 
70 #ifdef INCLUDE_TEST_CODE /* Remove them from release build */
71 
79 static void tfm_attest_test_1002(struct test_result_t *ret)
80 {
81  int32_t err;
82 
83  err = minimal_test();
84  if (err != 0) {
85  TEST_LOG("minimal_test() returned: %d\r\n", err);
86  TEST_FAIL("Attest token minimal_test() has failed");
87  return;
88  }
89 
90  ret->val = TEST_PASSED;
91 }
92 
97 static void tfm_attest_test_1003(struct test_result_t *ret)
98 {
99  int32_t err;
100 
101  err = minimal_get_size_test();
102  if (err != 0) {
103  TEST_LOG("minimal_get_size_test() returned: %d\r\n", err);
104  TEST_FAIL("Attest token minimal_get_size_test() has failed");
105  return;
106  }
107 
108  ret->val = TEST_PASSED;
109 }
110 
117 static void tfm_attest_test_1004(struct test_result_t *ret)
118 {
119  int32_t err;
120 
121  err = decode_test_symmetric_iat_short_circuit_tag();
122  if (err != 0) {
123  TEST_LOG("decode_test_symmetric_iat_short_circuit_tag() returned: %d\r\n", err);
124  TEST_FAIL("Attest token decode_test_symmetric_iat_short_circuit_tag() has failed");
125  return;
126  }
127 
128  ret->val = TEST_PASSED;
129 }
130 
139 static void tfm_attest_test_1005(struct test_result_t *ret)
140 {
141  psa_status_t err;
142  size_t token_size;
143 
144  /* Call with with bigger challenge object than allowed */
146  &token_size);
147 
148  if (err != PSA_ERROR_INVALID_ARGUMENT) {
149  TEST_FAIL("Attestation should fail with too big challenge object");
150  return;
151  }
152 
153  /* Call with smaller buffer size than size of test token */
154  err = buffer_too_small_test();
155  if (err != 0) {
156  TEST_LOG("buffer_too_small_test() returned: %d\r\n", err);
157  TEST_FAIL("Attest token buffer_too_small_test() has failed");
158  return;
159  }
160 
161  ret->val = TEST_PASSED;
162 }
163 #endif /* INCLUDE_TEST_CODE */
#define TEST_FAIL(info_msg)
enum test_suite_err_t set_testsuite(const char *name, struct test_t *test_list, uint32_t size, struct test_suite_t *p_ts)
Sets test suite parameters.
#define INVALID_CHALLENGE_OBJECT_SIZE
Size of challenge object that is invalid.
int_fast16_t minimal_get_size_test(void)
Test token size calculation.
psa_status_t psa_initial_attest_get_token_size(size_t challenge_size, size_t *token_size)
Get the exact size of initial attestation token in bytes.
#define PSA_ERROR_INVALID_ARGUMENT
int_fast16_t buffer_too_small_test(void)
Pass too small a buffer and confirm correct error result.
Expected values for test suite.
struct test_result_t ret
Entry points for attestation token tests.
int_fast16_t minimal_test(void)
Minimal token creation test using a short-circuit signature.
#define TEST_LOG(...)
enum test_status_t val
int32_t psa_status_t
Function return status.
Definition: crypto_types.h:43
void register_testsuite_s_attestation_interface(struct test_suite_t *p_test_suite)
Register testsuite for the initial attestation service.