RSA Security 5.2.2 manual Performing Elliptic Curve Operations

Models: 5.2.2

1 376
Download 376 pages 13.91 Kb
Page 294
Image 294

Performing Elliptic Curve Operations

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:

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 */

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:

2 7 2

R S A B S A F E C r y p t o - C D e v e l o p e r ’s G u i d e

Page 294
Image 294
RSA Security 5.2.2 manual Performing Elliptic Curve Operations