• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*******************************************************************************
3  * Copyright 2017-2018, Fraunhofer SIT sponsored by Infineon Technologies AG
4  * All rights reserved.
5  *******************************************************************************/
6 #ifdef HAVE_CONFIG_H
7 #include <config.h>
8 #endif
9 
10 #include <stdlib.h>
11 
12 #include "tss2_esys.h"
13 
14 #include "esys_iutil.h"
15 #define LOGMODULE test
16 #include "util/log.h"
17 #include "util/aux_util.h"
18 
19 /** Test the ESAPI functions for TPM tests.
20  *
21  * Tested ESAPI commands:
22  *  - Esys_GetTestResult() (M)
23  *  - Esys_IncrementalSelfTest() (M)
24  *  - Esys_SelfTest() (M)
25  *
26  * @param[in,out] esys_context The ESYS_CONTEXT.
27  * @retval EXIT_FAILURE
28  * @retval EXIT_SUCCESS
29  */
30 int
test_esys_tpm_tests(ESYS_CONTEXT * esys_context)31 test_esys_tpm_tests(ESYS_CONTEXT * esys_context)
32 {
33     TSS2_RC r;
34 
35     esys_context->state = _ESYS_STATE_INIT;
36     r = Esys_SelfTest(esys_context,
37                       ESYS_TR_NONE, ESYS_TR_NONE, ESYS_TR_NONE, 0);
38     goto_if_error(r, "Error SelfTest did fail", error);
39 
40     TPML_ALG alg_list = { .count = 1 , .algorithms = { TPM2_ALG_SHA1 }};
41     TPML_ALG *toDoList;
42 
43     esys_context->state = _ESYS_STATE_INIT;
44     r = Esys_IncrementalSelfTest(esys_context,
45                                  ESYS_TR_NONE, ESYS_TR_NONE, ESYS_TR_NONE,
46                                  &alg_list, &toDoList);
47     goto_if_error(r, "Error IncrementalSelfTest did not fail", error);
48     free(toDoList);
49 
50     TPM2B_MAX_BUFFER *outData;
51     TPM2_RC testResult;
52 
53     esys_context->state = _ESYS_STATE_INIT;
54     r = Esys_GetTestResult(esys_context,
55                            ESYS_TR_NONE, ESYS_TR_NONE, ESYS_TR_NONE,
56                            &outData, &testResult);
57     goto_if_error(r, "Error GetTestResult did fail", error);
58     free(outData);
59 
60     return EXIT_SUCCESS;
61 
62  error:
63     return EXIT_FAILURE;
64 }
65 
66 int
test_invoke_esapi(ESYS_CONTEXT * esys_context)67 test_invoke_esapi(ESYS_CONTEXT * esys_context) {
68     return test_esys_tpm_tests(esys_context);
69 }
70