VirtualBox

source: vbox/trunk/src/libs/libtpms-0.9.6/tests/tpm2_selftest.c

Last change on this file was 91612, checked in by vboxsync, 3 years ago

src/libs: Export libtpms-0.9.0, bugref:10078

File size: 1.7 KB
Line 
1#include <stdio.h>
2#include <string.h>
3#include <assert.h>
4
5#include <libtpms/tpm_library.h>
6#include <libtpms/tpm_error.h>
7#include <libtpms/tpm_memory.h>
8
9int main(void)
10{
11 unsigned char *rbuffer = NULL;
12 uint32_t rlength;
13 uint32_t rtotal = 0;
14 TPM_RESULT res;
15 int ret = 1;
16 unsigned char tpm2_startup[] = {
17 0x80, 0x01, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00,
18 0x01, 0x44, 0x00, 0x00
19 };
20 unsigned char tpm2_selftest[] = {
21 0x80, 0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00,
22 0x01, 0x43, 0x01
23 };
24 const unsigned char tpm2_selftest_resp[] = {
25 0x80, 0x01, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00,
26 0x00, 0x00
27 };
28
29 res = TPMLIB_ChooseTPMVersion(TPMLIB_TPM_VERSION_2);
30 if (res) {
31 fprintf(stderr, "TPMLIB_ChooseTPMVersion() failed: 0x%02x\n", res);
32 goto exit;
33 }
34
35 res = TPMLIB_MainInit();
36 if (res) {
37 fprintf(stderr, "TPMLIB_MainInit() failed: 0x%02x\n", res);
38 goto exit;
39 }
40
41 res = TPMLIB_Process(&rbuffer, &rlength, &rtotal,
42 tpm2_startup, sizeof(tpm2_startup));
43 if (res) {
44 fprintf(stderr, "TPMLIB_Process(Startup) failed: 0x%02x\n", res);
45 goto exit;
46 }
47
48 res = TPMLIB_Process(&rbuffer, &rlength, &rtotal,
49 tpm2_selftest, sizeof(tpm2_selftest));
50 if (res) {
51 fprintf(stderr, "TPMLIB_Process(TPM2_Self) failed: 0x%02x\n",
52 res);
53 goto exit;
54 }
55
56 if (memcmp(rbuffer, tpm2_selftest_resp, rlength)) {
57 fprintf(stderr, "Expected response from TPM2_Selftest is different than received one.\n");
58 goto exit;
59 }
60
61 fprintf(stdout, "OK\n");
62
63 ret = 0;
64
65exit:
66 TPMLIB_Terminate();
67 TPM_Free(rbuffer);
68
69 return ret;
70}
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use