Performing Diffie-Hellman Key Agreement
256 RSA BSAFE Crypto-C Developers Guide
Diffie-Hellman Key Agreement
If you are one of the parties involved in the key agreement, perform the following
steps. Note that instead of Update and Final, you use B_KeyAgreePhase1 and
B_KeyAgreePhase2. Also, if you are writing an application that executes the Diffie-
Hellman key agreement, the application must be interactive.
This process will produce an agreed-upon secret value. That value may be larger than
necessary. For instance, the agreement may produce a 64-byte agreed upon secret
value, yet the parties may need only 8 bytes. The application must determine which
bytes from the agreed upon secret value to use.
The example in this section corresponds to the file dhagree.c.
Step 1: Creating An Algorithm Object
Declare a variable to be B_ALGORITHM_OBJ. As defined in the function prototype in
Chapter 4 of the Reference Manual, its address is the argument for
B_CreateAlgorithmObject:
Step 2: Setting The Algorithm Object
There are two possible AIs to use in setting a Diffie-Hellman key agreement algorithm
object: AI_DHKeyAgree and AI_DHKeyAgreeBER. Recall that in generating the Diffie-
Hellman parameters, the central authority set an algorithm object and then retrieved
its
info
using B_GetAlgorithmInfo. The central authority then distributed that
info
to
you, telling you which AI to use. For this example, use AI_DHKeyAgreeBER to match
the usage in Distributing Diffie-Hellman Parameters on page253:
B_ALGORITHM_OBJ dhKeyAgreeAlg = (B_ALGORITHM_OBJ)NULL_PTR;
if ((status = B_CreateAlgorithmObject (&dhKeyAgreeAlg)) != 0)
break;
/* Assume you received the BER-encoded DH parameters from the
central authority in the ITEM dhParametersBER. */
ITEM dhParametersBER;