The Diffie-Hellman Public-Key Blob

Diffie-Hellman public-key blobs (type PUBLICKEYBLOB) are used to exchange the (G^X) mod P value in a D-H key exchange. They have the following format:

BLOBHEADER blobheader; // As explained under "Data Structures"
DHPUBKEY dhpubkey;
BYTE y[dhpubkey.bitlen/8]; // Where y = (G^X) mod P
 

The following table describes each component of the key blob.

Field Description
blobheader A BLOBHEADER structure. The bType member must have a value of PUBLICKEYBLOB.
dhpubkey A DHPUBKEY structure. The magic member should be set to "DH1" (0x31484400) for public keys.

Notice that the hex value is just an ASCII encoding of "DH1."

y The Y value, (G^X) mod P, is located directly after the DHPUBKEY structure, and should always be the length (in bytes) of the DHPUBKEY bitlen field (bit length of P) divided by eight. If the length of the data that results from the calculation of (G^X) mod P is one or more bytes shorter than P divided by 8, the data must be padded with the necessary bytes (of zero value) to make the data the desired length (little-endian format).