forked from wolfSSL/wolfTPM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tpm2_wrap.h
2885 lines (2308 loc) · 114 KB
/
tpm2_wrap.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* tpm2_wrap.h
*
* Copyright (C) 2006-2022 wolfSSL Inc.
*
* This file is part of wolfTPM.
*
* wolfTPM is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* wolfTPM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/
#ifndef __TPM2_WRAP_H__
#define __TPM2_WRAP_H__
#include <wolftpm/tpm2.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct WOLFTPM2_HANDLE {
TPM_HANDLE hndl;
TPM2B_AUTH auth; /* Used if policyAuth is not set */
TPMT_SYM_DEF symmetric;
TPM2B_NAME name;
int policyAuth; /* Handle requires Policy, not password Auth */
unsigned int nameLoaded : 1; /* flag to indicate if "name" was loaded and computed */
} WOLFTPM2_HANDLE;
#define TPM_SES_PWD 0xFF /* Session type for Password that fits in one byte */
typedef struct WOLFTPM2_SESSION {
TPM_ST type; /* Trial, Policy or HMAC; or TPM_SES_PWD */
WOLFTPM2_HANDLE handle; /* Session handle from StartAuthSession */
TPM2B_NONCE nonceTPM; /* Value from StartAuthSession */
TPM2B_NONCE nonceCaller; /* Fresh nonce at each command */
TPM2B_DIGEST salt; /* User defined */
TPMI_ALG_HASH authHash;
} WOLFTPM2_SESSION;
typedef struct WOLFTPM2_DEV {
TPM2_CTX ctx;
TPM2_AUTH_SESSION session[MAX_SESSION_NUM];
} WOLFTPM2_DEV;
typedef struct WOLFTPM2_KEY {
WOLFTPM2_HANDLE handle;
TPM2B_PUBLIC pub;
} WOLFTPM2_KEY;
typedef struct WOLFTPM2_KEYBLOB {
WOLFTPM2_HANDLE handle;
TPM2B_PUBLIC pub;
TPM2B_NAME name;
TPM2B_PRIVATE priv;
} WOLFTPM2_KEYBLOB;
typedef struct WOLFTPM2_HASH {
WOLFTPM2_HANDLE handle;
} WOLFTPM2_HASH;
typedef struct WOLFTPM2_NV {
WOLFTPM2_HANDLE handle;
} WOLFTPM2_NV;
typedef struct WOLFTPM2_HMAC {
WOLFTPM2_HASH hash;
WOLFTPM2_KEY key;
/* option bits */
word16 hmacKeyLoaded:1;
word16 hmacKeyKeep:1;
} WOLFTPM2_HMAC;
#ifdef WOLFTPM2_CERT_GEN
typedef struct WOLFTPM2_CSR {
Cert req;
} WOLFTPM2_CSR;
#endif
#ifndef WOLFTPM2_MAX_BUFFER
#define WOLFTPM2_MAX_BUFFER 2048
#endif
typedef struct WOLFTPM2_BUFFER {
int size;
byte buffer[WOLFTPM2_MAX_BUFFER];
} WOLFTPM2_BUFFER;
typedef enum WOLFTPM2_MFG {
TPM_MFG_UNKNOWN = 0,
TPM_MFG_INFINEON,
TPM_MFG_STM,
TPM_MFG_MCHP,
TPM_MFG_NUVOTON,
TPM_MFG_NATIONTECH,
} WOLFTPM2_MFG;
typedef struct WOLFTPM2_CAPS {
WOLFTPM2_MFG mfg;
char mfgStr[4 + 1];
char vendorStr[(4 * 4) + 1];
word32 tpmType;
word16 fwVerMajor;
word16 fwVerMinor;
word32 fwVerVendor;
/* bits */
word16 fips140_2 : 1; /* using FIPS mode */
word16 cc_eal4 : 1; /* Common Criteria EAL4+ */
word16 req_wait_state : 1; /* requires SPI wait state */
} WOLFTPM2_CAPS;
/* NV Handles */
#define TPM2_NV_RSA_EK_CERT 0x01C00002
#define TPM2_NV_ECC_EK_CERT 0x01C0000A
/* Wrapper API's to simplify TPM use */
/** @defgroup wolfTPM2_Wrappers wolfTPM2 Wrappers
*
* This module describes the rich API of wolfTPM called wrappers.
*
* wolfTPM wrappers are used in two main cases:
* * Perform common TPM 2.0 tasks, like key generation and storage
* * Perform complex TPM 2.0 tasks, like attestation and parameter encryption
*
* wolfTPM enables quick and rapid use of TPM 2.0 thanks to its many wrapper functions.
*
*/
/* For devtpm and swtpm builds, the ioCb and userCtx are not used and should be set to NULL */
/*!
\ingroup wolfTPM2_Wrappers
\brief Test initialization of a TPM and optionally the TPM capabilities can be received
\return TPM_RC_SUCCESS: successful
\return TPM_RC_FAILURE: generic failure (check TPM IO and TPM return code)
\return BAD_FUNC_ARG: check the provided arguments
\param ioCb function pointer to a IO callback (see examples/tpm_io.h)
\param userCtx pointer to a user context (can be NULL)
\param caps to a structure of WOLFTPM2_CAPS type for returning the TPM capabilities (can be NULL)
\sa wolfTPM2_Init
\sa TPM2_Init
*/
WOLFTPM_API int wolfTPM2_Test(TPM2HalIoCb ioCb, void* userCtx, WOLFTPM2_CAPS* caps);
/*!
\ingroup wolfTPM2_Wrappers
\brief Complete initialization of a TPM
\return TPM_RC_SUCCESS: successful
\return TPM_RC_FAILURE: generic failure (check TPM IO communication)
\return BAD_FUNC_ARG: check the provided arguments
\param dev pointer to an empty structure of WOLFTPM2_DEV type
\param ioCb function pointer to a IO callback (see examples/tpm_io.h)
\param userCtx pointer to a user context (can be NULL)
_Example_
\code
int rc;
WOLFTPM2_DEV dev;
rc = wolfTPM2_Init(&dev, TPM2_IoCb, userCtx);
if (rc != TPM_RC_SUCCESS) {
//wolfTPM2_Init failed
goto exit;
}
\endcode
\sa wolfTPM2_OpenExisting
\sa wolfTPM2_Test
\sa TPM2_Init
*/
WOLFTPM_API int wolfTPM2_Init(WOLFTPM2_DEV* dev, TPM2HalIoCb ioCb, void* userCtx);
/*!
\ingroup wolfTPM2_Wrappers
\brief Use an already initialized TPM, in its current TPM locality
\return TPM_RC_SUCCESS: successful
\return TPM_RC_FAILURE: generic failure (check TPM IO communication)
\return BAD_FUNC_ARG: check the provided arguments
\param dev pointer to an empty structure of WOLFTPM2_DEV type
\param ioCb function pointer to a IO callback (see examples/tpm_io.h)
\param userCtx pointer to a user context (can be NULL)
\sa wolfTPM2_Init
\sa wolfTPM2_Cleanup
\sa TPM2_Init
*/
WOLFTPM_API int wolfTPM2_OpenExisting(WOLFTPM2_DEV* dev, TPM2HalIoCb ioCb, void* userCtx);
/*!
\ingroup wolfTPM2_Wrappers
\brief Easy to use TPM and wolfcrypt deinitialization
\note Calls wolfTPM2_Cleanup_ex with appropriate doShutdown parameter
\return TPM_RC_SUCCESS: successful
\return TPM_RC_FAILURE: generic failure (check TPM IO communication)
\return BAD_FUNC_ARG: check the provided arguments
\param dev pointer to a populated structure of WOLFTPM2_DEV type
_Example_
\code
int rc;
rc = wolfTPM2_Cleanup(&dev);
if (rc != TPM_RC_SUCCESS) {
//wolfTPM2_Cleanup failed
goto exit;
}
\endcode
\sa wolfTPM2_OpenExisting
\sa wolfTPM2_Test
\sa TPM2_Init
*/
WOLFTPM_API int wolfTPM2_Cleanup(WOLFTPM2_DEV* dev);
/*!
\ingroup wolfTPM2_Wrappers
\brief Deinitialization of a TPM (and wolfcrypt if it was used)
\return TPM_RC_SUCCESS: successful
\return TPM_RC_FAILURE: generic failure (check TPM IO communication)
\return BAD_FUNC_ARG: check the provided arguments
\param dev pointer to a populated structure of WOLFTPM2_DEV type
\param doShutdown flag value, if true a TPM2_Shutdown command will be executed
_Example_
\code
int rc;
//perform TPM2_Shutdown after deinitialization
rc = wolfTPM2_Cleanup_ex(&dev, 1);
if (rc != TPM_RC_SUCCESS) {
//wolfTPM2_Cleanup_ex failed
goto exit;
}
\endcode
\sa wolfTPM2_OpenExisting
\sa wolfTPM2_Test
\sa TPM2_Init
*/
WOLFTPM_API int wolfTPM2_Cleanup_ex(WOLFTPM2_DEV* dev, int doShutdown);
/*!
\ingroup wolfTPM2_Wrappers
\brief Provides the device ID of a TPM
\return an integer value of a valid TPM device ID
\return or INVALID_DEVID if the TPM initialization could not extract DevID
\param dev pointer to an populated structure of WOLFTPM2_DEV type
_Example_
\code
int tpmDevId;
tpmDevId = wolfTPM2_GetTpmDevId(&dev);
if (tpmDevId != INVALID_DEVID) {
//wolfTPM2_Cleanup_ex failed
goto exit;
}
\endcode
\sa wolfTPM2_GetCapabilities
\sa wolfTPM2_Init
*/
WOLFTPM_API int wolfTPM2_GetTpmDevId(WOLFTPM2_DEV* dev);
/*!
\ingroup wolfTPM2_Wrappers
\brief Asks the TPM to perform its self test
\return TPM_RC_SUCCESS: successful
\return TPM_RC_FAILURE: generic failure (check TPM IO communication and TPM return code)
\return BAD_FUNC_ARG: check the provided arguments
\param dev pointer to a populated structure of WOLFTPM2_DEV type
_Example_
\code
int rc;
//perform TPM2_Shutdown after deinitialization
rc = wolfTPM2_SelfTest(&dev);
if (rc != TPM_RC_SUCCESS) {
//wolfTPM2_SelfTest failed
goto exit;
}
\endcode
\sa wolfTPM2_OpenExisting
\sa wolfTPM2_Test
\sa TPM2_Init
*/
WOLFTPM_API int wolfTPM2_SelfTest(WOLFTPM2_DEV* dev);
/*!
\ingroup wolfTPM2_Wrappers
\brief Reported the available TPM capabilities
\return TPM_RC_SUCCESS: successful
\return TPM_RC_FAILURE: generic failure (check TPM IO communication and TPM return code)
\return BAD_FUNC_ARG: check the provided arguments
\param dev pointer to a populated structure of WOLFTPM2_DEV type
\param caps pointer to an empty structure of WOLFTPM2_CAPS type to store the capabilities
_Example_
\code
int rc;
WOLFTPM2_CAPS caps;
//perform TPM2_Shutdown after deinitialization
rc = wolfTPM2_GetCapabilities(&dev, &caps);
if (rc != TPM_RC_SUCCESS) {
//wolfTPM2_GetCapabilities failed
goto exit;
}
\endcode
\sa wolfTPM2_GetTpmDevId
\sa wolfTPM2_SelfTest
\sa wolfTPM2_Init
*/
WOLFTPM_API int wolfTPM2_GetCapabilities(WOLFTPM2_DEV* dev, WOLFTPM2_CAPS* caps);
/*!
\ingroup wolfTPM2_Wrappers
\brief Clears one of the TPM Authorization slots, pointed by its index number
\return TPM_RC_SUCCESS: successful
\return TPM_RC_FAILURE: unable to get lock on the TPM2 Context
\return BAD_FUNC_ARG: check the provided arguments
\param dev pointer to a TPM2_DEV struct
\param index integer value, specifying the TPM Authorization slot, between zero and three
\sa wolfTPM2_SetAuth
\sa wolfTPM2_SetAuthPassword
\sa wolfTPM2_SetAuthHandle
\sa wolfTPM2_SetAuthSession
*/
WOLFTPM_API int wolfTPM2_UnsetAuth(WOLFTPM2_DEV* dev, int index);
/*!
\ingroup wolfTPM2_Wrappers
\brief Sets a TPM Authorization slot using the provided index, session handle, attributes and auth
\note It is recommended to use one of the other wolfTPM2 wrappers, like wolfTPM2_SetAuthPassword.
Because the wolfTPM2_SetAuth wrapper provides complete control over the TPM Authorization slot for
advanced use cases. In most scenarios, wolfTPM2_SetAuthHandle and SetAuthPassword are used.
\return TPM_RC_SUCCESS: successful
\return BAD_FUNC_ARG: check the provided arguments
\param dev pointer to a TPM2_DEV struct
\param index integer value, specifying the TPM Authorization slot, between zero and three
\param sessionHandle integer value of TPM_HANDLE type
\param auth pointer to a structure of type TPM2B_AUTH containing one TPM Authorization
\param sessionAttributes integer value of type TPMA_SESSION, selecting one or more attributes for the Session
\param name pointer to a TPM2B_NAME structure
\sa wolfTPM2_SetAuthPassword
\sa wolfTPM2_SetAuthHandle
\sa wolfTPM2_SetAuthSession
*/
WOLFTPM_API int wolfTPM2_SetAuth(WOLFTPM2_DEV* dev, int index,
TPM_HANDLE sessionHandle, const TPM2B_AUTH* auth, TPMA_SESSION sessionAttributes,
const TPM2B_NAME* name);
/*!
\ingroup wolfTPM2_Wrappers
\brief Sets a TPM Authorization slot using the provided user auth, typically a password
\note Often used for authorizing the loading and use of TPM keys, including Primary Keys
\return TPM_RC_SUCCESS: successful
\return BAD_FUNC_ARG: check the provided arguments
\param dev pointer to a TPM2_DEV struct
\param index integer value, specifying the TPM Authorization slot, between zero and three
\param auth pointer to a structure of type TPM2B_AUTH, typically containing a TPM Key Auth
\sa wolfTPM2_SetAuthHandle
\sa wolfTPM2_SetAuthSession
\sa wolfTPM2_SetAuth
*/
WOLFTPM_API int wolfTPM2_SetAuthPassword(WOLFTPM2_DEV* dev, int index, const TPM2B_AUTH* auth);
/*!
\ingroup wolfTPM2_Wrappers
\brief Sets a TPM Authorization slot using the user auth associated with a wolfTPM2 Handle
\note This wrapper is especially useful when using a TPM key for multiple operations and TPM Authorization is required again.
\return TPM_RC_SUCCESS: successful
\return BAD_FUNC_ARG: check the provided arguments
\param dev pointer to a TPM2_DEV struct
\param index integer value, specifying the TPM Authorization slot, between zero and three
\param handle pointer to a populated structure of WOLFTPM2_HANDLE type
\sa wolfTPM2_SetAuth
\sa wolfTPM2_SetAuthPassword
\sa wolfTPM2_SetAuthHandle
\sa wolfTPM2_SetAuthSession
*/
WOLFTPM_API int wolfTPM2_SetAuthHandle(WOLFTPM2_DEV* dev, int index, const WOLFTPM2_HANDLE* handle);
/*!
\ingroup wolfTPM2_Wrappers
\brief Sets a TPM Authorization slot using the provided TPM session handle, index and session attributes
\note This wrapper is useful for configuring TPM sessions, e.g. session for parameter encryption
\return TPM_RC_SUCCESS: successful
\return BAD_FUNC_ARG: check the provided arguments
\param dev pointer to a TPM2_DEV struct
\param index integer value, specifying the TPM Authorization slot, between zero and three
\param tpmSession sessionHandle integer value of TPM_HANDLE type
\param sessionAttributes integer value of type TPMA_SESSION, selecting one or more attributes for the Session
\sa wolfTPM2_SetAuth
\sa wolfTPM2_SetAuthPassword
\sa wolfTPM2_SetAuthHandle
*/
WOLFTPM_API int wolfTPM2_SetAuthSession(WOLFTPM2_DEV* dev, int index,
const WOLFTPM2_SESSION* tpmSession, TPMA_SESSION sessionAttributes);
/*!
\ingroup wolfTPM2_Wrappers
\brief Updates the Name used in a TPM Session with the Name associated with wolfTPM2 Handle
\note Typically, this wrapper is used from another wrappers and in very specific use cases. For example, wolfTPM2_NVWriteAuth
\return TPM_RC_SUCCESS: successful
\return BAD_FUNC_ARG: check the provided arguments
\param dev pointer to a TPM2_DEV struct
\param index integer value, specifying the TPM Authorization slot, between zero and three
\param handle pointer to a populated structure of WOLFTPM2_HANDLE type
\sa wolfTPM2_SetAuth
\sa wolfTPM2_SetAuthPassword
\sa wolfTPM2_SetAuthHandle
\sa wolfTPM2_SetAuthSession
*/
WOLFTPM_API int wolfTPM2_SetAuthHandleName(WOLFTPM2_DEV* dev, int index, const WOLFTPM2_HANDLE* handle);
/*!
\ingroup wolfTPM2_Wrappers
\brief Create a TPM session, Policy, HMAC or Trial
\note This wrapper can also be used to start TPM session for parameter encryption, see wolfTPM nvram or keygen example
\return TPM_RC_SUCCESS: successful
\return BAD_FUNC_ARG: check the provided arguments
\param dev pointer to a TPM2_DEV struct
\param session pointer to an empty WOLFTPM2_SESSION struct
\param tpmKey pointer to a WOLFTPM2_KEY that will be used as a salt for the session
\param bind pointer to a WOLFTPM2_HANDLE that will be used to make the session bounded
\param sesType byte value, the session type (HMAC, Policy or Trial)
\param encDecAlg integer value, specifying the algorithm in case of parameter encryption (TPM_ALG_CFB or TPM_ALG_XOR). Any value not CFB or XOR is considered NULL and parameter encryption is disabled.
\sa wolfTPM2_SetAuthSession
*/
WOLFTPM_API int wolfTPM2_StartSession(WOLFTPM2_DEV* dev,
WOLFTPM2_SESSION* session, WOLFTPM2_KEY* tpmKey,
WOLFTPM2_HANDLE* bind, TPM_SE sesType, int encDecAlg);
/*!
\ingroup wolfTPM2_Wrappers
\brief Creates a TPM session with Policy Secret to satisfy the default EK policy
\note This wrapper can be used only if the EK authorization is not changed from default
\return TPM_RC_SUCCESS: successful
\return BAD_FUNC_ARG: check the provided arguments
\return TPM_RC_FAILURE: check TPM return code, check available handles, check TPM IO
\param dev pointer to a TPM2_DEV struct
\param session pointer to an empty WOLFTPM2_SESSION struct
\sa wolfTPM2_SetAuthSession
\sa wolfTPM2_StartSession
*/
WOLFTPM_API int wolfTPM2_CreateAuthSession_EkPolicy(WOLFTPM2_DEV* dev,
WOLFTPM2_SESSION* tpmSession);
/*!
\ingroup wolfTPM2_Wrappers
\brief Single function to prepare and create a TPM 2.0 Primary Key
\note TPM 2.0 allows only asymmetric RSA or ECC primary keys. Afterwards, both symmetric and asymmetric keys can be created under a TPM 2.0 Primary Key
Typically, Primary Keys are used to create Hierarchies of TPM 2.0 Keys.
The TPM uses a Primary Key to wrap the other keys, signing or decrypting.
\return TPM_RC_SUCCESS: successful
\return TPM_RC_FAILURE: generic failure (check TPM IO and TPM return code)
\return BAD_FUNC_ARG: check the provided arguments
\param dev pointer to a TPM2_DEV struct
\param key pointer to an empty struct of WOLFTPM2_KEY type
\param primaryHandle integer value, specifying one of four TPM 2.0 Primary Seeds: TPM_RH_OWNER, TPM_RH_ENDORSEMENT, TPM_RH_PLATFORM or TPM_RH_NULL
\param publicTemplate pointer to a TPMT_PUBLIC structure populated manually or using one of the wolfTPM2_GetKeyTemplate_... wrappers
\param auth pointer to a string constant, specifying the password authorization for the Primary Key
\param authSz integer value, specifying the size of the password authorization, in bytes
\sa wolfTPM2_CreateKey
\sa wolfTPM2_GetKeyTemplate_RSA
\sa wolfTPM2_GetKeyTemplate_ECC
*/
WOLFTPM_API int wolfTPM2_CreatePrimaryKey(WOLFTPM2_DEV* dev,
WOLFTPM2_KEY* key, TPM_HANDLE primaryHandle, TPMT_PUBLIC* publicTemplate,
const byte* auth, int authSz);
/*!
\ingroup wolfTPM2_Wrappers
\brief Change the authorization secret of a TPM 2.0 key
\note TPM does not allow the authorization secret of a Primary Key to be changed.
Instead, use wolfTPM2_CreatePrimary to create the same PrimaryKey with a new auth.
\return TPM_RC_SUCCESS: successful
\return TPM_RC_FAILURE: generic failure (check TPM IO and TPM return code)
\return BAD_FUNC_ARG: check the provided arguments
\param dev pointer to a TPM2_DEV struct
\param key pointer to an empty struct of WOLFTPM2_KEY type
\param parent pointer to a struct of WOLFTPM2_HANDLE type, specifying a TPM 2.0 Primary Key to be used as the parent(Storage Key)
\param auth pointer to a string constant, specifying the password authorization of the TPM 2.0 key
\param authSz integer value, specifying the size of the password authorization, in bytes
\sa wolfTPM2_CreatePrimaryKey
\sa wolfTPM2_SetAuthHandle
\sa wolfTPM2_UnloadHandle
*/
WOLFTPM_API int wolfTPM2_ChangeAuthKey(WOLFTPM2_DEV* dev, WOLFTPM2_KEY* key,
WOLFTPM2_HANDLE* parent, const byte* auth, int authSz);
/*!
\ingroup wolfTPM2_Wrappers
\brief Single function to prepare and create a TPM 2.0 Key
\note This function only creates the key material and stores it into the keyblob argument. To load the key use wolfTPM2_LoadKey
\return TPM_RC_SUCCESS: successful
\return TPM_RC_FAILURE: generic failure (check TPM IO and TPM return code)
\return BAD_FUNC_ARG: check the provided arguments
\param dev pointer to a TPM2_DEV struct
\param keyBlob pointer to an empty struct of WOLFTPM2_KEYBLOB type
\param parent pointer to a struct of WOLFTPM2_HANDLE type, specifying the a 2.0 Primary Key to be used as the parent(Storage Key)
\param publicTemplate pointer to a TPMT_PUBLIC structure populated manually or using one of the wolfTPM2_GetKeyTemplate_... wrappers
\param auth pointer to a string constant, specifying the password authorization for the TPM 2.0 Key
\param authSz integer value, specifying the size of the password authorization, in bytes
\sa wolfTPM2_LoadKey
\sa wolfTPM2_GetKeyTemplate_RSA
\sa wolfTPM2_GetKeyTemplate_ECC
\sa wolfTPM2_CreatePrimaryKey
*/
WOLFTPM_API int wolfTPM2_CreateKey(WOLFTPM2_DEV* dev,
WOLFTPM2_KEYBLOB* keyBlob, WOLFTPM2_HANDLE* parent,
TPMT_PUBLIC* publicTemplate, const byte* auth, int authSz);
/*!
\ingroup wolfTPM2_Wrappers
\brief Single function to load a TPM 2.0 key
\note To load a TPM 2.0 key its parent(Primary Key) should also be loaded prior to this operation. Primary Keys are loaded when they are created.
\return TPM_RC_SUCCESS: successful
\return TPM_RC_FAILURE: generic failure (check TPM IO and TPM return code)
\return BAD_FUNC_ARG: check the provided arguments
\param dev pointer to a TPM2_DEV struct
\param keyBlob pointer to a struct of WOLFTPM2_KEYBLOB type
\param parent pointer to a struct of WOLFTPM2_HANDLE type, specifying a TPM 2.0 Primary Key to be used as the parent(Storage Key)
\sa wolfTPM2_CreateKey
\sa wolfTPM2_CreatePrimaryKey
\sa wolfTPM2_GetKeyTemplate_RSA
\sa wolfTPM2_GetKeyTemplate_ECC
*/
WOLFTPM_API int wolfTPM2_LoadKey(WOLFTPM2_DEV* dev,
WOLFTPM2_KEYBLOB* keyBlob, WOLFTPM2_HANDLE* parent);
/*!
\ingroup wolfTPM2_Wrappers
\brief Single function to create and load a TPM 2.0 Key in one step
\return TPM_RC_SUCCESS: successful
\return TPM_RC_FAILURE: generic failure (check TPM IO and TPM return code)
\return BAD_FUNC_ARG: check the provided arguments
\param dev pointer to a TPM2_DEV struct
\param key pointer to an empty struct of WOLFTPM2_KEY type
\param parent pointer to a struct of WOLFTPM2_HANDLE type, specifying a TPM 2.0 Primary Key to be used as the parent(Storage Key)
\param publicTemplate pointer to a TPMT_PUBLIC structure populated manually or using one of the wolfTPM2_GetKeyTemplate_... wrappers
\param auth pointer to a string constant, specifying the password authorization of the TPM 2.0 key
\param authSz integer value, specifying the size of the password authorization, in bytes
\sa wolfTPM2_CreateKey
\sa wolfTPM2_GetKeyTemplate_RSA
\sa wolfTPM2_GetKeyTemplate_ECC
*/
WOLFTPM_API int wolfTPM2_CreateAndLoadKey(WOLFTPM2_DEV* dev,
WOLFTPM2_KEY* key, WOLFTPM2_HANDLE* parent, TPMT_PUBLIC* publicTemplate,
const byte* auth, int authSz);
/*!
\ingroup wolfTPM2_Wrappers
\brief Creates and loads a key using single TPM 2.0 operation, and stores encrypted private key material
\return TPM_RC_SUCCESS: successful
\return TPM_RC_FAILURE: generic failure (check TPM IO and TPM return code)
\return BAD_FUNC_ARG: check the provided arguments
\param dev pointer to a TPM2_DEV struct
\param keyBlob pointer to an empty struct of WOLFTPM2_KEYBLOB type, contains private key material as encrypted data
\param parent pointer to a struct of WOLFTPM2_HANDLE type, specifying a TPM 2.0 Primary Key to be used as the parent(Storage Key)
\param publicTemplate pointer to a TPMT_PUBLIC structure populated manually or using one of the wolfTPM2_GetKeyTemplate_... wrappers
\param auth pointer to a string constant, specifying the password authorization of the TPM 2.0 key
\param authSz integer value, specifying the size of the password authorization, in bytes
\sa wolfTPM2_CreateAndLoadKey
\sa wolfTPM2_CreateKey
\sa wolfTPM2_LoadKey
*/
WOLFTPM_API int wolfTPM2_CreateLoadedKey(WOLFTPM2_DEV* dev, WOLFTPM2_KEYBLOB* keyBlob,
WOLFTPM2_HANDLE* parent, TPMT_PUBLIC* publicTemplate,
const byte* auth, int authSz);
/*!
\ingroup wolfTPM2_Wrappers
\brief Wrapper to load the public part of an external key
\note The key must be formatted to the format expected by the TPM, see the 'pub' argument and the alternative wrappers.
\return TPM_RC_SUCCESS: successful
\return TPM_RC_FAILURE: generic failure (check TPM IO and TPM return code)
\return BAD_FUNC_ARG: check the provided arguments
\param dev pointer to a TPM2_DEV struct
\param key pointer to an empty struct of WOLFTPM2_KEY type
\param pub pointer to a populated structure of TPM2B_PUBLIC type
\sa wolfTPM2_LoadRsaPublicKey
\sa wolfTPM2_LoadEccPublicKey
\sa wolfTPM2_wolfTPM2_LoadPrivateKey
*/
WOLFTPM_API int wolfTPM2_LoadPublicKey(WOLFTPM2_DEV* dev, WOLFTPM2_KEY* key,
const TPM2B_PUBLIC* pub);
/*!
\ingroup wolfTPM2_Wrappers
\brief Single function to import an external private key and load it into the TPM in one step
\note The private key material needs to be prepared in a format that the TPM expects, see the 'sens' argument
\return TPM_RC_SUCCESS: successful
\return TPM_RC_FAILURE: generic failure (check TPM IO and TPM return code)
\return BAD_FUNC_ARG: check the provided arguments
\param dev pointer to a TPM2_DEV struct
\param parentKey pointer to a struct of WOLFTPM2_HANDLE type (can be NULL for external keys)
\param key pointer to an empty struct of WOLFTPM2_KEY type
\param pub pointer to a populated structure of TPM2B_PUBLIC type
\param sens pointer to a populated structure of TPM2B_SENSITIVE type
\sa wolfTPM2_CreateKey
\sa wolfTPM2_GetKeyTemplate_RSA
\sa wolfTPM2_GetKeyTemplate_ECC
*/
WOLFTPM_API int wolfTPM2_LoadPrivateKey(WOLFTPM2_DEV* dev,
const WOLFTPM2_KEY* parentKey, WOLFTPM2_KEY* key, const TPM2B_PUBLIC* pub,
TPM2B_SENSITIVE* sens);
/*!
\ingroup wolfTPM2_Wrappers
\brief Single function to import an external private key and load it into the TPM in one step
\note The primary key material needs to be prepared in a format that the TPM expects, see the 'sens' argument
\return TPM_RC_SUCCESS: successful
\return TPM_RC_FAILURE: generic failure (check TPM IO and TPM return code)
\return BAD_FUNC_ARG: check the provided arguments
\param dev pointer to a TPM2_DEV struct
\param parentKey pointer to a struct of WOLFTPM2_HANDLE type (can be NULL for external keys)
\param keyBlob pointer to an empty struct of WOLFTPM2_KEYBLOB type
\param pub pointer to a populated structure of TPM2B_PUBLIC type
\param sens pointer to a populated structure of TPM2B_SENSITIVE type
\sa wolfTPM2_ImportRsaPrivateKey
\sa wolfTPM2_ImportEccPrivateKey
*/
WOLFTPM_API int wolfTPM2_ImportPrivateKey(WOLFTPM2_DEV* dev,
const WOLFTPM2_KEY* parentKey, WOLFTPM2_KEYBLOB* keyBlob, const TPM2B_PUBLIC* pub,
TPM2B_SENSITIVE* sens);
/*!
\ingroup wolfTPM2_Wrappers
\brief Helper function to import the public part of an external RSA key
\note Recommended for use, because it does not require TPM format of the public part
\return TPM_RC_SUCCESS: successful
\return TPM_RC_FAILURE: generic failure (check TPM IO and TPM return code)
\return BAD_FUNC_ARG: check the provided arguments
\param dev pointer to a TPM2_DEV struct
\param key pointer to an empty struct of WOLFTPM2_KEY type
\param rsaPub pointer to a byte buffer containing the public key material
\param rsaPubSz integer value of word32 type, specifying the buffer size
\param exponent integer value of word32 type, specifying the RSA exponent
\sa wolfTPM2_LoadRsaPublicKey_ex
\sa wolfTPM2_LoadPublicKey
\sa wolfTPM2_LoadEccPublicKey
\sa wolfTPM2_ReadPublicKey
*/
WOLFTPM_API int wolfTPM2_LoadRsaPublicKey(WOLFTPM2_DEV* dev, WOLFTPM2_KEY* key,
const byte* rsaPub, word32 rsaPubSz, word32 exponent);
/*!
\ingroup wolfTPM2_Wrappers
\brief Advanced helper function to import the public part of an external RSA key
\note Allows the developer to specify TPM hashing algorithm and RSA scheme
\return TPM_RC_SUCCESS: successful
\return TPM_RC_FAILURE: generic failure (check TPM IO and TPM return code)
\return BAD_FUNC_ARG: check the provided arguments
\param dev pointer to a TPM2_DEV struct
\param key pointer to an empty struct of WOLFTPM2_KEY type
\param rsaPub pointer to a byte buffer containing the public key material
\param rsaPubSz integer value of word32 type, specifying the buffer size
\param exponent integer value of word32 type, specifying the RSA exponent
\param scheme value of TPMI_ALG_RSA_SCHEME type, specifying the RSA scheme
\param hashAlg value of TPMI_ALG_HASH type, specifying the TPM hashing algorithm
\sa wolfTPM2_LoadRsaPublicKey
\sa wolfTPM2_LoadPublicKey
\sa wolfTPM2_LoadEccPublicKey
\sa wolfTPM2_ReadPublicKey
*/
WOLFTPM_API int wolfTPM2_LoadRsaPublicKey_ex(WOLFTPM2_DEV* dev, WOLFTPM2_KEY* key,
const byte* rsaPub, word32 rsaPubSz, word32 exponent,
TPMI_ALG_RSA_SCHEME scheme, TPMI_ALG_HASH hashAlg);
/*!
\ingroup wolfTPM2_Wrappers
\brief Import an external RSA private key
\return TPM_RC_SUCCESS: successful
\return TPM_RC_FAILURE: generic failure (check TPM IO and TPM return code)
\return BAD_FUNC_ARG: check the provided arguments
\return BUFFER_E: arguments size is larger than what the TPM buffers allow
\param dev pointer to a TPM2_DEV struct
\param parentKey pointer to a struct of WOLFTPM2_HANDLE type (can be NULL for external keys and the key will be imported under the OWNER hierarchy)
\param keyBlob pointer to an empty struct of WOLFTPM2_KEYBLOB type
\param rsaPub pointer to a byte buffer, containing the public part of the RSA key
\param rsaPubSz integer value of word32 type, specifying the public part buffer size
\param exponent integer value of word32 type, specifying the RSA exponent
\param rsaPriv pointer to a byte buffer, containing the private material of the RSA key
\param rsaPrivSz integer value of word32 type, specifying the private material buffer size
\param scheme value of TPMI_ALG_RSA_SCHEME type, specifying the RSA scheme
\param hashAlg integer value of TPMI_ALG_HASH type, specifying a supported TPM 2.0 hash algorithm
\sa wolfTPM2_LoadRsaPrivateKey
\sa wolfTPM2_LoadRsaPrivateKey_ex
\sa wolfTPM2_LoadPrivateKey
*/
WOLFTPM_API int wolfTPM2_ImportRsaPrivateKey(WOLFTPM2_DEV* dev,
const WOLFTPM2_KEY* parentKey, WOLFTPM2_KEYBLOB* keyBlob,
const byte* rsaPub, word32 rsaPubSz, word32 exponent,
const byte* rsaPriv, word32 rsaPrivSz,
TPMI_ALG_RSA_SCHEME scheme, TPMI_ALG_HASH hashAlg);
/*!
\ingroup wolfTPM2_Wrappers
\brief Helper function to import and load an external RSA private key in one step
\return TPM_RC_SUCCESS: successful
\return TPM_RC_FAILURE: generic failure (check TPM IO and TPM return code)
\return BAD_FUNC_ARG: check the provided arguments
\param dev pointer to a TPM2_DEV struct
\param parentKey pointer to a struct of WOLFTPM2_HANDLE type (can be NULL for external keys and the key will be imported under the OWNER hierarchy)
\param key pointer to an empty struct of WOLFTPM2_KEY type
\param rsaPub pointer to a byte buffer, containing the public part of the RSA key
\param rsaPubSz integer value of word32 type, specifying the public part buffer size
\param exponent integer value of word32 type, specifying the RSA exponent
\param rsaPriv pointer to a byte buffer, containing the private material of the RSA key
\param rsaPrivSz integer value of word32 type, specifying the private material buffer size
\sa wolfTPM2_ImportRsaPrivateKey
\sa wolfTPM2_LoadRsaPrivateKey_ex
\sa wolfTPM2_LoadPrivateKey
*/
WOLFTPM_API int wolfTPM2_LoadRsaPrivateKey(WOLFTPM2_DEV* dev,
const WOLFTPM2_KEY* parentKey, WOLFTPM2_KEY* key,
const byte* rsaPub, word32 rsaPubSz, word32 exponent,
const byte* rsaPriv, word32 rsaPrivSz);
/*!
\ingroup wolfTPM2_Wrappers
\brief Advanced helper function to import and load an external RSA private key in one step
\return TPM_RC_SUCCESS: successful
\return TPM_RC_FAILURE: generic failure (check TPM IO and TPM return code)
\return BAD_FUNC_ARG: check the provided arguments
\param dev pointer to a TPM2_DEV struct
\param parentKey pointer to a struct of WOLFTPM2_HANDLE type (can be NULL for external keys and the key will be imported under the OWNER hierarchy)
\param key pointer to an empty struct of WOLFTPM2_KEY type
\param rsaPub pointer to a byte buffer, containing the public part of the RSA key
\param rsaPubSz integer value of word32 type, specifying the public part buffer size
\param exponent integer value of word32 type, specifying the RSA exponent
\param rsaPriv pointer to a byte buffer, containing the private material of the RSA key
\param rsaPrivSz integer value of word32 type, specifying the private material buffer size
\param scheme value of TPMI_ALG_RSA_SCHEME type, specifying the RSA scheme
\param hashAlg value of TPMI_ALG_HASH type, specifying the TPM hashing algorithm
\sa wolfTPM2_LoadRsaPrivateKey
\sa wolfTPM2_LoadPrivateKey
\sa wolfTPM2_ImportRsaPrivateKey
\sa wolfTPM2_LoadEccPrivateKey
*/
WOLFTPM_API int wolfTPM2_LoadRsaPrivateKey_ex(WOLFTPM2_DEV* dev,
const WOLFTPM2_KEY* parentKey, WOLFTPM2_KEY* key,
const byte* rsaPub, word32 rsaPubSz, word32 exponent,
const byte* rsaPriv, word32 rsaPrivSz,
TPMI_ALG_RSA_SCHEME scheme, TPMI_ALG_HASH hashAlg);
/*!
\ingroup wolfTPM2_Wrappers
\brief Helper function to import the public part of an external ECC key
\note Recommended for use, because it does not require TPM format of the public part
\return TPM_RC_SUCCESS: successful
\return TPM_RC_FAILURE: generic failure (check TPM IO and TPM return code)
\return BAD_FUNC_ARG: check the provided arguments
\param dev pointer to a TPM2_DEV struct
\param key pointer to an empty struct of WOLFTPM2_KEY type
\param curveId integer value, one of the accepted TPM_ECC_CURVE values
\param eccPubX pointer to a byte buffer containing the public material of point X
\param eccPubXSz integer value of word32 type, specifying the point X buffer size
\param eccPubY pointer to a byte buffer containing the public material of point Y
\param eccPubYSz integer value of word32 type, specifying the point Y buffer size
\sa wolfTPM2_LoadPublicKey
\sa wolfTPM2_LoadRsaPublicKey
\sa wolfTPM2_ReadPublicKey
\sa wolfTPM2_LoadEccPrivateKey
*/
WOLFTPM_API int wolfTPM2_LoadEccPublicKey(WOLFTPM2_DEV* dev, WOLFTPM2_KEY* key,
int curveId, const byte* eccPubX, word32 eccPubXSz,
const byte* eccPubY, word32 eccPubYSz);
/*!
\ingroup wolfTPM2_Wrappers
\brief Helper function to import the private material of an external ECC key
\return TPM_RC_SUCCESS: successful
\return TPM_RC_FAILURE: generic failure (check TPM IO and TPM return code)
\return BAD_FUNC_ARG: check the provided arguments
\param dev pointer to a TPM2_DEV struct
\param parentKey pointer to a struct of WOLFTPM2_HANDLE type (can be NULL for external keys and the key will be imported under the OWNER hierarchy)
\param keyBlob pointer to an empty struct of WOLFTPM2_KEYBLOB type
\param curveId integer value, one of the accepted TPM_ECC_CURVE values
\param eccPubX pointer to a byte buffer containing the public material of point X
\param eccPubXSz integer value of word32 type, specifying the point X buffer size
\param eccPubY pointer to a byte buffer containing the public material of point Y
\param eccPubYSz integer value of word32 type, specifying the point Y buffer size
\param eccPriv pointer to a byte buffer containing the private material
\param eccPrivSz integer value of word32 type, specifying the private material size
\sa wolfTPM2_LoadEccPrivateKey
\sa wolfTPM2_LoadEccPrivateKey_ex
\sa wolfTPM2_LoadPrivateKey
*/
WOLFTPM_API int wolfTPM2_ImportEccPrivateKey(WOLFTPM2_DEV* dev,
const WOLFTPM2_KEY* parentKey, WOLFTPM2_KEYBLOB* keyBlob,
int curveId, const byte* eccPubX, word32 eccPubXSz,
const byte* eccPubY, word32 eccPubYSz,
const byte* eccPriv, word32 eccPrivSz);
/*!
\ingroup wolfTPM2_Wrappers
\brief Helper function to import and load an external ECC private key in one step
\return TPM_RC_SUCCESS: successful
\return TPM_RC_FAILURE: generic failure (check TPM IO and TPM return code)
\return BAD_FUNC_ARG: check the provided arguments
\param dev pointer to a TPM2_DEV struct
\param parentKey pointer to a struct of WOLFTPM2_HANDLE type (can be NULL for external keys and the key will be imported under the OWNER hierarchy)
\param key pointer to an empty struct of WOLFTPM2_KEY type
\param curveId integer value, one of the accepted TPM_ECC_CURVE values
\param eccPubX pointer to a byte buffer containing the public material of point X
\param eccPubXSz integer value of word32 type, specifying the point X buffer size
\param eccPubY pointer to a byte buffer containing the public material of point Y
\param eccPubYSz integer value of word32 type, specifying the point Y buffer size
\param eccPriv pointer to a byte buffer containing the private material
\param eccPrivSz integer value of word32 type, specifying the private material size
\sa wolfTPM2_ImportEccPrivateKey
\sa wolfTPM2_LoadEccPublicKey
\sa wolfTPM2_LoadPrivateKey
*/
WOLFTPM_API int wolfTPM2_LoadEccPrivateKey(WOLFTPM2_DEV* dev,
const WOLFTPM2_KEY* parentKey, WOLFTPM2_KEY* key,
int curveId, const byte* eccPubX, word32 eccPubXSz,
const byte* eccPubY, word32 eccPubYSz,
const byte* eccPriv, word32 eccPrivSz);
/*!
\ingroup wolfTPM2_Wrappers
\brief Helper function to receive the public part of a loaded TPM object using its handle
\note The public part of a TPM symmetric keys contains just TPM meta data
\return TPM_RC_SUCCESS: successful
\return TPM_RC_FAILURE: generic failure (check TPM IO and TPM return code)
\return BAD_FUNC_ARG: check the provided arguments
\param dev pointer to a TPM2_DEV struct
\param key pointer to an empty struct of WOLFTPM2_KEY type
\param handle integer value of TPM_HANDLE type, specifying handle of a loaded TPM object
\sa wolfTPM2_LoadRsaPublicKey
\sa wolfTPM2_LoadEccPublicKey
\sa wolfTPM2_LoadPublicKey
*/
WOLFTPM_API int wolfTPM2_ReadPublicKey(WOLFTPM2_DEV* dev, WOLFTPM2_KEY* key,
const TPM_HANDLE handle);
/*!
\ingroup wolfTPM2_Wrappers
\brief Using this wrapper a secret can be sealed inside a TPM 2.0 Key
\note The secret size can not be larger than 128 bytes
\return TPM_RC_SUCCESS: successful
\return TPM_RC_FAILURE: generic failure (check TPM IO and TPM return code)
\return BAD_FUNC_ARG: check the provided arguments
\param dev pointer to a TPM2_DEV struct
\param keyBlob pointer to an empty struct of WOLFTPM2_KEYBLOB type
\param parent pointer to a struct of WOLFTPM2_HANDLE type, specifying the a 2.0 Primary Key to be used as the parent(Storage Key)
\param publicTemplate pointer to a TPMT_PUBLIC structure populated using one of the wolfTPM2_GetKeyTemplate_KeySeal
\param auth pointer to a string constant, specifying the password authorization for the TPM 2.0 Key
\param authSz integer value, specifying the size of the password authorization, in bytes
\param sealData pointer to a byte buffer, containing the secret(user data) to be sealed
\param sealSize integer value, specifying the size of the seal buffer, in bytes
\sa wolfTPM2_GetKeyTemplate_KeySeal
\sa TPM2_Unseal
\sa wolfTPM2_CreatePrimary
*/
WOLFTPM_API int wolfTPM2_CreateKeySeal(WOLFTPM2_DEV* dev,
WOLFTPM2_KEYBLOB* keyBlob, WOLFTPM2_HANDLE* parent,
TPMT_PUBLIC* publicTemplate, const byte* auth, int authSz,
const byte* sealData, int sealSize);
/*!
\ingroup wolfTPM2_Wrappers
\brief Helper function to generate a hash of the public area of an object in the format expected by the TPM
\note Computed TPM name includes hash of the TPM_ALG_ID and the public are of the object
\return TPM_RC_SUCCESS: successful
\return TPM_RC_FAILURE: generic failure (check TPM IO and TPM return code)
\return BAD_FUNC_ARG: check the provided arguments
\param pub pointer to a populated structure of TPM2B_PUBLIC type, containing the public area of a TPM object
\param out pointer to an empty struct of TPM2B_NAME type, to store the computed name
\sa wolfTPM2_ImportPrivateKey
*/
WOLFTPM_API int wolfTPM2_ComputeName(const TPM2B_PUBLIC* pub, TPM2B_NAME* out);
/*!
\ingroup wolfTPM2_Wrappers
\brief Helper function to convert TPM2B_SENSITIVE to TPM2B_PRIVATE