3
* Licensed Materials - Property of IBM
5
* trousers - An open source TCG Software Stack
7
* (C) Copyright International Business Machines Corp. 2007
17
#include "trousers/tss.h"
18
#include "trousers/trousers.h"
19
#include "trousers_types.h"
20
#include "spi_utils.h"
21
#include "capabilities.h"
27
migdata_free(void *data)
29
struct tr_migdata_obj *migdata = (struct tr_migdata_obj *)data;
35
obj_is_migdata(TSS_HOBJECT hObject)
37
TSS_BOOL answer = FALSE;
39
if ((obj_list_get_obj(&migdata_list, hObject))) {
41
obj_list_put(&migdata_list);
48
obj_migdata_add(TSS_HCONTEXT hContext, TSS_HOBJECT *phObject)
51
struct tr_migdata_obj *migdata = calloc(1, sizeof(struct tr_migdata_obj));
53
if (migdata == NULL) {
54
LogError("malloc of %zd bytes failed.", sizeof(struct tr_migdata_obj));
55
return TSPERR(TSS_E_OUTOFMEMORY);
58
if ((result = obj_list_add(&migdata_list, hContext, 0, migdata, phObject))) {
67
obj_migdata_remove(TSS_HMIGDATA hMigData, TSS_HCONTEXT hContext)
71
if ((result = obj_list_remove(&migdata_list, &migdata_free, hMigData, hContext)))
78
obj_migdata_get_tsp_context(TSS_HMIGDATA hMigData, TSS_HCONTEXT *hContext)
80
struct tsp_object *obj;
82
if ((obj = obj_list_get_obj(&migdata_list, hMigData)) == NULL)
83
return TSPERR(TSS_E_INVALID_HANDLE);
85
*hContext = obj->tspContext;
87
obj_list_put(&migdata_list);
93
obj_migdata_set_migrationblob(TSS_HMIGDATA hMigData, UINT32 whichOne, UINT32 blobSize, BYTE *blob)
98
case TSS_MIGATTRIB_MIG_MSALIST_PUBKEY_BLOB:
99
result = obj_migdata_set_msa_pubkey(hMigData, blobSize, blob);
101
case TSS_MIGATTRIB_MIG_AUTHORITY_PUBKEY_BLOB:
102
result = obj_migdata_set_ma_pubkey(hMigData, blobSize, blob);
104
case TSS_MIGATTRIB_MIG_DESTINATION_PUBKEY_BLOB:
105
result = obj_migdata_set_dest_pubkey(hMigData, blobSize, blob);
107
case TSS_MIGATTRIB_MIG_SOURCE_PUBKEY_BLOB:
108
result = obj_migdata_set_src_pubkey(hMigData, blobSize, blob);
111
result = TSPERR(TSS_E_BAD_PARAMETER);
118
obj_migdata_get_migrationblob(TSS_HMIGDATA hMigData, UINT32 whichOne, UINT32 *blobSize, BYTE **blob)
123
case TSS_MIGATTRIB_MIG_XOR_BLOB:
124
result = obj_migdata_get_blob(hMigData, blobSize, blob);
127
result = TSPERR(TSS_E_BAD_PARAMETER);
134
obj_migdata_set_authoritydata(TSS_HMIGDATA hMigData, UINT32 whichOne, UINT32 blobSize, BYTE *blob)
139
case TSS_MIGATTRIB_AUTHORITY_DIGEST:
140
result = obj_migdata_set_msa_digest(hMigData, blobSize, blob);
142
case TSS_MIGATTRIB_AUTHORITY_APPROVAL_HMAC:
143
result = obj_migdata_set_msa_hmac(hMigData, blobSize, blob);
145
case TSS_MIGATTRIB_AUTHORITY_MSALIST:
146
result = obj_migdata_set_msa_list(hMigData, blobSize, blob);
149
result = TSPERR(TSS_E_BAD_PARAMETER);
156
obj_migdata_get_authoritydata(TSS_HMIGDATA hMigData, UINT32 whichOne, UINT32 *blobSize, BYTE **blob)
161
case TSS_MIGATTRIB_AUTHORITY_DIGEST:
162
result = obj_migdata_get_msa_digest(hMigData, blobSize, blob);
164
case TSS_MIGATTRIB_AUTHORITY_APPROVAL_HMAC:
165
result = obj_migdata_get_msa_hmac(hMigData, blobSize, blob);
167
case TSS_MIGATTRIB_AUTHORITY_MSALIST:
168
result = obj_migdata_get_msa_list(hMigData, blobSize, blob);
171
result = TSPERR(TSS_E_BAD_PARAMETER);
178
obj_migdata_set_migauthdata(TSS_HMIGDATA hMigData, UINT32 whichOne, UINT32 blobSize, BYTE *blob)
183
case TSS_MIGATTRIB_MIG_AUTH_AUTHORITY_DIGEST:
184
result = obj_migdata_set_ma_digest(hMigData, blobSize, blob);
186
case TSS_MIGATTRIB_MIG_AUTH_DESTINATION_DIGEST:
187
result = obj_migdata_set_dest_digest(hMigData, blobSize, blob);
189
case TSS_MIGATTRIB_MIG_AUTH_SOURCE_DIGEST:
190
result = obj_migdata_set_src_digest(hMigData, blobSize, blob);
193
result = TSPERR(TSS_E_BAD_PARAMETER);
200
obj_migdata_get_migauthdata(TSS_HMIGDATA hMigData, UINT32 whichOne, UINT32 *blobSize, BYTE **blob)
205
case TSS_MIGATTRIB_MIG_AUTH_AUTHORITY_DIGEST:
206
result = obj_migdata_get_ma_digest(hMigData, blobSize, blob);
208
case TSS_MIGATTRIB_MIG_AUTH_DESTINATION_DIGEST:
209
result = obj_migdata_get_dest_digest(hMigData, blobSize, blob);
211
case TSS_MIGATTRIB_MIG_AUTH_SOURCE_DIGEST:
212
result = obj_migdata_get_src_digest(hMigData, blobSize, blob);
215
result = TSPERR(TSS_E_BAD_PARAMETER);
222
obj_migdata_set_ticketdata(TSS_HMIGDATA hMigData, UINT32 whichOne, UINT32 blobSize, BYTE *blob)
227
case TSS_MIGATTRIB_TICKET_SIG_DIGEST:
228
result = obj_migdata_set_sig_data(hMigData, blobSize, blob);
230
case TSS_MIGATTRIB_TICKET_SIG_VALUE:
231
result = obj_migdata_set_sig_value(hMigData, blobSize, blob);
233
case TSS_MIGATTRIB_TICKET_SIG_TICKET:
234
result = obj_migdata_set_sig_ticket(hMigData, blobSize, blob);
236
case TSS_MIGATTRIB_TICKET_RESTRICT_TICKET:
237
result = obj_migdata_set_cmk_auth(hMigData, blobSize, blob);
240
result = TSPERR(TSS_E_BAD_PARAMETER);
247
obj_migdata_get_ticketdata(TSS_HMIGDATA hMigData, UINT32 whichOne, UINT32 *blobSize, BYTE **blob)
252
case TSS_MIGATTRIB_TICKET_SIG_TICKET:
253
result = obj_migdata_get_sig_ticket(hMigData, blobSize, blob);
256
result = TSPERR(TSS_E_BAD_PARAMETER);
263
obj_migdata_set_ticket_blob(TSS_HMIGDATA hMigData, UINT32 migTicketSize, BYTE *migTicket)
265
struct tsp_object *obj;
266
struct tr_migdata_obj *migdata;
267
TSS_RESULT result = TSS_SUCCESS;
269
if ((obj = obj_list_get_obj(&migdata_list, hMigData)) == NULL)
270
return TSPERR(TSS_E_INVALID_HANDLE);
272
migdata = (struct tr_migdata_obj *)obj->data;
274
migdata->migTicketSize = 0;
275
free(migdata->migTicket);
276
if ((migdata->migTicket = malloc(migTicketSize)) == NULL) {
277
LogError("malloc of %u bytes failed.", migTicketSize);
278
result = TSPERR(TSS_E_OUTOFMEMORY);
281
memcpy(migdata->migTicket, migTicket, migTicketSize);
282
migdata->migTicketSize = migTicketSize;
285
obj_list_put(&migdata_list);
291
obj_migdata_get_ticket_blob(TSS_HMIGDATA hMigData, UINT32 *migTicketSize, BYTE **migTicket)
293
struct tsp_object *obj;
294
struct tr_migdata_obj *migdata;
295
TSS_RESULT result = TSS_SUCCESS;
297
if ((obj = obj_list_get_obj(&migdata_list, hMigData)) == NULL)
298
return TSPERR(TSS_E_INVALID_HANDLE);
300
migdata = (struct tr_migdata_obj *)obj->data;
302
if ((*migTicket = calloc_tspi(obj->tspContext, migdata->migTicketSize)) == NULL) {
303
LogError("malloc of %u bytes failed.", migdata->migTicketSize);
304
result = TSPERR(TSS_E_OUTOFMEMORY);
307
memcpy(*migTicket, migdata->migTicket, migdata->migTicketSize);
308
*migTicketSize = migdata->migTicketSize;
311
obj_list_put(&migdata_list);
317
obj_migdata_set_msa_list(TSS_HMIGDATA hMigData, UINT32 msaListSize, BYTE *msaList)
319
struct tsp_object *obj;
320
struct tr_migdata_obj *migdata;
321
UINT32 i, count, size;
323
TSS_RESULT result = TSS_SUCCESS;
325
if ((obj = obj_list_get_obj(&migdata_list, hMigData)) == NULL)
326
return TSPERR(TSS_E_INVALID_HANDLE);
328
migdata = (struct tr_migdata_obj *)obj->data;
330
count = msaListSize / sizeof(digest->digest);
331
size = count * sizeof(*digest);
333
migdata->msaList.MSAlist = 0;
334
free(migdata->msaList.migAuthDigest);
335
if ((migdata->msaList.migAuthDigest = malloc(size)) == NULL) {
336
LogError("malloc of %u bytes failed.", size);
337
result = TSPERR(TSS_E_OUTOFMEMORY);
340
digest = migdata->msaList.migAuthDigest;
341
for (i = 0; i < count; i++) {
342
memcpy(digest->digest, msaList, sizeof(digest->digest));
343
msaList += sizeof(digest->digest);
346
migdata->msaList.MSAlist = count;
348
result = obj_migdata_calc_msa_digest(migdata);
351
obj_list_put(&migdata_list);
357
obj_migdata_get_msa_list(TSS_HMIGDATA hMigData, UINT32 *size, BYTE **msaList)
359
struct tsp_object *obj;
360
struct tr_migdata_obj *migdata;
364
TSS_RESULT result = TSS_SUCCESS;
366
if ((obj = obj_list_get_obj(&migdata_list, hMigData)) == NULL)
367
return TSPERR(TSS_E_INVALID_HANDLE);
369
migdata = (struct tr_migdata_obj *)obj->data;
371
*size = migdata->msaList.MSAlist * sizeof(migdata->msaList.migAuthDigest->digest);
372
if ((*msaList = calloc_tspi(obj->tspContext, *size)) == NULL) {
373
LogError("malloc of %u bytes failed.", *size);
374
result = TSPERR(TSS_E_OUTOFMEMORY);
377
tmpMsaList = *msaList;
378
digest = migdata->msaList.migAuthDigest;
379
for (i = 0; i < migdata->msaList.MSAlist; i++) {
380
memcpy(tmpMsaList, digest->digest, sizeof(digest->digest));
381
tmpMsaList += sizeof(digest->digest);
386
obj_list_put(&migdata_list);
392
obj_migdata_set_msa_pubkey(TSS_HMIGDATA hMigData, UINT32 blobSize, BYTE *pubKeyBlob)
394
struct tsp_object *obj;
395
struct tr_migdata_obj *migdata;
397
TPM_DIGEST msaDigest;
399
TSS_RESULT result = TSS_SUCCESS;
401
if ((obj = obj_list_get_obj(&migdata_list, hMigData)) == NULL)
402
return TSPERR(TSS_E_INVALID_HANDLE);
404
migdata = (struct tr_migdata_obj *)obj->data;
406
if ((result = obj_migdata_calc_pubkey_digest(blobSize, pubKeyBlob, &msaDigest)))
409
size = (migdata->msaList.MSAlist + 1) * sizeof(*digest);
410
if ((migdata->msaList.migAuthDigest = realloc(migdata->msaList.migAuthDigest, size)) == NULL) {
411
LogError("malloc of %u bytes failed.", size);
412
result = TSPERR(TSS_E_OUTOFMEMORY);
415
digest = migdata->msaList.migAuthDigest + migdata->msaList.MSAlist;
417
migdata->msaList.MSAlist++;
419
result = obj_migdata_calc_msa_digest(migdata);
422
obj_list_put(&migdata_list);
428
obj_migdata_set_msa_digest(TSS_HMIGDATA hMigData, UINT32 digestSize, BYTE *digest)
430
struct tsp_object *obj;
431
struct tr_migdata_obj *migdata;
432
TSS_RESULT result = TSS_SUCCESS;
434
if ((obj = obj_list_get_obj(&migdata_list, hMigData)) == NULL)
435
return TSPERR(TSS_E_INVALID_HANDLE);
437
migdata = (struct tr_migdata_obj *)obj->data;
439
if (digestSize != sizeof(migdata->msaDigest.digest)) {
440
result = TSPERR(TSS_E_BAD_PARAMETER);
443
memcpy(migdata->msaDigest.digest, digest, sizeof(migdata->msaDigest.digest));
446
obj_list_put(&migdata_list);
452
obj_migdata_get_msa_digest(TSS_HMIGDATA hMigData, UINT32 *digestSize, BYTE **digest)
454
struct tsp_object *obj;
455
struct tr_migdata_obj *migdata;
456
TSS_RESULT result = TSS_SUCCESS;
458
if ((obj = obj_list_get_obj(&migdata_list, hMigData)) == NULL)
459
return TSPERR(TSS_E_INVALID_HANDLE);
461
migdata = (struct tr_migdata_obj *)obj->data;
463
if ((*digest = calloc_tspi(obj->tspContext, sizeof(migdata->msaDigest.digest))) == NULL) {
464
LogError("malloc of %zd bytes failed.", sizeof(migdata->msaDigest.digest));
465
result = TSPERR(TSS_E_OUTOFMEMORY);
468
memcpy(*digest, migdata->msaDigest.digest, sizeof(migdata->msaDigest.digest));
469
*digestSize = sizeof(migdata->msaDigest.digest);
472
obj_list_put(&migdata_list);
478
obj_migdata_get_msa_list_blob(TSS_HMIGDATA hMigData, UINT32 *blobSize, BYTE **msaListBlob)
480
struct tsp_object *obj;
481
struct tr_migdata_obj *migdata;
483
TSS_RESULT result = TSS_SUCCESS;
485
if ((obj = obj_list_get_obj(&migdata_list, hMigData)) == NULL)
486
return TSPERR(TSS_E_INVALID_HANDLE);
488
migdata = (struct tr_migdata_obj *)obj->data;
491
Trspi_LoadBlob_MSA_COMPOSITE(&offset, NULL, &migdata->msaList);
494
if ((*msaListBlob = calloc_tspi(obj->tspContext, *blobSize)) == NULL) {
495
LogError("malloc of %u bytes failed.", *blobSize);
496
result = TSPERR(TSS_E_OUTOFMEMORY);
500
Trspi_LoadBlob_MSA_COMPOSITE(&offset, *msaListBlob, &migdata->msaList);
503
obj_list_put(&migdata_list);
509
obj_migdata_set_msa_hmac(TSS_HMIGDATA hMigData, UINT32 hmacSize, BYTE *hmac)
511
struct tsp_object *obj;
512
struct tr_migdata_obj *migdata;
513
TSS_RESULT result = TSS_SUCCESS;
515
if ((obj = obj_list_get_obj(&migdata_list, hMigData)) == NULL)
516
return TSPERR(TSS_E_INVALID_HANDLE);
518
migdata = (struct tr_migdata_obj *)obj->data;
520
if (hmacSize != sizeof(migdata->msaHmac.digest)) {
521
result = TSPERR(TSS_E_BAD_PARAMETER);
524
memcpy(migdata->msaHmac.digest, hmac, sizeof(migdata->msaHmac.digest));
527
obj_list_put(&migdata_list);
533
obj_migdata_get_msa_hmac(TSS_HMIGDATA hMigData, UINT32 *hmacSize, BYTE **hmac)
535
struct tsp_object *obj;
536
struct tr_migdata_obj *migdata;
537
TSS_RESULT result = TSS_SUCCESS;
539
if ((obj = obj_list_get_obj(&migdata_list, hMigData)) == NULL)
540
return TSPERR(TSS_E_INVALID_HANDLE);
542
migdata = (struct tr_migdata_obj *)obj->data;
544
if ((*hmac = calloc_tspi(obj->tspContext, sizeof(migdata->msaHmac.digest))) == NULL) {
545
LogError("malloc of %zd bytes failed.", sizeof(migdata->msaHmac.digest));
546
result = TSPERR(TSS_E_OUTOFMEMORY);
549
memcpy(*hmac, migdata->msaHmac.digest, sizeof(migdata->msaHmac.digest));
550
*hmacSize = sizeof(migdata->msaHmac.digest);
553
obj_list_put(&migdata_list);
559
obj_migdata_set_ma_pubkey(TSS_HMIGDATA hMigData, UINT32 blobSize, BYTE *pubKeyBlob)
561
struct tsp_object *obj;
562
struct tr_migdata_obj *migdata;
563
TPM_DIGEST pubKeyDigest;
564
TSS_RESULT result = TSS_SUCCESS;
566
if ((obj = obj_list_get_obj(&migdata_list, hMigData)) == NULL)
567
return TSPERR(TSS_E_INVALID_HANDLE);
569
migdata = (struct tr_migdata_obj *)obj->data;
571
if ((result = obj_migdata_calc_pubkey_digest(blobSize, pubKeyBlob, &pubKeyDigest)))
574
migdata->maDigest = pubKeyDigest;
576
obj_migdata_calc_sig_data_digest(migdata);
579
obj_list_put(&migdata_list);
585
obj_migdata_set_ma_digest(TSS_HMIGDATA hMigData, UINT32 digestSize, BYTE *digest)
587
struct tsp_object *obj;
588
struct tr_migdata_obj *migdata;
589
TSS_RESULT result = TSS_SUCCESS;
591
if ((obj = obj_list_get_obj(&migdata_list, hMigData)) == NULL)
592
return TSPERR(TSS_E_INVALID_HANDLE);
594
migdata = (struct tr_migdata_obj *)obj->data;
596
if (digestSize != sizeof(migdata->maDigest.digest)) {
597
result = TSPERR(TSS_E_BAD_PARAMETER);
600
memcpy(migdata->maDigest.digest, digest, sizeof(migdata->maDigest.digest));
602
obj_migdata_calc_sig_data_digest(migdata);
605
obj_list_put(&migdata_list);
611
obj_migdata_get_ma_digest(TSS_HMIGDATA hMigData, UINT32 *digestSize, BYTE **digest)
613
struct tsp_object *obj;
614
struct tr_migdata_obj *migdata;
615
TSS_RESULT result = TSS_SUCCESS;
617
if ((obj = obj_list_get_obj(&migdata_list, hMigData)) == NULL)
618
return TSPERR(TSS_E_INVALID_HANDLE);
620
migdata = (struct tr_migdata_obj *)obj->data;
622
if ((*digest = calloc_tspi(obj->tspContext, sizeof(migdata->maDigest.digest))) == NULL) {
623
LogError("malloc of %zd bytes failed.", sizeof(migdata->maDigest.digest));
624
result = TSPERR(TSS_E_OUTOFMEMORY);
627
memcpy(*digest, migdata->maDigest.digest, sizeof(migdata->maDigest.digest));
628
*digestSize = sizeof(migdata->maDigest.digest);
631
obj_list_put(&migdata_list);
637
obj_migdata_set_dest_pubkey(TSS_HMIGDATA hMigData, UINT32 blobSize, BYTE *pubKeyBlob)
639
struct tsp_object *obj;
640
struct tr_migdata_obj *migdata;
641
TPM_DIGEST pubKeyDigest;
642
TSS_RESULT result = TSS_SUCCESS;
644
if ((obj = obj_list_get_obj(&migdata_list, hMigData)) == NULL)
645
return TSPERR(TSS_E_INVALID_HANDLE);
647
migdata = (struct tr_migdata_obj *)obj->data;
649
if ((result = obj_migdata_calc_pubkey_digest(blobSize, pubKeyBlob, &pubKeyDigest)))
652
migdata->destDigest = pubKeyDigest;
654
obj_migdata_calc_sig_data_digest(migdata);
657
obj_list_put(&migdata_list);
663
obj_migdata_set_dest_digest(TSS_HMIGDATA hMigData, UINT32 digestSize, BYTE *digest)
665
struct tsp_object *obj;
666
struct tr_migdata_obj *migdata;
667
TSS_RESULT result = TSS_SUCCESS;
669
if ((obj = obj_list_get_obj(&migdata_list, hMigData)) == NULL)
670
return TSPERR(TSS_E_INVALID_HANDLE);
672
migdata = (struct tr_migdata_obj *)obj->data;
674
if (digestSize != sizeof(migdata->destDigest.digest)) {
675
result = TSPERR(TSS_E_BAD_PARAMETER);
678
memcpy(migdata->destDigest.digest, digest, sizeof(migdata->destDigest.digest));
680
obj_migdata_calc_sig_data_digest(migdata);
683
obj_list_put(&migdata_list);
689
obj_migdata_get_dest_digest(TSS_HMIGDATA hMigData, UINT32 *digestSize, BYTE **digest)
691
struct tsp_object *obj;
692
struct tr_migdata_obj *migdata;
693
TSS_RESULT result = TSS_SUCCESS;
695
if ((obj = obj_list_get_obj(&migdata_list, hMigData)) == NULL)
696
return TSPERR(TSS_E_INVALID_HANDLE);
698
migdata = (struct tr_migdata_obj *)obj->data;
700
if ((*digest = calloc_tspi(obj->tspContext, sizeof(migdata->destDigest.digest))) == NULL) {
701
LogError("malloc of %zd bytes failed.", sizeof(migdata->destDigest.digest));
702
result = TSPERR(TSS_E_OUTOFMEMORY);
705
memcpy(*digest, migdata->destDigest.digest, sizeof(migdata->destDigest.digest));
706
*digestSize = sizeof(migdata->destDigest.digest);
709
obj_list_put(&migdata_list);
715
obj_migdata_set_src_pubkey(TSS_HMIGDATA hMigData, UINT32 blobSize, BYTE *pubKeyBlob)
717
struct tsp_object *obj;
718
struct tr_migdata_obj *migdata;
719
TPM_DIGEST pubKeyDigest;
720
TSS_RESULT result = TSS_SUCCESS;
722
if ((obj = obj_list_get_obj(&migdata_list, hMigData)) == NULL)
723
return TSPERR(TSS_E_INVALID_HANDLE);
725
migdata = (struct tr_migdata_obj *)obj->data;
727
if ((result = obj_migdata_calc_pubkey_digest(blobSize, pubKeyBlob, &pubKeyDigest)))
730
migdata->srcDigest = pubKeyDigest;
732
obj_migdata_calc_sig_data_digest(migdata);
735
obj_list_put(&migdata_list);
741
obj_migdata_set_src_digest(TSS_HMIGDATA hMigData, UINT32 digestSize, BYTE *digest)
743
struct tsp_object *obj;
744
struct tr_migdata_obj *migdata;
745
TSS_RESULT result = TSS_SUCCESS;
747
if ((obj = obj_list_get_obj(&migdata_list, hMigData)) == NULL)
748
return TSPERR(TSS_E_INVALID_HANDLE);
750
migdata = (struct tr_migdata_obj *)obj->data;
752
if (digestSize != sizeof(migdata->srcDigest.digest)) {
753
result = TSPERR(TSS_E_BAD_PARAMETER);
756
memcpy(migdata->srcDigest.digest, digest, sizeof(migdata->srcDigest.digest));
758
obj_migdata_calc_sig_data_digest(migdata);
761
obj_list_put(&migdata_list);
767
obj_migdata_get_src_digest(TSS_HMIGDATA hMigData, UINT32 *digestSize, BYTE **digest)
769
struct tsp_object *obj;
770
struct tr_migdata_obj *migdata;
771
TSS_RESULT result = TSS_SUCCESS;
773
if ((obj = obj_list_get_obj(&migdata_list, hMigData)) == NULL)
774
return TSPERR(TSS_E_INVALID_HANDLE);
776
migdata = (struct tr_migdata_obj *)obj->data;
778
if ((*digest = calloc_tspi(obj->tspContext, sizeof(migdata->srcDigest.digest))) == NULL) {
779
LogError("malloc of %zd bytes failed.", sizeof(migdata->srcDigest.digest));
780
result = TSPERR(TSS_E_OUTOFMEMORY);
783
memcpy(*digest, migdata->srcDigest.digest, sizeof(migdata->srcDigest.digest));
784
*digestSize = sizeof(migdata->srcDigest.digest);
787
obj_list_put(&migdata_list);
793
obj_migdata_set_cmk_auth(TSS_HMIGDATA hMigData, UINT32 digestsSize, BYTE *digests)
795
struct tsp_object *obj;
796
struct tr_migdata_obj *migdata;
797
TSS_RESULT result = TSS_SUCCESS;
799
if ((obj = obj_list_get_obj(&migdata_list, hMigData)) == NULL)
800
return TSPERR(TSS_E_INVALID_HANDLE);
802
migdata = (struct tr_migdata_obj *)obj->data;
804
if (digestsSize != (sizeof(migdata->maDigest.digest) +
805
sizeof(migdata->destDigest.digest) +
806
sizeof(migdata->srcDigest.digest))) {
807
result = TSPERR(TSS_E_BAD_PARAMETER);
810
memcpy(migdata->maDigest.digest, digests, sizeof(migdata->maDigest.digest));
811
digests += sizeof(migdata->maDigest.digest);
812
memcpy(migdata->destDigest.digest, digests, sizeof(migdata->destDigest.digest));
813
digests += sizeof(migdata->destDigest.digest);
814
memcpy(migdata->srcDigest.digest, digests, sizeof(migdata->srcDigest.digest));
816
obj_migdata_calc_sig_data_digest(migdata);
819
obj_list_put(&migdata_list);
825
obj_migdata_get_cmk_auth(TSS_HMIGDATA hMigData, TPM_CMK_AUTH *cmkAuth)
827
struct tsp_object *obj;
828
struct tr_migdata_obj *migdata;
830
if ((obj = obj_list_get_obj(&migdata_list, hMigData)) == NULL)
831
return TSPERR(TSS_E_INVALID_HANDLE);
833
migdata = (struct tr_migdata_obj *)obj->data;
835
cmkAuth->migrationAuthorityDigest = migdata->maDigest;
836
cmkAuth->destinationKeyDigest = migdata->destDigest;
837
cmkAuth->sourceKeyDigest = migdata->srcDigest;
839
obj_list_put(&migdata_list);
845
obj_migdata_get_cmk_auth_blob(TSS_HMIGDATA hMigData, UINT32 *blobSize, BYTE **cmkAuthBlob)
847
struct tsp_object *obj;
848
TPM_CMK_AUTH cmkAuth;
852
if ((result = obj_migdata_get_cmk_auth(hMigData, &cmkAuth)))
855
if ((obj = obj_list_get_obj(&migdata_list, hMigData)) == NULL)
856
return TSPERR(TSS_E_INVALID_HANDLE);
859
Trspi_LoadBlob_CMK_AUTH(&offset, NULL, &cmkAuth);
862
if ((*cmkAuthBlob = calloc_tspi(obj->tspContext, *blobSize)) == NULL) {
863
LogError("malloc of %u bytes failed.", *blobSize);
864
result = TSPERR(TSS_E_OUTOFMEMORY);
868
Trspi_LoadBlob_CMK_AUTH(&offset, *cmkAuthBlob, &cmkAuth);
871
obj_list_put(&migdata_list);
877
obj_migdata_set_sig_data(TSS_HMIGDATA hMigData, UINT32 sigDataSize, BYTE *sigData)
879
struct tsp_object *obj;
880
struct tr_migdata_obj *migdata;
881
TSS_RESULT result = TSS_SUCCESS;
883
if ((obj = obj_list_get_obj(&migdata_list, hMigData)) == NULL)
884
return TSPERR(TSS_E_INVALID_HANDLE);
886
migdata = (struct tr_migdata_obj *)obj->data;
888
if (sigDataSize != sizeof(migdata->sigData.digest)) {
889
result = TSPERR(TSS_E_BAD_PARAMETER);
892
memcpy(migdata->sigData.digest, sigData, sizeof(migdata->sigData.digest));
895
obj_list_put(&migdata_list);
901
obj_migdata_get_sig_data(TSS_HMIGDATA hMigData, UINT32 *sigDataSize, BYTE **sigData)
903
struct tsp_object *obj;
904
struct tr_migdata_obj *migdata;
905
TSS_RESULT result = TSS_SUCCESS;
907
if ((obj = obj_list_get_obj(&migdata_list, hMigData)) == NULL)
908
return TSPERR(TSS_E_INVALID_HANDLE);
910
migdata = (struct tr_migdata_obj *)obj->data;
912
if ((*sigData = calloc_tspi(obj->tspContext, sizeof(migdata->sigData.digest))) == NULL) {
913
LogError("malloc of %zd bytes failed.", sizeof(migdata->sigData.digest));
914
result = TSPERR(TSS_E_OUTOFMEMORY);
917
memcpy(*sigData, migdata->sigData.digest, sizeof(migdata->sigData.digest));
918
*sigDataSize = sizeof(migdata->sigData.digest);
921
obj_list_put(&migdata_list);
927
obj_migdata_set_sig_value(TSS_HMIGDATA hMigData, UINT32 sigValueSize, BYTE *sigValue)
929
struct tsp_object *obj;
930
struct tr_migdata_obj *migdata;
931
TSS_RESULT result = TSS_SUCCESS;
933
if ((obj = obj_list_get_obj(&migdata_list, hMigData)) == NULL)
934
return TSPERR(TSS_E_INVALID_HANDLE);
936
migdata = (struct tr_migdata_obj *)obj->data;
938
migdata->sigValueSize = 0;
939
free(migdata->sigValue);
940
if ((migdata->sigValue = malloc(sigValueSize)) == NULL) {
941
LogError("malloc of %u bytes failed.", sigValueSize);
942
result = TSPERR(TSS_E_OUTOFMEMORY);
945
memcpy(migdata->sigValue, sigValue, sigValueSize);
946
migdata->sigValueSize = sigValueSize;
949
obj_list_put(&migdata_list);
955
obj_migdata_get_sig_value(TSS_HMIGDATA hMigData, UINT32 *sigValueSize, BYTE **sigValue)
957
struct tsp_object *obj;
958
struct tr_migdata_obj *migdata;
959
TSS_RESULT result = TSS_SUCCESS;
961
if ((obj = obj_list_get_obj(&migdata_list, hMigData)) == NULL)
962
return TSPERR(TSS_E_INVALID_HANDLE);
964
migdata = (struct tr_migdata_obj *)obj->data;
966
if ((*sigValue = calloc_tspi(obj->tspContext, migdata->sigValueSize)) == NULL) {
967
LogError("malloc of %u bytes failed.", migdata->sigValueSize);
968
result = TSPERR(TSS_E_OUTOFMEMORY);
971
memcpy(*sigValue, migdata->sigValue, migdata->sigValueSize);
972
*sigValueSize = migdata->sigValueSize;
975
obj_list_put(&migdata_list);
981
obj_migdata_set_sig_ticket(TSS_HMIGDATA hMigData, UINT32 sigTicketSize, BYTE *sigTicket)
983
struct tsp_object *obj;
984
struct tr_migdata_obj *migdata;
985
TSS_RESULT result = TSS_SUCCESS;
987
if ((obj = obj_list_get_obj(&migdata_list, hMigData)) == NULL)
988
return TSPERR(TSS_E_INVALID_HANDLE);
990
migdata = (struct tr_migdata_obj *)obj->data;
992
if (sigTicketSize != sizeof(migdata->sigTicket.digest)) {
993
result = TSPERR(TSS_E_BAD_PARAMETER);
996
memcpy(migdata->sigTicket.digest, sigTicket, sizeof(migdata->sigTicket.digest));
999
obj_list_put(&migdata_list);
1005
obj_migdata_get_sig_ticket(TSS_HMIGDATA hMigData, UINT32 *sigTicketSize, BYTE **sigTicket)
1007
struct tsp_object *obj;
1008
struct tr_migdata_obj *migdata;
1009
TSS_RESULT result = TSS_SUCCESS;
1011
if ((obj = obj_list_get_obj(&migdata_list, hMigData)) == NULL)
1012
return TSPERR(TSS_E_INVALID_HANDLE);
1014
migdata = (struct tr_migdata_obj *)obj->data;
1016
if ((*sigTicket = calloc_tspi(obj->tspContext, sizeof(migdata->sigTicket.digest))) == NULL) {
1017
LogError("malloc of %zd bytes failed.", sizeof(migdata->sigTicket.digest));
1018
result = TSPERR(TSS_E_OUTOFMEMORY);
1021
memcpy(*sigTicket, migdata->sigTicket.digest, sizeof(migdata->sigTicket.digest));
1022
*sigTicketSize = sizeof(migdata->sigTicket.digest);
1025
obj_list_put(&migdata_list);
1031
obj_migdata_set_blob(TSS_HMIGDATA hMigData, UINT32 blobSize, BYTE *blob)
1033
struct tsp_object *obj;
1034
struct tr_migdata_obj *migdata;
1035
TSS_RESULT result = TSS_SUCCESS;
1037
if ((obj = obj_list_get_obj(&migdata_list, hMigData)) == NULL)
1038
return TSPERR(TSS_E_INVALID_HANDLE);
1040
migdata = (struct tr_migdata_obj *)obj->data;
1042
migdata->blobSize = 0;
1043
free(migdata->blob);
1044
if ((migdata->blob = malloc(blobSize)) == NULL) {
1045
LogError("malloc of %u bytes failed.", blobSize);
1046
result = TSPERR(TSS_E_OUTOFMEMORY);
1049
memcpy(migdata->blob, blob, blobSize);
1050
migdata->blobSize = blobSize;
1053
obj_list_put(&migdata_list);
1059
obj_migdata_get_blob(TSS_HMIGDATA hMigData, UINT32 *blobSize, BYTE **blob)
1061
struct tsp_object *obj;
1062
struct tr_migdata_obj *migdata;
1063
TSS_RESULT result = TSS_SUCCESS;
1065
if ((obj = obj_list_get_obj(&migdata_list, hMigData)) == NULL)
1066
return TSPERR(TSS_E_INVALID_HANDLE);
1068
migdata = (struct tr_migdata_obj *)obj->data;
1070
if ((*blob = calloc_tspi(obj->tspContext, migdata->blobSize)) == NULL) {
1071
LogError("malloc of %u bytes failed.", migdata->blobSize);
1072
result = TSPERR(TSS_E_OUTOFMEMORY);
1075
memcpy(*blob, migdata->blob, migdata->blobSize);
1076
*blobSize = migdata->blobSize;
1079
obj_list_put(&migdata_list);
1086
obj_migdata_calc_pubkey_digest(UINT32 blobSize, BYTE *blob, TPM_DIGEST *digest)
1088
Trspi_HashCtx hashCtx;
1091
result = Trspi_HashInit(&hashCtx, TSS_HASH_SHA1);
1092
result |= Trspi_HashUpdate(&hashCtx, blobSize, blob);
1093
result |= Trspi_HashFinal(&hashCtx, digest->digest);
1099
obj_migdata_calc_msa_digest(struct tr_migdata_obj *migdata)
1101
Trspi_HashCtx hashCtx;
1104
result = Trspi_HashInit(&hashCtx, TSS_HASH_SHA1);
1105
result |= Trspi_Hash_MSA_COMPOSITE(&hashCtx, &migdata->msaList);
1106
result |= Trspi_HashFinal(&hashCtx, migdata->msaDigest.digest);
1112
obj_migdata_calc_sig_data_digest(struct tr_migdata_obj *migdata)
1114
Trspi_HashCtx hashCtx;
1117
result = Trspi_HashInit(&hashCtx, TSS_HASH_SHA1);
1118
result |= Trspi_Hash_DIGEST(&hashCtx, migdata->maDigest.digest);
1119
result |= Trspi_Hash_DIGEST(&hashCtx, migdata->destDigest.digest);
1120
result |= Trspi_Hash_DIGEST(&hashCtx, migdata->srcDigest.digest);
1121
result |= Trspi_HashFinal(&hashCtx, migdata->sigData.digest);