B_KeyAgreePhase1
NULL_PTR

Performing Diffie-Hellman Key Agreement

if ((status = B_SetAlgorithmInfo (dhKeyAgreeAlg, AI_DHKeyAgreeBER, (POINTER)&dhParametersBER)) != 0)

break;

Step 3: Init

Initialize the algorithm object with B_KeyAgreeInit. The Reference Manual Chapter 4 entry on this function indicates it takes four arguments. The first is the algorithm object, dhKeyAgreeAlg. The second is a key object. The Diffie-Hellman key agreement algorithm does not require a key, so use a properly cast NULL_PTR for this argument. The third argument is an algorithm chooser, and the last is a surrender context. This

function is fast, so it is reasonable to pass a properly castfor the surrender context.

B_ALGORITHM_METHOD *DH_AGREE_SAMPLE_CHOOSER[] = { &AM_DH_KEY_AGREE,

(B_ALGORITHM_METHOD *)NULL_PTR

};

if ((status = B_KeyAgreeInit

(dhKeyAgreeAlg, (B_KEY_OBJ)NULL_PTR, DH_AGREE_SAMPLE_CHOOSER, (A_SURRENDER_CTX *)NULL_PTR)) != 0)

break;

Step 4: Phase 1

In Phase 1, you generate a random private value and compute a public value from that private value and the parameters. The Reference Manual Chapter 4 entry on

describes the format of its six arguments.

The first is the algorithm object.

The second is output. This output is the public value, which will be the same size as the prime. You are responsible for allocating the memory for the buffer to contain the public value. In this example, you do not know how big the prime is; just set the algorithm with the BER-encodedinfo. That info does contain the size of the prime, but you would have to know exactly where to look. An easier way to find the prime size is by getting the algorithm info as AI_DHKeyAgree.

The third argument for the Phase 1 call is the address of an unsigned int. Crypto-C will place the length in bytes of the public value at that address.

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 5 7

Page 279
Image 279
RSA Security 5.2.2 manual If status = BKeyAgreeInit