Skip to content

Commit 5f0981d

Browse files
Sjorsjakubtrnka
andcommitted
Expand ECDH details
Co-authored-by: Jakub Trnka <[email protected]>
1 parent fb03db5 commit 5f0981d

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

04-Protocol-Security.md

+19-1
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,28 @@ The following functions will also be referenced:
153153
- Calls `MixHash(ciphertext)`
154154
- returns `plaintext`
155155

156-
- `ellswift_ecdh_xonly(k, rk)`: performs an Elliptic-Curve Diffie-Hellman operation
156+
- `ECDH(k, rk)`: performs an Elliptic-Curve Diffie-Hellman operation
157157
using `k`, which is a valid `secp256k1` private key, and `rk`, which is a EllSwift
158158
encoded public key
159159
- The output is 32 bytes
160+
- It is a shortcut for performing operation `v2_ecdh` defined in BIP324<sup>[7](#reference-7)</sup>:
161+
- let `k, ellswift_k` be key pair created by `ellswift_create()` function
162+
- let `rk` be remote public key **encoded as ellswift**.
163+
- let `initiator` be bool flag that is **true** if the party performing ECDH initiated the handshake
164+
- then `ECDH(k, rk) = v2_ecdh(k, ellswift_k, rk, initiator)`
165+
166+
- `v2_ecdh(k, ellswift_k, rk, initiator)`:
167+
- let `ecdh_point_x32` = `ellswift_ecdh_xonly(rk, k)`
168+
- if initiator == true:
169+
- return `tagged_hash(ellswift_k, rk, ecdh_point_x32)`
170+
- else return `tagged_hash(rk, ellswift_k, ecdh_point_x32)`
171+
- **Note that the ecdh result is not commutative with respect to roles! Therefore the initiator flag is needed**
172+
173+
- `ellswift_ecdh_xonly` - see BIP324<sup>[7](#reference-7)</sup>
174+
- `tagged_hash(a, b, c)`:
175+
- let tag = `SHA256("bip324_ellswift_xonly_ecdh")`
176+
- return `SHA256(concatenate(tag, tag, a, b, c))`
177+
160178

161179

162180

0 commit comments

Comments
 (0)