# How to handle IKEv1 and IKEv2 diffie-hellman shared secret bits length not multiple of 8?

In Cryptographic Algorithm Validation Program for KDF document, here, page 9, it says "If a field size that is not a multiple of 8 bits, the shared secret is represented by a string of bytes that is padded with zeros on the left".

However, I get a valid input like this, dhLength=4348 g^xy=ED6DAAE... (Total contains 1088 characters in hex, so 544 bytes, so 4352 bits)

where dhLength < length of g^xy, how to handle this situation, also g^xy is not started with padding 0. I tried to cut, pad 0 to extra long, erase 'E' to '0', results are all wrong.

• That is completely a programming issue and going to be off-topic here. With a nicely presented code, it can be answered in StackOverflow. Do you keep this data in which form? BYTE []? – kelalaka Jun 21 at 20:23
• Hi, @kelalaka . My question could be if dhLength(in bits) < g^xy length(in bits), what shall I do? CAVP standards only talk about dhLength > g^xy length, and the provided request vectors also dhLength > g^xy. For programming, I firstly read the hex, convert to bytes, then input bytes array and size in bytes. In this case, (g_xy_byte, 544) are input. My software itself 100% no problem. – Joe Jun 21 at 20:33
• I think there is something seriously wrong if you get values that are larger than the field size, right? – Maarten Bodewes Jun 21 at 20:34
• @MaartenBodewes True. But this is the valid vector that provides from NIST ACVP ( Automated Cryptographic Validation Program). I am also confused with it. – Joe Jun 21 at 20:36
• dhLength(in bits) < g^xy length(in bits) this shouldn't be the case since $g^{xy}$ is computed modulo. – kelalaka Jun 21 at 20:37