# Replacing elliptic curve diffie-hellman primitive with elliptic curve cofactor diffie-hellman for specifc curves?

From what I've read about elliptic curve Diffie-hellman with and without cofactor (I am pretty new to the whole thing so I am not able to understand everything) is that when the cofactor of the curve $$h$$ is $$1$$, Both should give the same result. So for curves such as secp256r1 (which has $$h=1$$) both should give the same result. Unfortunately, when I am coding it using some third party libraries for Diffie-Hellman primitive without cofactor, I am not getting the expected result of Diffie Hellman with the cofactor. At this point, I am not sure if I have understood the theory incorrectly or if there's some issue with my code. Could someone verify or refute my understanding?

• You say "both should give the same result". Both what? Do you mean that you're getting $(g^a)^b \ne (g^b)^a$? Then it's a bug in your code. Nothing to do with the cofactor. Jun 18 '19 at 8:19
• @fkraiem . Actually, I meant that ( ECDH with cofactor) and (ECDH without cofactor) should both give the same result if the cofactor of the curve is 1 . After using another third party source I am getting the correct result. There seems to be an issue in code Jun 18 '19 at 8:59
• "ECDH with(out) cofactor" is not standard terminology. I personally have no idea what it could mean; ECDH is ECDH, regardless of the cofactor. Jun 18 '19 at 10:29
• I have come across the terms "Elliptic Curve Diffie-Hellman Primitive" and "Elliptic Curve Cofactor Diffie-Hellman Primitive" for differentiating them in a pretty standard documentation. secg.org/sec1-v2.pdf Jun 18 '19 at 11:06
• You should add this reference to your question. Of course, if the cofactor is 1, the two procedures are the same. Jun 18 '19 at 11:17