1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /***********************************************************************
3 * Copyright (c) 2017-2018, Intel Corporation
4 *
5 * All rights reserved.
6 ***********************************************************************/
7 #ifdef HAVE_CONFIG_H
8 #include <config.h>
9 #endif
10
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14
15 #include "tss2_sys.h"
16
17 #define LOGMODULE test
18 #include "util/log.h"
19 #include "test.h"
20
21 /**
22 * This program contains integration test for SAPI Tss2_Sys_StirRandom.
23 * Since StirRandom is quite simple we can only check for success if we
24 * supply correct parameters.
25 */
26 int
test_invoke(TSS2_SYS_CONTEXT * sapi_context)27 test_invoke (TSS2_SYS_CONTEXT *sapi_context)
28 {
29 TSS2_RC rc;
30 TPM2B_SENSITIVE_DATA inData = {
31 .size = 20,
32 .buffer = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
33 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}
34 };
35
36 LOG_INFO("StirRandom tests started.");
37 /* Check invalid context */
38 rc = Tss2_Sys_StirRandom(NULL, 0, NULL, 0);
39 if (rc != TSS2_SYS_RC_BAD_REFERENCE) {
40 LOG_ERROR("StirRandom (ctx) FAILED! Response Code : %x", rc);
41 exit(1);
42 }
43
44 /* check empty input data */
45 rc = Tss2_Sys_StirRandom(sapi_context, 0, NULL, 0);
46 if (rc != TSS2_RC_SUCCESS) {
47 LOG_ERROR("StirRandom (empty) FAILED! Response Code : %x", rc);
48 exit(1);
49 }
50
51 /* check with correct input data*/
52 rc = Tss2_Sys_StirRandom(sapi_context, 0, &inData, 0);
53 if (rc != TSS2_RC_SUCCESS) {
54 LOG_ERROR("StirRandom (indata) FAILED! Response Code : %x", rc);
55 exit(1);
56 }
57 LOG_INFO("StirRandom Test Passed!");
58 return 0;
59 }
60