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. 2006
8  *
9  */
10 
11 #include "daa_parameter.h"
12 
13 setenv("TCSD_FOREGROUND", "1", 1);
14 
15 static EVP_MD *digest = NULL;
16 
DAA_PARAM_get_message_digest(void)17 extern EVP_MD *DAA_PARAM_get_message_digest(void) {
18 	if( digest == NULL) {
19 		OpenSSL_add_all_digests();
20 		digest = EVP_get_digestbyname( DAA_PARAM_MESSAGE_DIGEST_ALGORITHM);
21 	}
22 	return digest;
23 }
24 
25 // from common.c (ltp-tss)
err_string(TSS_RESULT r)26 char *err_string(TSS_RESULT r)
27 {
28 	/* Check the return code to see if it is common to all layers.
29 	 * If so, return it.
30 	 */
31 	switch (TSS_ERROR_CODE(r)) {
32 		case TSS_SUCCESS:	return "TSS_SUCCESS";
33 		default:
34 			break;
35 	}
36 
37 	/* The return code is either unknown, or specific to a layer */
38 	if (TSS_ERROR_LAYER(r) == TSS_LAYER_TPM) {
39 		switch (TSS_ERROR_CODE(r)) {
40 			case TCPA_E_AUTHFAIL:		return "TCPA_E_AUTHFAIL";
41 			case TCPA_E_BADINDEX:		return "TCPA_E_BADINDEX";
42 			case TCPA_E_AUDITFAILURE:	return "TCPA_E_AUDITFAILURE";
43 			case TCPA_E_CLEAR_DISABLED:	return "TCPA_E_CLEAR_DISABLED";
44 			case TCPA_E_DEACTIVATED:	return "TCPA_E_DEACTIVATED";
45 			case TCPA_E_DISABLED:		return "TCPA_E_DISABLED";
46 			case TCPA_E_DISABLED_CMD:	return "TCPA_E_DISABLED_CMD";
47 			case TCPA_E_FAIL:		return "TCPA_E_FAIL";
48 			case TCPA_E_INACTIVE:		return "TCPA_E_INACTIVE";
49 			case TCPA_E_INSTALL_DISABLED:	return "TCPA_E_INSTALL_DISABLED";
50 			case TCPA_E_INVALID_KEYHANDLE:	return "TCPA_E_INVALID_KEYHANDLE";
51 			case TCPA_E_KEYNOTFOUND:	return "TCPA_E_KEYNOTFOUND";
52 			case TCPA_E_NEED_SELFTEST:	return "TCPA_E_NEED_SELFTEST";
53 			case TCPA_E_MIGRATEFAIL:	return "TCPA_E_MIGRATEFAIL";
54 			case TCPA_E_NO_PCR_INFO:	return "TCPA_E_NO_PCR_INFO";
55 			case TCPA_E_NOSPACE:		return "TCPA_E_NOSPACE";
56 			case TCPA_E_NOSRK:		return "TCPA_E_NOSRK";
57 			case TCPA_E_NOTSEALED_BLOB:	return "TCPA_E_NOTSEALED_BLOB";
58 			case TCPA_E_OWNER_SET:		return "TCPA_E_OWNER_SET";
59 			case TCPA_E_RESOURCES:		return "TCPA_E_RESOURCES";
60 			case TCPA_E_SHORTRANDOM:	return "TCPA_E_SHORTRANDOM";
61 			case TCPA_E_SIZE:		return "TCPA_E_SIZE";
62 			case TCPA_E_WRONGPCRVAL:	return "TCPA_E_WRONGPCRVAL";
63 			case TCPA_E_BAD_PARAM_SIZE:	return "TCPA_E_BAD_PARAM_SIZE";
64 			case TCPA_E_SHA_THREAD:		return "TCPA_E_SHA_THREAD";
65 			case TCPA_E_SHA_ERROR:		return "TCPA_E_SHA_ERROR";
66 			case TCPA_E_FAILEDSELFTEST:	return "TCPA_E_FAILEDSELFTEST";
67 			case TCPA_E_AUTH2FAIL:		return "TCPA_E_AUTH2FAIL";
68 			case TCPA_E_BADTAG:		return "TCPA_E_BADTAG";
69 			case TCPA_E_IOERROR:		return "TCPA_E_IOERROR";
70 			case TCPA_E_ENCRYPT_ERROR:	return "TCPA_E_ENCRYPT_ERROR";
71 			case TCPA_E_DECRYPT_ERROR:	return "TCPA_E_DECRYPT_ERROR";
72 			case TCPA_E_INVALID_AUTHHANDLE:	return "TCPA_E_INVALID_AUTHHANDLE";
73 			case TCPA_E_NO_ENDORSEMENT:	return "TCPA_E_NO_ENDORSEMENT";
74 			case TCPA_E_INVALID_KEYUSAGE:	return "TCPA_E_INVALID_KEYUSAGE";
75 			case TCPA_E_WRONG_ENTITYTYPE:	return "TCPA_E_WRONG_ENTITYTYPE";
76 			case TCPA_E_INVALID_POSTINIT:	return "TCPA_E_INVALID_POSTINIT";
77 			case TCPA_E_INAPPROPRIATE_SIG:	return "TCPA_E_INAPPROPRIATE_SIG";
78 			case TCPA_E_BAD_KEY_PROPERTY:	return "TCPA_E_BAD_KEY_PROPERTY";
79 			case TCPA_E_BAD_MIGRATION:	return "TCPA_E_BAD_MIGRATION";
80 			case TCPA_E_BAD_SCHEME:		return "TCPA_E_BAD_SCHEME";
81 			case TCPA_E_BAD_DATASIZE:	return "TCPA_E_BAD_DATASIZE";
82 			case TCPA_E_BAD_MODE:		return "TCPA_E_BAD_MODE";
83 			case TCPA_E_BAD_PRESENCE:	return "TCPA_E_BAD_PRESENCE";
84 			case TCPA_E_BAD_VERSION:	return "TCPA_E_BAD_VERSION";
85 			case TCPA_E_RETRY:		return "TCPA_E_RETRY";
86 			default:			return "UNKNOWN TPM ERROR";
87 		}
88 	} else if (TSS_ERROR_LAYER(r) == TSS_LAYER_TDDL) {
89 		switch (TSS_ERROR_CODE(r)) {
90 			case TSS_E_FAIL:			return "TSS_E_FAIL";
91 			case TSS_E_BAD_PARAMETER:		return "TSS_E_BAD_PARAMETER";
92 			case TSS_E_INTERNAL_ERROR:		return "TSS_E_INTERNAL_ERROR";
93 			case TSS_E_NOTIMPL:			return "TSS_E_NOTIMPL";
94 			case TSS_E_PS_KEY_NOTFOUND:		return "TSS_E_PS_KEY_NOTFOUND";
95 			case TSS_E_KEY_ALREADY_REGISTERED:	return "TSS_E_KEY_ALREADY_REGISTERED";
96 			case TSS_E_CANCELED:			return "TSS_E_CANCELED";
97 			case TSS_E_TIMEOUT:			return "TSS_E_TIMEOUT";
98 			case TSS_E_OUTOFMEMORY:			return "TSS_E_OUTOFMEMORY";
99 			case TSS_E_TPM_UNEXPECTED:		return "TSS_E_TPM_UNEXPECTED";
100 			case TSS_E_COMM_FAILURE:		return "TSS_E_COMM_FAILURE";
101 			case TSS_E_TPM_UNSUPPORTED_FEATURE:	return "TSS_E_TPM_UNSUPPORTED_FEATURE";
102 			case TDDL_E_COMPONENT_NOT_FOUND:	return "TDDL_E_COMPONENT_NOT_FOUND";
103 			case TDDL_E_ALREADY_OPENED:		return "TDDL_E_ALREADY_OPENED";
104 			case TDDL_E_BADTAG:			return "TDDL_E_BADTAG";
105 			case TDDL_E_INSUFFICIENT_BUFFER:	return "TDDL_E_INSUFFICIENT_BUFFER";
106 			case TDDL_E_COMMAND_COMPLETED:		return "TDDL_E_COMMAND_COMPLETED";
107 			case TDDL_E_ALREADY_CLOSED:		return "TDDL_E_ALREADY_CLOSED";
108 			case TDDL_E_IOERROR:			return "TDDL_E_IOERROR";
109 			default:				return "UNKNOWN TDDL ERROR";
110 		}
111 	} else if (TSS_ERROR_LAYER(r) == TSS_LAYER_TCS) {
112 		switch (TSS_ERROR_CODE(r)) {
113 			case TSS_E_FAIL:			return "TSS_E_FAIL";
114 			case TSS_E_BAD_PARAMETER:		return "TSS_E_BAD_PARAMETER";
115 			case TSS_E_INTERNAL_ERROR:		return "TSS_E_INTERNAL_ERROR";
116 			case TSS_E_NOTIMPL:			return "TSS_E_NOTIMPL";
117 			case TSS_E_PS_KEY_NOTFOUND:		return "TSS_E_PS_KEY_NOTFOUND";
118 			case TSS_E_KEY_ALREADY_REGISTERED:	return "TSS_E_KEY_ALREADY_REGISTERED";
119 			case TSS_E_CANCELED:			return "TSS_E_CANCELED";
120 			case TSS_E_TIMEOUT:			return "TSS_E_TIMEOUT";
121 			case TSS_E_OUTOFMEMORY:			return "TSS_E_OUTOFMEMORY";
122 			case TSS_E_TPM_UNEXPECTED:		return "TSS_E_TPM_UNEXPECTED";
123 			case TSS_E_COMM_FAILURE:		return "TSS_E_COMM_FAILURE";
124 			case TSS_E_TPM_UNSUPPORTED_FEATURE:	return "TSS_E_TPM_UNSUPPORTED_FEATURE";
125 			case TCS_E_KEY_MISMATCH:		return "TCS_E_KEY_MISMATCH";
126 			case TCS_E_KM_LOADFAILED:		return "TCS_E_KM_LOADFAILED";
127 			case TCS_E_KEY_CONTEXT_RELOAD:		return "TCS_E_KEY_CONTEXT_RELOAD";
128 			case TCS_E_INVALID_CONTEXTHANDLE:	return "TCS_E_INVALID_CONTEXTHANDLE";
129 			case TCS_E_INVALID_KEYHANDLE:		return "TCS_E_INVALID_KEYHANDLE";
130 			case TCS_E_INVALID_AUTHHANDLE:		return "TCS_E_INVALID_AUTHHANDLE";
131 			case TCS_E_INVALID_AUTHSESSION:		return "TCS_E_INVALID_AUTHSESSION";
132 			case TCS_E_INVALID_KEY:			return "TCS_E_INVALID_KEY";
133 			default:				return "UNKNOWN TCS ERROR";
134 		}
135 	} else {
136 		switch (TSS_ERROR_CODE(r)) {
137 			case TSS_E_FAIL:			return "TSS_E_FAIL";
138 			case TSS_E_BAD_PARAMETER:		return "TSS_E_BAD_PARAMETER";
139 			case TSS_E_INTERNAL_ERROR:		return "TSS_E_INTERNAL_ERROR";
140 			case TSS_E_NOTIMPL:			return "TSS_E_NOTIMPL";
141 			case TSS_E_PS_KEY_NOTFOUND:		return "TSS_E_PS_KEY_NOTFOUND";
142 			case TSS_E_KEY_ALREADY_REGISTERED:	return "TSS_E_KEY_ALREADY_REGISTERED";
143 			case TSS_E_CANCELED:			return "TSS_E_CANCELED";
144 			case TSS_E_TIMEOUT:			return "TSS_E_TIMEOUT";
145 			case TSS_E_OUTOFMEMORY:			return "TSS_E_OUTOFMEMORY";
146 			case TSS_E_TPM_UNEXPECTED:		return "TSS_E_TPM_UNEXPECTED";
147 			case TSS_E_COMM_FAILURE:		return "TSS_E_COMM_FAILURE";
148 			case TSS_E_TPM_UNSUPPORTED_FEATURE:	return "TSS_E_TPM_UNSUPPORTED_FEATURE";
149 			case TSS_E_INVALID_OBJECT_TYPE:		return "TSS_E_INVALID_OBJECT_TYPE";
150 			case TSS_E_INVALID_OBJECT_INITFLAG:	return "TSS_E_INVALID_OBJECT_INITFLAG";
151 			case TSS_E_INVALID_HANDLE:		return "TSS_E_INVALID_HANDLE";
152 			case TSS_E_NO_CONNECTION:		return "TSS_E_NO_CONNECTION";
153 			case TSS_E_CONNECTION_FAILED:		return "TSS_E_CONNECTION_FAILED";
154 			case TSS_E_CONNECTION_BROKEN:		return "TSS_E_CONNECTION_BROKEN";
155 			case TSS_E_HASH_INVALID_ALG:		return "TSS_E_HASH_INVALID_ALG";
156 			case TSS_E_HASH_INVALID_LENGTH:		return "TSS_E_HASH_INVALID_LENGTH";
157 			case TSS_E_HASH_NO_DATA:		return "TSS_E_HASH_NO_DATA";
158 			case TSS_E_SILENT_CONTEXT:		return "TSS_E_SILENT_CONTEXT";
159 			case TSS_E_INVALID_ATTRIB_FLAG:		return "TSS_E_INVALID_ATTRIB_FLAG";
160 			case TSS_E_INVALID_ATTRIB_SUBFLAG:	return "TSS_E_INVALID_ATTRIB_SUBFLAG";
161 			case TSS_E_INVALID_ATTRIB_DATA:		return "TSS_E_INVALID_ATTRIB_DATA";
162 			case TSS_E_NO_PCRS_SET:			return "TSS_E_NO_PCRS_SET";
163 			case TSS_E_KEY_NOT_LOADED:		return "TSS_E_KEY_NOT_LOADED";
164 			case TSS_E_KEY_NOT_SET:			return "TSS_E_KEY_NOT_SET";
165 			case TSS_E_VALIDATION_FAILED:		return "TSS_E_VALIDATION_FAILED";
166 			case TSS_E_TSP_AUTHREQUIRED:		return "TSS_E_TSP_AUTHREQUIRED";
167 			case TSS_E_TSP_AUTH2REQUIRED:		return "TSS_E_TSP_AUTH2REQUIRED";
168 			case TSS_E_TSP_AUTHFAIL:		return "TSS_E_TSP_AUTHFAIL";
169 			case TSS_E_TSP_AUTH2FAIL:		return "TSS_E_TSP_AUTH2FAIL";
170 			case TSS_E_KEY_NO_MIGRATION_POLICY:	return "TSS_E_KEY_NO_MIGRATION_POLICY";
171 			case TSS_E_POLICY_NO_SECRET:		return "TSS_E_POLICY_NO_SECRET";
172 			case TSS_E_INVALID_OBJ_ACCESS:		return "TSS_E_INVALID_OBJ_ACCESS";
173 			case TSS_E_INVALID_ENCSCHEME:		return "TSS_E_INVALID_ENCSCHEME";
174 			case TSS_E_INVALID_SIGSCHEME:		return "TSS_E_INVALID_SIGSCHEME";
175 			case TSS_E_ENC_INVALID_LENGTH:		return "TSS_E_ENC_INVALID_LENGTH";
176 			case TSS_E_ENC_NO_DATA:			return "TSS_E_ENC_NO_DATA";
177 			case TSS_E_ENC_INVALID_TYPE:		return "TSS_E_ENC_INVALID_TYPE";
178 			case TSS_E_INVALID_KEYUSAGE:		return "TSS_E_INVALID_KEYUSAGE";
179 			case TSS_E_VERIFICATION_FAILED:		return "TSS_E_VERIFICATION_FAILED";
180 			case TSS_E_HASH_NO_IDENTIFIER:		return "TSS_E_HASH_NO_IDENTIFIER";
181 			default:	return "UNKNOWN TSS ERROR";
182 		}
183 	}
184 }
185