exth_crypto v0.1.6 ExthCrypto.ECIES.ECDH

Implements Elliptic Curve Diffie-Hellman, as it pertains to Exthereum.

Link to this section Summary

Functions

Generates a static shared secret between two parties according to the protocol for elliptic curve diffie hellman

Generates a new keypair for elliptic curve diffie-hellman

Link to this section Functions

Link to this function generate_shared_secret(local_private_key, remote_public_key, curve \\ :secp256k1)

Generates a static shared secret between two parties according to the protocol for elliptic curve diffie hellman.

Examples

iex> ExthCrypto.ECIES.ECDH.generate_shared_secret(ExthCrypto.Test.private_key(:key_b), ExthCrypto.Test.public_key(:key_a), :secp256k1)
<<68, 139, 102, 172, 32, 159, 198, 236, 33, 216, 132, 22, 62, 46, 163, 215, 53, 40, 177, 14, 51, 94, 155, 151, 21, 226, 9, 254, 153, 48, 112, 226>>

iex> ExthCrypto.ECIES.ECDH.generate_shared_secret(ExthCrypto.Test.private_key(:key_a), ExthCrypto.Test.public_key(:key_b), :secp256k1)
<<68, 139, 102, 172, 32, 159, 198, 236, 33, 216, 132, 22, 62, 46, 163, 215, 53, 40, 177, 14, 51, 94, 155, 151, 21, 226, 9, 254, 153, 48, 112, 226>>
Link to this function new_ecdh_keypair(curve \\ :secp256k1)

Generates a new keypair for elliptic curve diffie-hellman.

These keys should be used as ephemeral keys in the key-exchange protocol.

Examples

iex> {public_key, private_key} = ExthCrypto.ECIES.ECDH.new_ecdh_keypair()
iex> byte_size(public_key)
65
iex> byte_size(private_key)
32
iex> {public_key, private_key} == :crypto.generate_key(:ecdh, :secp256k1, private_key)
true