Curve 25519 is one of the most widely used ECC methods. It uses a curve of \(y^2 = x^3 + 486662 x^2 + x\) [plot], and which is a Montgomery curve. The prime number used is \(2^{255}-19\). In this case we will use Python to implement X25519 (and which uses Curve 25519), but only uses the x-axis point for the sharing of values. The base point \(G\) on Curve 25519 is (9,1478161944 ... 7755586237401). With X25519 we typically discard the y co-ordinate value, and only use the x-co-ordinate.
Curve 25519 with NaClTheoryCurve 25519 is one of the most widely used ECC methods. It uses a curve of: \(y^2 = x^3 + 486662 x^2 + x\) This is a Montgomery curve. The prime number used is \(2^{255}-19\). In this case we will use Python to implement X25519 (and which uses Curve 25519), but only uses the x-axis point for the sharing of values. The base point \(G\) on Curve 25519 is (9,1478161944 ... 7755586237401) The vectors are tested against the vectors [here] and [here]: Private= "a8abababababababababababababababababababababababababababababab6b" Public="e3712d851a0e5d79b831c5e34ab22b41a198171de209b8b8faca23a11c624859" Private="c8cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd4d" Public="b5bea823d9c9ff576091c54b7c596c0ae296884f0e150290e88455d7fba6126f" Shared="235101b705734aae8d4c2d9d0f1baf90bbb2a8c233d831a80d43815bb47ead10" and: Alice's private key, a: 77076d0a7318a57d3c16c17251b26645df4c2f87ebc0992ab177fba51db92c2a Alice's public key, X25519(a, 9): 8520f0098930a754748b7ddcb43ef75a0dbf3a0d26381af4eba4a98eaa9b4e6a Bob's private key, b: 5dab087e624a8a4b79e17f8b83800ee66f3bb1292618b6fd1c2f8b27ff88e0eb Bob's public key, X25519(b, 9): de9edb7d7b7dc1b4d35b61c2ece435373f8343c85b78674dadfc7e146f882b4f Their shared secret, K: 4a5d9d5ba4ce2de1728e3bf480350f25e07e21c947d19e3376f09b3c1e161742 The coding is: from nacl import bindings as c from typing import List, Tuple from binascii import hexlify, unhexlify import binascii import sys def tohex(b: bytes) -> str: return hexlify(b).decode("ascii") val=2 if (len(sys.argv)>1): val=int(sys.argv[1]) inval= val.to_bytes(32, 'little') print("\nVal: ",val) print("Val (binary): ",inval.hex()) res = c.crypto_scalarmult_base(inval) print (f"{val}.G: {res.hex()}") print (f"{val}.G: ",int.from_bytes(res,"integer")) test1= binascii.unhexlify("a8abababababababababababababababababababababababababababababab6b") res = c.crypto_scalarmult_base(test1) print ("\nTest 1: ",res.hex()) if (res.hex()=="e3712d851a0e5d79b831c5e34ab22b41a198171de209b8b8faca23a11c624859"): print(" Successful test") test2= binascii.unhexlify("c8cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd4d") res = c.crypto_scalarmult_base(test2) print ("Test 2: ",res.hex()) if (res.hex()=="b5bea823d9c9ff576091c54b7c596c0ae296884f0e150290e88455d7fba6126f"): print(" Successful test") print("\nNow we generate random keys") pubkey, secretkey = c.crypto_box_keypair() print ("Private key: ",tohex(secretkey)) print ("Public key: ",tohex(pubkey)) A sample run shows: Private key: 21e92f3f32bec5ffda005329940341785ca9a8403be412641412efb3eb52138f Public key: 0928cb724ad9d8982f7f4793e1262d97de8d1b5f891f57738f393fee11acb256 Val: 1 Val (binary): 0100000000000000000000000000000000000000000000000000000000000000 1.G: 2fe57da347cd62431528daac5fbb290730fff684afc4cfc2ed90995f58cb3b74 Test 1: e3712d851a0e5d79b831c5e34ab22b41a198171de209b8b8faca23a11c624859 Successful test Test 2: b5bea823d9c9ff576091c54b7c596c0ae296884f0e150290e88455d7fba6126f Successful test |