xref: /netbsd-src/crypto/external/cpl/trousers/dist/src/tcs/tcsi_quote2.c (revision 2d5f7628c5531eb583b9313ac2fd1cf8582b4479)
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. 2007
8  *
9  */
10 
11 
12 #include <stdlib.h>
13 #include <stdio.h>
14 #include <string.h>
15 #include <inttypes.h>
16 
17 #include "trousers/tss.h"
18 #include "trousers_types.h"
19 #include "tcs_tsp.h"
20 #include "tcsps.h"
21 #include "tcs_utils.h"
22 #include "tcs_int_literals.h"
23 #include "capabilities.h"
24 #include "tcslog.h"
25 #include "req_mgr.h"
26 #include "tcsd_wrap.h"
27 #include "tcsd.h"
28 
29 
30 TSS_RESULT
TCSP_Quote2_Internal(TCS_CONTEXT_HANDLE hContext,TCS_KEY_HANDLE keyHandle,TCPA_NONCE antiReplay,UINT32 pcrDataSizeIn,BYTE * pcrDataIn,TSS_BOOL addVersion,TPM_AUTH * privAuth,UINT32 * pcrDataSizeOut,BYTE ** pcrDataOut,UINT32 * versionInfoSize,BYTE ** versionInfo,UINT32 * sigSize,BYTE ** sig)31 TCSP_Quote2_Internal(TCS_CONTEXT_HANDLE hContext,	/* in */
32 		    TCS_KEY_HANDLE keyHandle,	/* in */
33 		    TCPA_NONCE antiReplay,	/* in */
34 		    UINT32 pcrDataSizeIn,	/* in */
35 		    BYTE * pcrDataIn,	/* in */
36 		    TSS_BOOL addVersion, /* in */
37 		    TPM_AUTH * privAuth,	/* in, out */
38 		    UINT32 * pcrDataSizeOut,	/* out */
39 		    BYTE ** pcrDataOut,	/* out */
40 		    UINT32 * versionInfoSize, /* out */
41 		    BYTE ** versionInfo, /* out */
42 		    UINT32 * sigSize,	/* out */
43 		    BYTE ** sig)	/* out */
44 {
45 	UINT64 offset = 0;
46 	UINT32 paramSize;
47 	TSS_RESULT result;
48 	UINT32 keySlot;
49 
50 	/* Command packet to be sent to the TPM */
51 	BYTE txBlob[TSS_TPM_TXBLOB_SIZE];
52 
53 	LogDebug("Entering quote2");
54 
55 	if ((result = ctx_verify_context(hContext)))
56 		goto done;
57 
58 	if (privAuth != NULL) {
59 		LogDebug("Auth Used");
60 		if ((result = auth_mgr_check(hContext, &privAuth->AuthHandle)))
61 			goto done;
62 	} else {
63 		LogDebug("No Auth");
64 	}
65 	if ((result = ensureKeyIsLoaded(hContext, keyHandle, &keySlot)))
66 		goto done;
67 
68 	if ((result = tpm_rqu_build(TPM_ORD_Quote2, &offset, txBlob, keySlot, antiReplay.nonce,
69 				    pcrDataSizeIn, pcrDataIn, &addVersion, privAuth)))
70 		goto done;
71 
72 	if ((result = req_mgr_submit_req(txBlob)))
73 		goto done;
74 
75 	result = UnloadBlob_Header(txBlob, &paramSize);
76 	if (!result) {
77 		result = tpm_rsp_parse(TPM_ORD_Quote2, txBlob, paramSize, pcrDataSizeOut,
78 				       pcrDataOut, &addVersion, versionInfoSize, versionInfo,
79 				       sigSize, sig, privAuth);
80 	}
81 	LogResult("Quote2", result);
82 done:
83 	auth_mgr_release_auth(privAuth, NULL, hContext);
84 	return result;
85 }
86 
87