A SERVICE OF

logo

Performing Elliptic Curve Operations
272 RSA BSAFE Crypto-C Developers Guide
B_GetKeyInfo gives a pointer to memory, but this memory is owned by Crypto-C. If
you want to store this information, you need to make your own copy of the
information because another call to Crypto-C may modify the memory owned by
Crypto-C. The routines
AllocAndCopyECPubKeyInfo
and
FreeECPubKeyInfo
given here
retrieve and store the key information. These routines are used in the sample code for
building public-key acceleration tables.
AllocAndCopyECPubKeyInfo
takes as input a pointer to an A_EC_PUBLIC_KEY structure
containing memory belonging to Crypto-C. It copies the information from the
structure owned by Crypto-C to an
A_EC_PUBLIC_KEY structure created by the
application and outputs a pointer to the structure just created. The memory allocated
with
AllocAndCopyECPubKeyInfo
should be freed using
FreeECPubKeyInfo
when
appropriate:
FreeECPubKeyInfo
takes a pointer to an A_EC_PUBLIC_KEY structure that contains space
that was allocated by
AllocAndCopyECPubKeyInfo
and calls T_malloc to free all allocated
data:
int AllocAndCopyECPubKeyInfo(output, input)
A_EC_PUBLIC_KEY *output;
A_EC_PUBLIC_KEY *input;
{
int status;
do {
output->publicKey.len = input->publicKey.len;
output->publicKey.data = T_malloc(output->publicKey.len);
if ((status = (output->publicKey.data == NULL_PTR)) != 0)
break;
T_memcpy(output->publicKey.data, input->publicKey.data,
output->publicKey.len);
if ((status = AllocAndCopyECParamInfo(&(output->curveParams),
&(input->curveParams))) != 0)
break;
} while(0);
if (status != 0)
printf("AllocAndCopyECPubKeyInfo failed with status %i\n", status);
return status;
} /* end AllocAndCopyECPubKeyInfo */