xref: /netbsd-src/crypto/external/cpl/trousers/dist/src/tspi/tspi_oper.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 
16 #include "trousers/tss.h"
17 #include "trousers/trousers.h"
18 #include "trousers_types.h"
19 #include "spi_utils.h"
20 #include "obj.h"
21 #include "tsplog.h"
22 
23 
24 TSS_RESULT
Tspi_TPM_SetOperatorAuth(TSS_HTPM hTpm,TSS_HPOLICY hOperatorPolicy)25 Tspi_TPM_SetOperatorAuth(TSS_HTPM    hTpm,		/* in */
26 			 TSS_HPOLICY hOperatorPolicy)	/* in */
27 {
28 	TSS_HCONTEXT tspContext;
29 	UINT32 type;
30 	TCPA_SECRET operatorAuth;
31 	TSS_RESULT result = TSS_SUCCESS;
32 
33 	if ((result = obj_tpm_get_tsp_context(hTpm, &tspContext)))
34 		return result;
35 
36 	if ((result = obj_policy_get_type(hOperatorPolicy, &type)))
37 		return result;
38 
39 	if (type != TSS_POLICY_OPERATOR)
40 		return TSPERR(TSS_E_BAD_PARAMETER);
41 
42 	if ((result = obj_policy_get_secret(hOperatorPolicy, TR_SECRET_CTX_NEW, &operatorAuth)))
43 		return result;
44 
45 	if ((result = TCS_API(tspContext)->SetOperatorAuth(tspContext, &operatorAuth)))
46 		return result;
47 
48 	if ((result = obj_tpm_set_policy(hTpm, hOperatorPolicy)))
49 		return result;
50 
51 	return result;
52 }
53