Home | History | Annotate | Line # | Download | only in tcs
      1 
      2 /*
      3  * Licensed Materials - Property of IBM
      4  *
      5  * trousers - An open source TCG Software Stack
      6  *
      7  * (C) Copyright International Business Machines Corp. 2004-2006
      8  *
      9  */
     10 
     11 
     12 #include <stdlib.h>
     13 #include <stdio.h>
     14 #include <string.h>
     15 #include <unistd.h>
     16 #include <sys/types.h>
     17 #include <sys/stat.h>
     18 #include <sys/mman.h>
     19 #include <fcntl.h>
     20 #include <errno.h>
     21 
     22 #include "trousers/tss.h"
     23 #include "trousers_types.h"
     24 #include "trousers_types.h"
     25 #include "tcs_tsp.h"
     26 #include "tcs_utils.h"
     27 #include "tcs_int_literals.h"
     28 #include "capabilities.h"
     29 #include "tcsps.h"
     30 #include "tcslog.h"
     31 #include "tddl.h"
     32 #include "req_mgr.h"
     33 #include "tcsd_wrap.h"
     34 #include "tcsd.h"
     35 
     36 
     37 TSS_RESULT
     38 UnloadBlob_PCR_SELECTION(UINT64 *offset, BYTE *blob, TCPA_PCR_SELECTION *pcr)
     39 {
     40 	if (!pcr) {
     41 		UINT16 size;
     42 
     43 		UnloadBlob_UINT16(offset, &size, blob);
     44 
     45 		if (size > 0)
     46 			UnloadBlob(offset, size, blob, NULL);
     47 
     48 		return TSS_SUCCESS;
     49 	}
     50 
     51 	UnloadBlob_UINT16(offset, &pcr->sizeOfSelect, blob);
     52 	pcr->pcrSelect = malloc(pcr->sizeOfSelect);
     53         if (pcr->pcrSelect == NULL) {
     54 		LogError("malloc of %hu bytes failed.", pcr->sizeOfSelect);
     55 		pcr->sizeOfSelect = 0;
     56                 return TCSERR(TSS_E_OUTOFMEMORY);
     57         }
     58 	UnloadBlob(offset, pcr->sizeOfSelect, blob, pcr->pcrSelect);
     59 
     60 	return TSS_SUCCESS;
     61 }
     62 
     63 void
     64 LoadBlob_PCR_SELECTION(UINT64 *offset, BYTE * blob, TCPA_PCR_SELECTION pcr)
     65 {
     66 	LoadBlob_UINT16(offset, pcr.sizeOfSelect, blob);
     67 	LoadBlob(offset, pcr.sizeOfSelect, blob, pcr.pcrSelect);
     68 }
     69 
     70 TSS_RESULT
     71 UnloadBlob_PCR_COMPOSITE(UINT64 *offset, BYTE *blob, TCPA_PCR_COMPOSITE *out)
     72 {
     73 	TSS_RESULT rc;
     74 
     75 	if (!out) {
     76 		UINT32 size;
     77 
     78 		if ((rc = UnloadBlob_PCR_SELECTION(offset, blob, NULL)))
     79 			return rc;
     80 
     81 		UnloadBlob_UINT32(offset, &size, blob);
     82 		if (size > 0)
     83 			UnloadBlob(offset, size, blob, NULL);
     84 
     85 		return TSS_SUCCESS;
     86 	}
     87 
     88 	if ((rc = UnloadBlob_PCR_SELECTION(offset, blob, &out->select)))
     89 		return rc;
     90 
     91 	UnloadBlob_UINT32(offset, &out->valueSize, blob);
     92 	out->pcrValue = malloc(out->valueSize);
     93         if (out->pcrValue == NULL) {
     94 		LogError("malloc of %u bytes failed.", out->valueSize);
     95 		out->valueSize = 0;
     96                 return TCSERR(TSS_E_OUTOFMEMORY);
     97         }
     98 	UnloadBlob(offset, out->valueSize, blob, (BYTE *) out->pcrValue);
     99 
    100 	return TSS_SUCCESS;
    101 }
    102