xref: /aosp_15_r20/external/tpm2-tss/test/integration/esys-hash.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 #define LOGMODULE test
17 #include "util/log.h"
18 #include "util/aux_util.h"
19 
20 /** This test is intended to test the ESAPI command  Esys_HASH.
21  *
22  * The test checks whether the TPM hash function can be used via the ESAPI.
23  *
24  * Tested ESAPI commands:
25  *  - Esys_Hash() (M)
26  *
27  * @param[in,out] esys_context The ESYS_CONTEXT.
28  * @retval EXIT_FAILURE
29  * @retval EXIT_SUCCESS
30  */
31 
32 int
test_esys_hash(ESYS_CONTEXT * esys_context)33 test_esys_hash(ESYS_CONTEXT * esys_context)
34 {
35     TSS2_RC r;
36     TPM2B_MAX_BUFFER data = { .size = 20,
37                               .buffer={0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0,
38                                        1, 2, 3, 4, 5, 6, 7, 8, 9}};
39     TPMI_ALG_HASH hashAlg = TPM2_ALG_SHA1;
40     TPMI_RH_HIERARCHY hierarchy = TPM2_RH_OWNER;
41     TPM2B_DIGEST *outHash = NULL;
42     TPMT_TK_HASHCHECK *validation = NULL;
43 
44     r = Esys_Hash(
45         esys_context,
46         ESYS_TR_NONE,
47         ESYS_TR_NONE,
48         ESYS_TR_NONE,
49         &data,
50         hashAlg,
51         hierarchy,
52         &outHash,
53         &validation);
54     goto_if_error(r, "Error: Hash", error);
55 
56     Esys_Free(outHash);
57     Esys_Free(validation);
58     return EXIT_SUCCESS;
59 
60  error:
61     Esys_Free(outHash);
62     Esys_Free(validation);
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_hash(esys_context);
69 }
70