Performing Elliptic Curve Operations

Step 5: Final

Step 5a: Allocate memory

You must allocate sufficient memory to hold the acceleration table. According to the Reference Manual, you can use B_BuildTableGetBufSize to tell how much space will be required to store the acceleration table:

ITEM accelTableItem; unsigned int maxTableLen;

if ((status = B_BuildTableGetBufSize(buildTable, &maxTableLen)) != 0) break;

accelTableItem.data = T_malloc(maxTableLen);

if ((status = (accelTableItem.data == NULL_PTR)) != 0) break;

Step 5b: Build the acceleration table

Finally, build the acceleration table and store it in an ITEM structure. You store it this way for convenience—when you actually use the acceleration table, you will have to provide it in an ITEM structure to B_SetAlgorithmInfo. Building an acceleration table can take a lot of time, so use a surrender context. See “The Surrender Context” on page 118 for more information:

ITEM accelTableItem;

generalSurrenderContext.Surrender = GeneralSurrenderFunction; generalSurrenderContext.handle = (POINTER)&generalFlag; generalSurrenderContext.reserved = NULL_PTR;

generalFlag = 0;

if ((status = B_BuildTableFinal(buildTable, accelTableItem.data, &(accelTableItem.len), maxTableLen, &generalSurrenderContext)) != 0)

break;

2 7 6

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 298
Image 298
RSA Security 5.2.2 manual Allocate memory, Build the acceleration table, Item accelTableItem