bip324: fix handshake pseudocode errors - #2259
Open
ViniciusCestarii wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix 4 bugs only in the pseudocode.
responder_K is never defined anywhere in the BIP. It should be responder_P.
ellswift_Y is not a variable in scope in respond_v2_handshake. The keypair was generated two lines earlier as peer.privkey_ours, peer.ellswift_ours, so use peer.ellswift_ours instead.
respond_v2_handshake consumes the first 1..16 bytes of the peer's key one at a time while testing them against V1_PREFIX. Those bytes are already off the wire, so discarding them leaves ellswift_theirs short by len(received_prefix) with every byte shifted. received_prefix is computed on line 365 and then never used again, which is the tell. Two consequences:
Prepending fixes both, and matches the prose at line 361: "The responder performs very similar steps but includes the earlier received prefix bytes in the public key."
Hardcoding True makes the responder encrypt with initiator_P and try to decrypt with responder_P (the initiator's assignment), so neither side can read the other.