3
* Licensed Materials - Property of IBM
5
* trousers - An open source TCG Software Stack
7
* (C) Copyright International Business Machines Corp. 2004-2006
16
#include "trousers/tss.h"
17
#include "trousers/trousers.h"
18
#include "spi_internal_types.h"
19
#include "spi_utils.h"
20
#include "capabilities.h"
25
Tspi_Hash_Sign(TSS_HHASH hHash, /* in */
26
TSS_HKEY hKey, /* in */
27
UINT32 * pulSignatureLength, /* out */
28
BYTE ** prgbSignature) /* out */
31
TPM_AUTH *pPrivAuth = &privAuth;
37
TCS_KEY_HANDLE tcsKeyHandle;
39
TSS_HCONTEXT tspContext;
43
if (pulSignatureLength == NULL || prgbSignature == NULL)
44
return TSPERR(TSS_E_BAD_PARAMETER);
46
if ((result = obj_hash_get_tsp_context(hHash, &tspContext)))
49
if ((result = obj_rsakey_get_policy(hKey, TSS_POLICY_USAGE, &hPolicy, &usesAuth)))
52
if ((result = obj_hash_get_value(hHash, &ulDataLen, &data)))
55
if ((result = obj_rsakey_get_tcs_handle(hKey, &tcsKeyHandle)))
60
Trspi_LoadBlob_UINT32(&offset, TPM_ORD_Sign, hashblob);
61
Trspi_LoadBlob_UINT32(&offset, ulDataLen, hashblob);
62
Trspi_LoadBlob(&offset, ulDataLen, hashblob, data);
63
Trspi_Hash(TSS_HASH_SHA1, offset, hashblob, digest.digest);
64
pPrivAuth = &privAuth;
66
if ((result = secret_PerformAuth_OIAP(hKey, TPM_ORD_Sign,
74
if ((result = TCSP_Sign(tspContext, tcsKeyHandle,
76
pPrivAuth, pulSignatureLength, prgbSignature)))
81
Trspi_LoadBlob_UINT32(&offset, result, hashblob);
82
Trspi_LoadBlob_UINT32(&offset, TPM_ORD_Sign, hashblob);
83
Trspi_LoadBlob_UINT32(&offset, *pulSignatureLength, hashblob);
84
Trspi_LoadBlob(&offset, *pulSignatureLength, hashblob, *prgbSignature);
85
Trspi_Hash(TSS_HASH_SHA1, offset, hashblob, digest.digest);
87
if ((result = obj_policy_validate_auth_oiap(hPolicy, &digest, &privAuth))) {
88
free_tspi(tspContext, *prgbSignature);
94
free_tspi(tspContext, data);
99
Tspi_Hash_VerifySignature(TSS_HHASH hHash, /* in */
100
TSS_HKEY hKey, /* in */
101
UINT32 ulSignatureLength, /* in */
102
BYTE * rgbSignature) /* in */
107
BYTE *hashData = NULL;
110
TSS_HCONTEXT tspContext;
112
if (ulSignatureLength > 0 && rgbSignature == NULL)
113
return TSPERR(TSS_E_BAD_PARAMETER);
115
if ((result = obj_rsakey_get_tsp_context(hKey, &tspContext)))
118
if ((result = obj_rsakey_get_modulus(hKey, &pubKeySize, &pubKey)))
121
if ((result = obj_rsakey_get_ss(hKey, &sigScheme))) {
122
free_tspi(tspContext, pubKey);
126
if ((result = obj_hash_get_value(hHash, &hashDataSize, &hashData))) {
127
free_tspi(tspContext, pubKey);
131
if (sigScheme == TSS_SS_RSASSAPKCS1V15_SHA1) {
132
result = Trspi_Verify(TSS_HASH_SHA1, hashData, hashDataSize, pubKey, pubKeySize,
133
rgbSignature, ulSignatureLength);
134
} else if (sigScheme == TSS_SS_RSASSAPKCS1V15_DER) {
135
result = Trspi_Verify(TSS_HASH_OTHER, hashData, hashDataSize, pubKey, pubKeySize,
136
rgbSignature, ulSignatureLength);
138
result = TSPERR(TSS_E_INVALID_SIGSCHEME);
141
free_tspi(tspContext, pubKey);
142
free_tspi(tspContext, hashData);
148
Tspi_Hash_SetHashValue(TSS_HHASH hHash, /* in */
149
UINT32 ulHashValueLength, /* in */
150
BYTE * rgbHashValue) /* in */
152
if (ulHashValueLength == 0 || rgbHashValue == NULL)
153
return TSPERR(TSS_E_BAD_PARAMETER);
155
return obj_hash_set_value(hHash, ulHashValueLength, rgbHashValue);
159
Tspi_Hash_GetHashValue(TSS_HHASH hHash, /* in */
160
UINT32 * pulHashValueLength, /* out */
161
BYTE ** prgbHashValue) /* out */
163
if (pulHashValueLength == NULL || prgbHashValue == NULL)
164
return TSPERR(TSS_E_BAD_PARAMETER);
166
return obj_hash_get_value(hHash, pulHashValueLength, prgbHashValue);
170
Tspi_Hash_UpdateHashValue(TSS_HHASH hHash, /* in */
171
UINT32 ulDataLength, /* in */
172
BYTE *rgbData) /* in */
174
if (rgbData == NULL && ulDataLength != 0)
175
return TSPERR(TSS_E_BAD_PARAMETER);
177
if (ulDataLength == 0)
180
return obj_hash_update_value(hHash, ulDataLength, rgbData);