Performing Elliptic Curve Operations

if ((status = B_KeyAgreeInit(alice, (B_KEY_OBJ)NULL_PTR, EC_DH_CHOOSER, (A_SURRENDER_CTX *)NULL_PTR)) != 0)

break;

You must allocate space to hold the results of Phase 1 and Phase 2. The largest size of Phase 1 output you can get is one byte larger than twice the field element size. For Phase 2, the size of the output should be the same as the field element size. (See the Reference Manual Chapter 2 entry for AI_EC_DHKeyAgree for details.)

You can get the field element size using Alice’s elliptic curve parameters. Since you have the parameters in the A_EC_PARAMS structure ecParams, look at the fieldElementBits field, which gives you the required information. A simple manipulation gives you the field element length in bytes:

unsigned int fieldElementLen, maxPhase1Len, maxPhase2Len;

fieldElementLen = (ecParams->fieldElementBits + 7) / 8; maxPhase1Len = (fieldElementLen * 2);

maxPhase2Len = fieldElementLen;

Step 4: Phase 1

During this phase, each party computes a private value and a public value. The private value is secret and currently cannot be accessed though the Crypto-C API. The public value should be transported to the other party. Note that you will have to supply a properly initialized random algorithm as the fifth argument to B_KeyAgreePhase1:

unsigned char *alicePublicValue = NULL_PTR; unsigned int alicePublicValueLen; alicePublicValue = T_malloc(maxPhase1Len);

if ((status = (alicePublicValue == NULL_PTR)) != 0) break;

if ((status = B_KeyAgreePhase1(alice, alicePublicValue, &alicePublicValueLen, maxPhase1Len, randomAlgorithm, (A_SURRENDER_CTX *)NULL_PTR)) != 0)

break;

C h a p t e r 7 P u b l i c - K e y O p e r a t i o n s

2 8 3

Page 305
Image 305
RSA Security 5.2.2 manual Phase, If status = alicePublicValue == Nullptr != 0 break