Skip to content

Commit 57a8f90

Browse files
JuergenReppSITAndreas Fuchs
authored andcommitted
Getting Started: Add compilation of standalone application.
To make it easier for newbies to get started, it is shown how a standalone application can be compiled. Signed-off-by: Juergen Repp <juergen.repp@sit.fraunhofer.de>
1 parent f1bcbc8 commit 57a8f90

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

_posts/2019-02-05-Getting-Started.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,49 @@ Check out the [tpm2-tss README] and [tpm2-tss INSTALL] for more information.
2323

2424
[tpm2-tss README]: https://github.com/tpm2-software/tpm2-tss/blob/master/README.md
2525
[tpm2-tss INSTALL]: https://github.com/tpm2-software/tpm2-tss/blob/master/INSTALL.md
26+
27+
28+
After successful installation a standalone application using ESAPI can be compiled as follows:
29+
30+
{% highlight bash %}
31+
gcc standalone-example.c -L=/usr/local/lib/ -ltss2-esys -o standalone-example
32+
{% endhighlight %}
33+
34+
Simple example standalone application:
35+
36+
{% highlight c %}
37+
#include <stdlib.h>
38+
#include <stdio.h>
39+
#include <tss2/tss2_esys.h>
40+
41+
int main() {
42+
43+
TSS2_RC r;
44+
45+
/* Initialize the ESAPI context */
46+
ESYS_CONTEXT *ctx;
47+
r = Esys_Initialize(&ctx, NULL, NULL);
48+
49+
if (r != TSS2_RC_SUCCESS){
50+
printf("\nError: Esys_Initializen\n");
51+
exit(1);
52+
}
53+
54+
/* Get random data */
55+
TPM2B_DIGEST *random_bytes;
56+
r = Esys_GetRandom(ctx, ESYS_TR_NONE, ESYS_TR_NONE, ESYS_TR_NONE, 20,
57+
&random_bytes);
58+
59+
if (r != TSS2_RC_SUCCESS){
60+
printf("\nError: Esys_GetRandom\n");
61+
exit(1);
62+
}
63+
64+
printf("\n");
65+
for (int i = 0; i < random_bytes->size; i++) {
66+
printf("0x%x ", random_bytes->buffer[i]);
67+
}
68+
printf("\n");
69+
exit(0);
70+
}
71+
{% endhighlight %}

0 commit comments

Comments
 (0)