This PR adds encryption to the p2p communication after a slightly overhauled version of BIP151 defined here (there is the plan to change BIP151 or to propose this protocol in a new BIP)
The encryption is optional and by default disabled (-netencryption
).
If enabled, a peer connecting to another peer signalling NODE_ENCRYPTED
(or added via -connect=
) will try to do the proposed key handshake and continue with encrypted communication.
If enabled, peers can request (and perform) encrypted communications by sending a handshake request.
Peers not supporting encryption are still accepted (no option to enforce encrypted communication).
There is a plan to make the handshake quantum resistance by adding NewHope to the key handshake (https://newhopecrypto.org). But since this PR is already very large, it’s unclear wether this should be an independent patch (probably another ~600 lines of code).
Out of scope:
- optimized ChaCha20 implementation (for review and security reasons, the implementation is extracted from openssh)
- benchmarks added to bench (I have done comparison against the v1 protocol with dbl-SHA256 the performance seems very similar)
- Please no discussion about the used crypto scheme or the proposal itself (better place would be the mailing list)
TODO:
- add option to
-connect=
RPCaddnode
where it is possible to specify the expected service flags (currently-connect=
will always try for encrypted coms).