Skip to main content

Module crypto

Module crypto 

Source
Expand description

The cryptography devp2p is built from: secp256k1 node keys, ECDH, recoverable signatures, keccak-256, and the ECIES variant the RLPx handshake encrypts with.

ECIES here is go-ethereum’s crypto/ecies with ECIES_AES128_SHA256, the only parameter set RLPx uses: an ephemeral secp256k1 key R, z = the x-coordinate of R·pub, a 32-byte NIST SP 800-56 concatenation KDF over SHA-256 (counter 1, no shared info), Ke = the first 16 bytes, Km = SHA-256 of the last 16, AES-128-CTR under Ke with a random IV, and an HMAC-SHA256 tag under Km over IV ‖ ciphertext ‖ shared_mac_data. RLPx passes the message’s two-byte size prefix as shared_mac_data, so the prefix is authenticated too.

The wire form is 0x04 ‖ R (64) ‖ IV (16) ‖ ciphertext ‖ tag (32): 113 bytes of overhead.

Structs§

NodeKey
A node’s identity: its secp256k1 key. The node id is the 64-byte uncompressed public key without the 0x04 prefix.

Constants§

ECIES_OVERHEAD
Bytes ECIES adds to a plaintext: the ephemeral key, the IV and the tag.

Functions§

ecdh_x
The x-coordinate of secret · public: the raw ECDH shared secret devp2p uses everywhere.
ecies_decrypt
Decrypt a message sent to secret. The tag is checked before anything is decrypted, in constant time.
ecies_encrypt
Encrypt plain to remote.
keccak256
keccak-256 (the pre-standard Keccak Ethereum uses, not SHA3-256) of the concatenation.
node_id
The 64-byte node id of a public key.
public_from_id
The public key a 64-byte node id names, refused when it is not a point on the curve.
recover
The public key that signed digest, from an r ‖ s ‖ v signature.
sign_recoverable
A recoverable signature over a 32-byte digest, as r ‖ s ‖ v with v 0 or 1.