3
* Licensed Materials - Property of IBM
5
* trousers - An open source TCG Software Stack
7
* (C) Copyright International Business Machines Corp. 2004-2007
16
#include "trousers/tss.h"
17
#include "trousers/trousers.h"
18
#include "trousers_types.h"
19
#include "spi_utils.h"
20
#include "capabilities.h"
25
/* encrypt some data with the RSA public key of 'key', using the padding appropriate for the key */
27
rsa_encrypt(TSS_HKEY key,
37
TSS_HCONTEXT tspContext;
40
if (!inData || !outDataLen || !outData)
41
return TSPERR(TSS_E_INTERNAL_ERROR);
43
if ((result = obj_rsakey_get_tsp_context(key, &tspContext)))
46
if ((result = obj_rsakey_get_pub_blob(key, &blobLen, &blob)))
50
if ((result = Trspi_UnloadBlob_PUBKEY(&offset, blob, &pubKey))) {
51
free_tspi(tspContext, blob);
54
free_tspi(tspContext, blob);
56
if (pubKey.pubKey.keyLength < inDataLen) {
57
result = TSPERR(TSS_E_ENC_INVALID_LENGTH);
61
if (pubKey.algorithmParms.encScheme == TPM_ES_RSAESPKCSv15 ||
62
pubKey.algorithmParms.encScheme == TSS_ES_RSAESPKCSV15) {
63
if ((result = Trspi_RSA_PKCS15_Encrypt(inData, inDataLen, outData, outDataLen,
64
pubKey.pubKey.key, pubKey.pubKey.keyLength)))
67
if ((result = Trspi_TPM_RSA_OAEP_Encrypt(inData, inDataLen, outData, outDataLen,
69
pubKey.pubKey.keyLength)))
74
free(pubKey.pubKey.key);
75
free(pubKey.algorithmParms.parms);
80
rsa_verify(TSS_HKEY key,
91
TSS_HCONTEXT tspContext;
95
return TSPERR(TSS_E_INTERNAL_ERROR);
97
if ((result = obj_rsakey_get_tsp_context(key, &tspContext)))
100
if ((result = obj_rsakey_get_pub_blob(key, &blobLen, &blob)))
104
if ((result = Trspi_UnloadBlob_PUBKEY(&offset, blob, &pubKey))) {
105
free_tspi(tspContext, blob);
108
free_tspi(tspContext, blob);
110
result = Trspi_Verify(type, hash, hashLen, pubKey.pubKey.key, pubKey.pubKey.keyLength,
113
free(pubKey.pubKey.key);
114
free(pubKey.algorithmParms.parms);