commit 2e4fe1c16d971fb43e9efb70d01d4e2dfc5c4a56 parent 4e4f12380524e1721315cfff125b5b3f06e4f6c3 Author: Jared Tobin <jared@jtobin.io> Date: Fri, 14 Mar 2025 14:51:04 +0400 lib: add ecdh example Diffstat:
M | lib/Crypto/Curve/Secp256k1.hs | | | 9 | ++++++++- |
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/lib/Crypto/Curve/Secp256k1.hs b/lib/Crypto/Curve/Secp256k1.hs @@ -1249,7 +1249,14 @@ _verify_ecdsa_unrestricted _mul (SHA256.hash -> h) p (ECDSA r s) -- The shared secret is the SHA256 hash of the x-coordinate of the -- point obtained by scalar multiplication. -- --- +-- >>> let sec_alice = 0x03 -- contrived +-- >>> let sec_bob = 2 ^ 128 - 1 -- contrived +-- >>> let pub_alice = derive_pub sec_alice +-- >>> let pub_bob = derive_pub sec_bob +-- >>> let secret_as_computed_by_alice = ecdh pub_bob sec_alice +-- >>> let secret_as_computed_by_bob = ecdh pub_alice sec_bob +-- >>> secret_as_computed_by_alice == secret_as_computed_by_bob +-- True ecdh :: Projective -- ^ public key -> Integer -- ^ secret key