Alice Whispers To Bob: At the core of privacy in the 21st Century is Extended Triple Diffie-Hellman and Ratchets

Prof Bill Buchanan OBE
Jun 16 · 9 min read

Some simple Diffie-Hellman

x3dh (Extended Triple Diffie-Hellman)

package main

import (
signal "github.com/dosco/libsignal-protocol-go"
"fmt"

)

func main() {


msA := signal.NewMemoryStore()
msB := signal.NewMemoryStore()

// Alice keys
idA := signal.GenerateRegistrationId()
msA.PutLocalRegistrationID(idA)


ikpA := signal.GenerateIdentityKeyPair()
msA.PutIdentityKeyPair(ikpA)

pkA := signal.GeneratePreKey(1)
msA.PutPreKey(1, pkA)

spkA := signal.GenerateSignedPreKey(ikpA, 1)
msA.PutSignedPreKey(1, spkA)

// Bob keys

idB := signal.GenerateRegistrationId()
msB.PutLocalRegistrationID(idB)

ikpB := signal.GenerateIdentityKeyPair()
msB.PutIdentityKeyPair(ikpB)

pkB := signal.GeneratePreKey(1)
msB.PutPreKey(1, pkB)

spkB := signal.GenerateSignedPreKey(ikpB, 1)
msB.PutSignedPreKey(1, spkB)


fmt.Printf("Alice ID (idA): %d\n", idB)
fmt.Printf("Alice ID key (pkA.Pub): %x\n", *pkA.Pub)
fmt.Printf("Alice Pre-key (spkA.Pub): %x\n\n", *spkA.Pub)

fmt.Printf("Bob ID (idB): %d\n", idB)
fmt.Printf("Bob ID key (pkB.Pub): %x\n", *pkB.Pub)
fmt.Printf("Bob Pre-key (spkB.Pub): %x\n\n", *spkB.Pub)


ephemeralKeyPair := signal.GenerateEphemeralKeyPair()
ekA := ephemeralKeyPair.Priv

// Calculate DH parameters and keys

dh1 := signal.DH(ikpA.Priv, spkB.Pub)
dh2 := signal.DH(ekA, ikpB.Pub)
dh3 := signal.DH(ekA, spkB.Pub)



fmt.Printf("DH1: %x\n", *dh1)
fmt.Printf("DH2: %x\n", *dh2)
fmt.Printf("DH3: %x\n", *dh3)

dhList := [][]byte{dh1[:], dh2[:], dh3[:]}

res := signal.KDF(dhList...)

fmt.Printf("\nKey (RootKey, ChainKey, Index): %x\n", *res)


}
Alice ID (idA): 2365460722503326970
Alice ID key (pkA.Pub): {27477a5a8af1141953c07c80769987042797dc141c92ceee7dde8cb6986aba2b}
Alice Pre-key (spkA.Pub): {7d8e1961549df7dc5063020eb2f30ac75899d0a71b0d2ab35528d7860d5f8c66}

Bob ID (idB): 2365460722503326970
Bob ID key (pkB.Pub): {7db8a56ee1c38fc2d20bc6f8f7cb48462b811e77e970a42acfb3b77192827970}
Bob Pre-key (spkB.Pub): {b7bd1285f297583978a24116053e69fc6e0564048b38f4a477fb6ca804099b0a}

DH1: 64e5514c1da82dc2b5eccef1fa96bc9066d763ee9eeba775fec1ba3a52024d40
DH2: dc6d9e773c6efd6c1a6f251eca01f8bc4f9b8765431ba6ac573e2eddcb31d20a
DH3: 8f2f59163616755cc99afa07201c3612c61e9029b96a6c39cf23ee34a5c1fe51

Key (RootKey, ChainKey, Index): {52827da3872cf4076dbc334a1fc9596599d745653a09fac7f0dcbad22337beca 1f1a4c84a1af18b7967449795c7995b6a946d2aace140e8e907cdcf5557e335e 0}

Signal

Double ratchet

Name 1:	Bob
Name 2: Alice
Bob keys are:
Identity key (Public key): tkUbaj1VwEIwi0kYRlWbl+0Don8WSgKOfbvij6+RT3c=
->Identity key (Private key): hIHdPPYfiF5eEoqXhAIOq1H5qy2VIJToadn1azjk96Q=
Ratchet key (Public key): 7P3yOKPcAX5rVnQkQCmmGfQdo0mi4GL33Yy7DpFMbU0=
-> Ratchet key (Private key): QYHS9FrJQ59VRDVqdwsDDVEbaaPp3myA+vUl3MTdC2Y=
Handshake Public key: a/xifzSbU5wSwF8CFh+xP2ybY7jG/gKoY7dW0DTOHhA=
->Handshake Private key: lSvv3TRFq7xuHxeTjQDqXQc2+UOALDDNJmRXnoDCUBA=
Encrypted message1 a->b: 2cuNbhbPkpcIck3j+9m76bUIr4X2cJdZSOARpGTzKPV3cs1NUrytT+CiNkgXVtJ2KEOzChxOeqLYoBjP11WW/UsSnkhFUkFH2So2iEXutBDHzlYExvQ9MCVkRkH6FaCnvpyPFvW5B6R+YUIok5CuZr0G9hI1Zqgcb0CRnZh0Nm4otP3f3A==Encrypted message2 a->b: efj2axgAmcBuyjkDzKARlaNzu5MzWqqqd0T9OZH/hW5Oy5JCQH1PN3/fYHu3lwU3N1gthhnGzHtJhlmq06pzXRcTJrhN5xlvsxAl+1K6t08QnD8Ev8myq1Ou719YySagwYRPBvZVo36GmFvN+qM05//weZtTFeL1fR2FZ1FMyjRR2+WiYjFzuE1AOw==Encrypted message3 b->a: H1gex6vZi0KTPywWK9XzVKmGiP2515XgYrM1Gx+kwq6JY8cQSLIKSHOjexqJhOR8MoGQs9IVX3aKbZkPRcKknsczl/jAdTav9ooFUe5c0XmJFWQEqwRkPgdpxFdbNmbMm7CwBne/6pyb7OfHEmzLUY+MYNLpF3dDwN6SOJFQTjzYe5eVaflBTrJn55TDb decrypt: The quick
b decrypt: brown fox jumps
a decrypt: over the lazy dog
H0(AlicePassword)≡HMAC(AlicePassword,0x00)
H1(AlicePassword)≡HMAC(AlicePassword,0x01)
H2(AlicePassword)≡HMAC(AlicePassword,0x02)
H3(AlicePassword)≡HMAC(AlicePassword,0x03)

Conclusions

ASecuritySite: When Bob Met Alice

This publication brings together interesting articles related to cyber security.

Prof Bill Buchanan OBE

Written by

Prof at Napier. Serial innovator. Crypto Punk. Believer in fairness, justice & freedom. EU Citizen. Auld Reekie native. Old World Breaker. New World Creator.

ASecuritySite: When Bob Met Alice

This publication brings together interesting articles related to cyber security.