本文整理汇总了C++中Tspi_Context_FreeMemory函数的典型用法代码示例。如果您正苦于以下问题:C++ Tspi_Context_FreeMemory函数的具体用法?C++ Tspi_Context_FreeMemory怎么用?C++ Tspi_Context_FreeMemory使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Tspi_Context_FreeMemory函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: tpm_rand_bytes
static int tpm_rand_bytes(unsigned char *buf, int num)
{
TSS_RESULT result;
BYTE *rand_data;
UINT32 total_requested = 0;
DBG("%s getting %d bytes", __FUNCTION__, num);
if (num - total_requested > 4096) {
if ((result = Tspi_TPM_GetRandom(hTPM, 4096, &rand_data))) {
TSSerr(TPM_F_TPM_RAND_BYTES, TPM_R_REQUEST_FAILED);
return 0;
}
memcpy(&buf[total_requested], rand_data, 4096);
Tspi_Context_FreeMemory(hContext, rand_data);
total_requested += 4096;
}
if ((result = Tspi_TPM_GetRandom(hTPM, num - total_requested, &rand_data))) {
TSSerr(TPM_F_TPM_RAND_BYTES, TPM_R_REQUEST_FAILED);
return 0;
}
memcpy(buf + total_requested, rand_data, num - total_requested);
Tspi_Context_FreeMemory(hContext, rand_data);
return 1;
}
示例2: main_v1_2
int
main_v1_2(char version)
{
char *function = "Tspi_TPM_PcrRead-trans03";
BYTE *rgbPcrValue;
UINT32 ulPcrValueLength;
TSS_HCONTEXT hContext;
TSS_HTPM hTPM;
TSS_RESULT result;
TSS_HKEY hSRK, hWrappingKey;
print_begin_test( function );
result = connect_load_all(&hContext, &hSRK, &hTPM);
if ( result != TSS_SUCCESS )
{
print_error( "connect_load_all", result );
Tspi_Context_FreeMemory( hContext, NULL );
Tspi_Context_Close( hContext );
exit( result );
}
result = Testsuite_Transport_Init(hContext, hSRK, hTPM, FALSE, TRUE, &hWrappingKey,
NULL);
if (result != TSS_SUCCESS) {
print_error("Testsuite_Transport_Init", result);
Tspi_Context_Close(hContext);
exit(result);
}
result = Tspi_TPM_PcrRead( hTPM, 8, &ulPcrValueLength, &rgbPcrValue );
if (result != TSS_SUCCESS) {
print_error("Tspi_TPM_PcrRead", result);
Tspi_Context_Close(hContext);
exit(result);
}
result = Testsuite_Transport_Final(hContext, 0);
if ( result != TSS_SUCCESS )
{
if( !(checkNonAPI(result)) )
{
print_error( function, result );
}
else
{
print_error_nonapi( function, result );
}
}
else
{
print_success( function, result );
}
print_end_test( function );
Tspi_Context_FreeMemory( hContext, NULL );
Tspi_Context_Close( hContext );
exit( result );
}
示例3: main_v1_1
main_v1_1(void){
char *nameOfFunction = "Tspi_GetAttribData09";
TSS_HCONTEXT hContext;
TSS_RESULT result;
TSS_HKEY hSRK;
BYTE* BLOB;
UINT32 BlobLength;
print_begin_test(nameOfFunction);
//Create Context
result = Tspi_Context_Create(&hContext);
if (result != TSS_SUCCESS) {
print_error("Tspi_Context_Create ", result);
exit(result);
}
//Connect Context
result = Tspi_Context_Connect(hContext, get_server(GLOBALSERVER));
if (result != TSS_SUCCESS) {
print_error("Tspi_Context_Connect", result);
Tspi_Context_Close(hContext);
exit(result);
}
//Load Key by UUID for SRK
result = Tspi_Context_LoadKeyByUUID(hContext, TSS_PS_TYPE_SYSTEM,
SRK_UUID, &hSRK);
if (result != TSS_SUCCESS) {
print_error("Tspi_Context_LoadKeyByUUID", result);
Tspi_Context_Close(hContext);
exit(result);
}
//Call GetAttribData
result = Tspi_GetAttribData(hSRK, TSS_TSPATTRIB_KEY_BLOB, TSS_TSPATTRIB_KEYBLOB_PUBLIC_KEY,
&BlobLength, &BLOB);
if (TSS_ERROR_CODE(result) != TSS_E_BAD_PARAMETER) {
if(!checkNonAPI(result)){
print_error(nameOfFunction, result);
print_end_test(nameOfFunction);
Tspi_Context_FreeMemory(hContext, NULL);
Tspi_Context_Close(hContext);
exit(result);
}
else{
print_error_nonapi(nameOfFunction, result);
print_end_test(nameOfFunction);
Tspi_Context_FreeMemory(hContext, NULL);
Tspi_Context_Close(hContext);
exit(result);
}
}
else{
print_success(nameOfFunction, result);
print_end_test(nameOfFunction);
Tspi_Context_FreeMemory(hContext, NULL);
Tspi_Context_Close(hContext);
exit(0);
}
}
示例4: main_v1_1
int
main_v1_1( void )
{
char *function = "Tspi_TPM_StirRandom02";
BYTE entropy;
TSS_HCONTEXT hContext;
TSS_HTPM whTPM = -1;
TSS_RESULT result;
UINT32 exitCode = 0;
print_begin_test( function );
// seed entropy with time
srand( time(0) );
// Create Context
result = Tspi_Context_Create( &hContext );
if ( result != TSS_SUCCESS )
{
print_error( "Tspi_Context_Create", result );
exit( result );
}
// Connect to Context
result = Tspi_Context_Connect( hContext, get_server(GLOBALSERVER) );
if ( result != TSS_SUCCESS )
{
print_error( "Tspi_Context_Connect", result );
Tspi_Context_FreeMemory( hContext, NULL );
Tspi_Context_Close( hContext );
exit( result );
}
entropy = ( rand() % 100 );
//Get random number
result = Tspi_TPM_StirRandom( whTPM, 16, &entropy );
if ( TSS_ERROR_CODE(result) != TSS_E_INVALID_HANDLE )
{
if( !(checkNonAPI(result)) )
{
print_error( function, result );
}
else
{
print_error_nonapi( function, result );
}
exitCode = result;
}
else
{
print_success( function, result );
}
print_end_test( function );
Tspi_Context_FreeMemory( hContext, NULL );
Tspi_Context_Close( hContext );
exit( exitCode );
}
示例5: main_v1_2
int
main_v1_2(char version)
{
char *function = "Tspi_TPM_SetStatus-trans01";
TSS_HCONTEXT hContext;
TSS_HTPM hTPM;
TSS_RESULT result;
TSS_HKEY hSRK, hSigningKey, hWrappingKey;
print_begin_test( function );
result = connect_load_all(&hContext, &hSRK, &hTPM);
if ( result != TSS_SUCCESS )
{
print_error( "connect_load_all", (result) );
Tspi_Context_FreeMemory( hContext, NULL );
Tspi_Context_Close( hContext );
exit( result );
}
result = Testsuite_Transport_Init(hContext, hSRK, hTPM, TRUE, FALSE, &hWrappingKey,
&hSigningKey);
if (result != TSS_SUCCESS) {
print_error("Testsuite_Transport_Init", result);
Tspi_Context_Close(hContext);
exit(result);
}
//Get random number
result = Tspi_TPM_SetStatus( hTPM, TSS_TPMSTATUS_SETOWNERINSTALL, TRUE );
if (result != TSS_SUCCESS) {
print_error("Tspi_TPM_SetStatus", result);
Tspi_Context_Close(hContext);
exit(result);
}
result = Testsuite_Transport_Final(hContext, hSigningKey);
if ( result != TSS_SUCCESS )
{
if( !(checkNonAPI(result)) )
{
print_error( function, result );
}
else
{
print_error_nonapi( function, result );
}
}
else
{
print_success( function, result );
}
print_end_test( function );
Tspi_Context_FreeMemory( hContext, NULL );
Tspi_Context_Close( hContext );
exit( result );
}
示例6: main_v1_1
main_v1_1(void){
char *nameOfFunction = "Tspi_TPM_SelfTestFull02";
TSS_HCONTEXT hContext;
TSS_RESULT result;
TSS_HTPM hTPM;
print_begin_test(nameOfFunction);
//Create Result
result = Tspi_Context_Create(&hContext);
if (result != TSS_SUCCESS) {
print_error("Tspi_Context_Create ", result);
exit(result);
}
//Connect Result
result = Tspi_Context_Connect(hContext, get_server(GLOBALSERVER));
if (result != TSS_SUCCESS) {
print_error("Tspi_Context_Connect ", result);
Tspi_Context_Close(hContext);
exit(result);
}
//Get TPM Object
result = Tspi_Context_GetTpmObject(hContext, &hTPM);
if (result != TSS_SUCCESS) {
print_error("Tspi_Context_GetTpmObject ", result);
Tspi_Context_Close(hContext);
exit(result);
}
//Self Test
result = Tspi_TPM_SelfTestFull(-1);
if (TSS_ERROR_CODE(result) != TSS_E_INVALID_HANDLE) {
if(!checkNonAPI(result)){
print_error(nameOfFunction, result);
print_end_test(nameOfFunction);
Tspi_Context_FreeMemory(hContext, NULL);
Tspi_Context_Close(hContext);
exit(result);
}
else{
print_error_nonapi(nameOfFunction, result);
print_end_test(nameOfFunction);
Tspi_Context_FreeMemory(hContext, NULL);
Tspi_Context_Close(hContext);
exit(result);
}
}
else{
print_success(nameOfFunction, result);
print_end_test(nameOfFunction);
Tspi_Context_FreeMemory(hContext, NULL);
Tspi_Context_Close(hContext);
exit(0);
}
}
示例7: main_v1_1
int
main_v1_1(void){
char *nameOfFunction = "Tspi_Context_CreateObject02";
TSS_HCONTEXT hContext;
TSS_HKEY hSignatureKey;
TSS_RESULT result;
print_begin_test(nameOfFunction);
//Create Context
result = Tspi_Context_Create(&hContext);
if (result != TSS_SUCCESS) {
print_error("Tspi_Context_Create ", result);
exit(result);
}
//Connect Context
result = Tspi_Context_Connect(hContext, get_server(GLOBALSERVER));
if (result != TSS_SUCCESS) {
print_error("Tspi_Context_Connect ", result);
Tspi_Context_Close(hContext);
exit(result);
}
//Create Object
result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_HASH,
TSS_KEY_SIZE_2048 | TSS_KEY_TYPE_SIGNING |
TSS_KEY_MIGRATABLE, &hSignatureKey);
if (TSS_ERROR_CODE(result) != TSS_E_INVALID_OBJECT_INITFLAG){
if(!checkNonAPI(result)){
print_error(nameOfFunction, result);
print_end_test(nameOfFunction);
Tspi_Context_FreeMemory(hContext, NULL);
Tspi_Context_CloseObject(hContext, hSignatureKey);
Tspi_Context_Close(hContext);
exit(result);
}
else{
print_error_nonapi(nameOfFunction, result);
print_end_test(nameOfFunction);
Tspi_Context_FreeMemory(hContext, NULL);
Tspi_Context_CloseObject(hContext, hSignatureKey);
Tspi_Context_Close(hContext);
exit(result);
}
}
else{
print_success(nameOfFunction, result);
print_end_test(nameOfFunction);
Tspi_Context_FreeMemory(hContext, NULL);
Tspi_Context_CloseObject(hContext, hSignatureKey);
Tspi_Context_Close(hContext);
exit(0);
}
}
示例8: main_v1_2
main_v1_2(char version)
{
char *nameOfFunction = "Tspi_TPM_ReadCounter03";
TSS_HCONTEXT hContext;
TSS_HTPM hTPM;
TSS_RESULT result;
print_begin_test(nameOfFunction);
//Create Context
result = Tspi_Context_Create(&hContext);
if (result != TSS_SUCCESS) {
print_error("Tspi_Context_Create ", result);
exit(result);
}
//Connect Context
result = Tspi_Context_Connect(hContext, get_server(GLOBALSERVER));
if (result != TSS_SUCCESS) {
print_error("Tspi_Context_Connect", result);
exit(result);
}
//GetTPM Object
result = Tspi_Context_GetTpmObject(hContext, &hTPM);
if (result != TSS_SUCCESS) {
print_error("Tspi_Context_GetTPMObject", result);
exit(result);
}
// Read Counter
result = Tspi_TPM_ReadCounter(hTPM, NULL);
if (TSS_ERROR_CODE(result) != TSS_E_BAD_PARAMETER) {
if(!checkNonAPI(result)){
print_error(nameOfFunction, result);
print_end_test(nameOfFunction);
Tspi_Context_FreeMemory(hContext, NULL);
Tspi_Context_Close(hContext);
exit(result);
}
else{
print_error_nonapi(nameOfFunction, result);
print_end_test(nameOfFunction);
Tspi_Context_FreeMemory(hContext, NULL);
Tspi_Context_Close(hContext);
exit(result);
}
}
else{
print_success(nameOfFunction, result);
print_end_test(nameOfFunction);
Tspi_Context_FreeMemory(hContext, NULL);
Tspi_Context_Close(hContext);
exit(0);
}
}
示例9: main_v1_1
int main_v1_1(void)
{
char *function = "Tspi_Hash_GetHashValue04";
TSS_HCONTEXT hContext;
TSS_HHASH hHash;
UINT32 ulHashValueLength, exitCode = 0;
BYTE *rgbHashValue, hashBuf[20];
TSS_RESULT result;
print_begin_test(function);
// Create Context
result = Tspi_Context_Create(&hContext);
if (result != TSS_SUCCESS) {
print_error("Tspi_Context_Create", result);
exit(result);
}
// Connect to Context
result = Tspi_Context_Connect(hContext, get_server(GLOBALSERVER));
if (result != TSS_SUCCESS) {
print_error("Tspi_Context_Connect", result);
Tspi_Context_FreeMemory(hContext, NULL);
Tspi_Context_Close(hContext);
exit(result);
}
result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_HASH,
TSS_HASH_SHA1, &hHash);
if (result != TSS_SUCCESS) {
print_error("Tspi_Context_CreateObject (hash)", result);
Tspi_Context_FreeMemory(hContext, NULL);
Tspi_Context_Close(hContext);
exit(result);
}
result = Tspi_Hash_GetHashValue(hHash, &ulHashValueLength,
&rgbHashValue);
if (TSS_ERROR_CODE(result) != TSS_E_HASH_NO_DATA) {
if (!(checkNonAPI(result))) {
print_error(function, result);
} else {
print_error_nonapi(function, result);
}
exitCode = result;
} else {
print_success(function, result);
}
print_end_test(function);
Tspi_Context_FreeMemory(hContext, NULL);
Tspi_Context_Close(hContext);
exit(exitCode);
}
示例10: main_v1_1
int main_v1_1(void)
{
TSS_RESULT result;
TSS_HCONTEXT hContext;
TSS_HTPM hTPM;
BYTE pcrValue[] = "01234567890123456789";
UINT32 ulPcrValLen = 20;
BYTE *newPcrValue;
UINT32 ulnewPcrValLen;
// Create Context
result = Tspi_Context_Create(&hContext);
if (TSS_SUCCESS != result) {
print_error("Tspi_Context_Create", result);
exit(result);
}
// Connect Context
result = Tspi_Context_Connect(hContext, get_server(GLOBALSERVER));
if (TSS_SUCCESS != result) {
print_error("Tspi_Context_Connect", result);
Tspi_Context_FreeMemory(hContext, NULL);
Tspi_Context_Close(hContext);
exit(result);
}
// Get TPM Object
result = Tspi_Context_GetTpmObject(hContext, &hTPM);
if (TSS_SUCCESS != result) {
print_error("Tspi_Context_GetTpmObject", result);
Tspi_Context_FreeMemory(hContext, NULL);
Tspi_Context_Close(hContext);
exit(result);
}
printf("ulPcrValLen:%d\n", ulPcrValLen);
// Call PcrExtend
result = Tspi_TPM_PcrExtend(hTPM, 15, ulPcrValLen, pcrValue,
NULL, &ulnewPcrValLen, &newPcrValue);
if (TSS_SUCCESS != result) {
print_error("Tspi_TPM_PcrExtend", result);
Tspi_Context_FreeMemory(hContext, NULL);
Tspi_Context_Close(hContext);
exit(result);
}
printf("\nSuccess\n");
Tspi_Context_FreeMemory(hContext, NULL);
Tspi_Context_Close(hContext);
return 0;
}
示例11: get_tpm_capability
int
get_tpm_capability(TSS_HCONTEXT hContext, TSS_HOBJECT hTPM, UINT32 cap,
UINT32 subcap, void *buf, size_t bufsize)
{
TSS_RESULT ret;
UINT32 datalen;
BYTE *data;
ret = Tspi_TPM_GetCapability(hTPM, cap, sizeof (subcap),
(BYTE *)&subcap, &datalen, &data);
if (ret) {
print_error(ret, gettext("Get TPM capability"));
return (ERR_FAIL);
}
if (datalen > bufsize) {
(void) fprintf(stderr,
gettext("Capability 0x%x returned %u bytes "
"(expected %u)\n"), cap, datalen, bufsize);
return (ERR_FAIL);
}
bcopy(data, buf, datalen);
ret = Tspi_Context_FreeMemory(hContext, data);
if (ret) {
print_error(ret, gettext("Free capability buffer"));
return (ERR_FAIL);
}
return (0);
}
示例12: print_tpm_pcrs
static int
print_tpm_pcrs(TSS_HCONTEXT hContext, TSS_HOBJECT hTPM)
{
UINT32 num_pcrs;
int i;
if (get_tpm_capability(hContext, hTPM, TSS_TPMCAP_PROPERTY,
TSS_TPMCAP_PROP_PCR, &num_pcrs, sizeof (num_pcrs)))
return (ERR_FAIL);
(void) printf(gettext("Platform Configuration Registers (%u)\n"),
num_pcrs);
/* Print each PCR */
for (i = 0; i < num_pcrs; i++) {
TSS_RESULT ret;
UINT32 datalen;
BYTE *data;
ret = Tspi_TPM_PcrRead(hTPM, i, &datalen, &data);
if (ret) {
print_error(ret, gettext("Read PCR"));
return (ret);
}
(void) printf("\tPCR %u:\t", i);
print_bytes(data, datalen, FALSE);
ret = Tspi_Context_FreeMemory(hContext, data);
if (ret) {
print_error(ret, gettext("Free PCR memory"));
return (ret);
}
}
return (0);
}
示例13: getrandombytes
void getrandombytes(
unsigned long bytes_size,
unsigned char *&output_value)
{
//establish a session
result = Tspi_Context_Connect(hcontext, 0);
if(result != TSS_SUCCESS) throw libhis_exception("Connect Context", result);
//get the TPM object
result = Tspi_Context_GetTpmObject(hcontext, &htpm);
if(result != TSS_SUCCESS) throw libhis_exception("Get TPM Object", result);
//get random bytes
BYTE *bytes_value;
result = Tspi_TPM_GetRandom(htpm, bytes_size, &bytes_value);
if(result != TSS_SUCCESS) throw libhis_exception("Get Random Bytes", result);
//copy C-style output into C++ format
output_value = new unsigned char[bytes_size];
for(unsigned long i = 0; i < bytes_size; i++)
{
output_value[i] = bytes_value[i];
}
//clean up random bytes
result = Tspi_Context_FreeMemory(hcontext, bytes_value);
if(result != TSS_SUCCESS) throw libhis_exception("Cleanup bytes", result);
return;
}
示例14: check
void check(char *msg, int cin)
{
int in = TSS_ERROR_CODE(cin);
printf("%s: ", msg);
if(in == TSS_SUCCESS) {
printf("TSS_SUCCESS\n");
return;
} else if(in == TSS_E_INVALID_HANDLE)
printf("\t\tTSS_E_INVALID_HANDLE\n");
else if(in == TSS_E_INTERNAL_ERROR)
printf("\t\tTSS_E_INTERNAL_ERROR\n");
else if(in == TSS_E_BAD_PARAMETER)
printf("\t\tTSS_E_BAD_PARAMETER\n");
else if(in == TSS_E_HASH_INVALID_LENGTH)
printf("\t\tTSS_E_HASH_INVALID_LENGTH\n");
else if(in == TSS_E_HASH_NO_DATA)
printf("\t\tTSS_E_HASH_NO_DATA\n");
else if(in == TSS_E_INVALID_SIGSCHEME)
printf("\t\tTSS_E_INVALID_SIGSCHEME\n");
else if(in == TSS_E_HASH_NO_IDENTIFIER)
printf("\t\tTSS_E_HASH_NO_IDENTIFIER\n");
else if(in == TSS_E_PS_KEY_NOTFOUND)
printf("\t\tTSS_E_PS_KEY_NOTFOUND\n");
else if(in == TSS_E_BAD_PARAMETER)
printf("\t\tTSS_E_BAD_PARAMETER\n");
else
printf("\t\tNot here: 0x%x\n", in);
Tspi_Context_FreeMemory(hContext, NULL);
Tspi_Context_Close(hContext);
exit(1);
}
示例15: read_pubkey
/* reads the RSA public key from the given TSS key.
* If psize is non-null it contains the total size of the parameters
* in bytes */
static int read_pubkey(gnutls_pubkey_t pub, TSS_HKEY key_ctx,
size_t * psize)
{
void *tdata;
UINT32 tint;
TSS_RESULT tssret;
gnutls_datum_t m, e;
int ret;
/* read the public key */
tssret = Tspi_GetAttribData(key_ctx, TSS_TSPATTRIB_RSAKEY_INFO,
TSS_TSPATTRIB_KEYINFO_RSA_MODULUS,
&tint, (void *) &tdata);
if (tssret != 0) {
gnutls_assert();
return tss_err(tssret);
}
m.data = tdata;
m.size = tint;
tssret = Tspi_GetAttribData(key_ctx, TSS_TSPATTRIB_RSAKEY_INFO,
TSS_TSPATTRIB_KEYINFO_RSA_EXPONENT,
&tint, (void *) &tdata);
if (tssret != 0) {
gnutls_assert();
Tspi_Context_FreeMemory(key_ctx, m.data);
return tss_err(tssret);
}
e.data = tdata;
e.size = tint;
ret = gnutls_pubkey_import_rsa_raw(pub, &m, &e);
Tspi_Context_FreeMemory(key_ctx, m.data);
Tspi_Context_FreeMemory(key_ctx, e.data);
if (ret < 0)
return gnutls_assert_val(ret);
if (psize)
*psize = e.size + m.size;
return 0;
}