xref: /aosp_15_r20/external/tpm2-tss/test/integration/esys-set-algorithm-set.int.c (revision 758e9fba6fc9adbf15340f70c73baee7b168b1c9)
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 
7 #ifdef HAVE_CONFIG_H
8 #include <config.h>
9 #endif
10 
11 #include <stdlib.h>
12 
13 #include "tss2_esys.h"
14 
15 #include "esys_iutil.h"
16 #include "test-esapi.h"
17 #define LOGMODULE test
18 #include "util/log.h"
19 #include "util/aux_util.h"
20 
21 /** Test the ESAPI function Esys_SetAlgorithmSet.
22  *
23  *\b Note: platform authorization needed.
24  *
25  * Tested ESAPI commands:
26  *  - Esys_SetAlgorithmSet() (O)
27  *
28  * @param[in,out] esys_context The ESYS_CONTEXT.
29  * @retval EXIT_FAILURE
30  * @retval EXIT_SKIP
31  * @retval EXIT_SUCCESS
32  */
33 
34 int
test_esys_set_algorithm_set(ESYS_CONTEXT * esys_context)35 test_esys_set_algorithm_set(ESYS_CONTEXT * esys_context)
36 {
37     TSS2_RC r;
38     int failure_return = EXIT_FAILURE;
39 
40     UINT32 algorithmSet = 0;
41 
42     r = Esys_SetAlgorithmSet(
43         esys_context,
44         ESYS_TR_RH_PLATFORM,
45         ESYS_TR_PASSWORD,
46         ESYS_TR_NONE,
47         ESYS_TR_NONE,
48         algorithmSet);
49 
50     if ((r == TPM2_RC_COMMAND_CODE) ||
51         (r == (TPM2_RC_COMMAND_CODE | TSS2_RESMGR_RC_LAYER)) ||
52         (r == (TPM2_RC_COMMAND_CODE | TSS2_RESMGR_TPM_RC_LAYER))) {
53         LOG_WARNING("Command TPM2_SetAlgorithmSet not supported by TPM.");
54         failure_return = EXIT_SKIP;
55         goto error;
56     }
57 
58     if ((r & ~TPM2_RC_N_MASK) == TPM2_RC_BAD_AUTH) {
59         /* Platform authorization not possible test will be skipped */
60         LOG_WARNING("Platform authorization not possible.");
61         failure_return = EXIT_SKIP;
62     }
63 
64     goto_if_error(r, "Error: SetAlgorithmSet", error);
65 
66     return EXIT_SUCCESS;
67 
68  error:
69     return failure_return;
70 }
71 
72 int
test_invoke_esapi(ESYS_CONTEXT * esys_context)73 test_invoke_esapi(ESYS_CONTEXT * esys_context) {
74     return test_esys_set_algorithm_set(esys_context);
75 }
76