From c0d83014c92cacd461cec72e2904bea525e1c6cd Mon Sep 17 00:00:00 2001 From: Ritu Sood Date: Tue, 22 May 2018 14:17:11 +0000 Subject: Allocating memory for modulus and exponent SoftHsm expects memory to be allocated by the plugin Issue-ID: AAF-260 Change-Id: I4ef93918a91971680f1f46517a46a29717a096b2 Signed-off-by: Ritu Sood --- TPM2-Plugin/lib/tpm2_plugin_api.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'TPM2-Plugin/lib') diff --git a/TPM2-Plugin/lib/tpm2_plugin_api.c b/TPM2-Plugin/lib/tpm2_plugin_api.c index 356ce7b..b949e48 100644 --- a/TPM2-Plugin/lib/tpm2_plugin_api.c +++ b/TPM2-Plugin/lib/tpm2_plugin_api.c @@ -384,11 +384,18 @@ int read_public(TSS2_SYS_CONTEXT *sapi_context, importkey_info->modulus_size = public.t.publicArea.unique.rsa.t.size; printf("importkey_info->modulus_size = %ld \n", importkey_info->modulus_size); - memcpy(importkey_info->modulus, &public.t.publicArea.unique.rsa.t.buffer, importkey_info->modulus_size); + importkey_info->modulus = (unsigned char *) malloc(importkey_info->modulus_size); + if (importkey_info->modulus != NULL) { + memcpy(importkey_info->modulus, &public.t.publicArea.unique.rsa.t.buffer, importkey_info->modulus_size); + } importkey_info->exponent_size = sizeof(public.t.publicArea.parameters.rsaDetail.exponent); printf("importkey_info->exponent_size = %ld \n", importkey_info->exponent_size); - memcpy(importkey_info->exponent, &public.t.publicArea.parameters.rsaDetail.exponent, importkey_info->exponent_size); + importkey_info->exponent = (unsigned char *) malloc(importkey_info->exponent_size); + if (importkey_info->exponent != NULL) { + memcpy(importkey_info->exponent, &public.t.publicArea.parameters.rsaDetail.exponent, importkey_info->exponent_size); + } + //*importkey_info->exponent = public.t.publicArea.parameters.rsaDetail.exponent; return 0; -- cgit 1.2.3-korg