The Yakk JPake Implementation 🔗
PAKE 🔗
It's a well-known fact -- strong passwords are better! (up until you can't remember them that is).
When creating YAKK, I wanted a way of allowing 2 users to share a signalling connection, but without mandating that they use a large secure key to encrypt the connection information. In addition, I was adamant that the controller of the communication channel between these 2 users cannot evesdrop on the messages sent without knowing the shared password, and is not able to brute-force guess the password. (TLDR: see it in action here)
Enter Password Authenticated Key Exchange (PAKE).
PAKE allows our 2 parties, Alice and Bob, to establish a shared cryptographic key using a weak shared secret (like a simple password), without needing to trust the communication channel used to establish the shared key.
JPake using modular arithmetic 🔗
J-PAKE (Password Authenticated Key Exchange by Juggling) is one such PAKE protocol, proposed by Hao and Ryan.
It consists of 2 stages:
- one-time key establishment
- key confirmation
A quick summary of the protocol can be written as follows.
Round 0 🔗
First, both Alice and Bob separately derive secret value from a shared low-entropy password .
In our implementation, this is done as . This is because has to be in the range . Alice and Bob also both check that is not equal to zero
Alice | Bob |
---|---|
Select uniformly from | Select uniformly from |
Select uniformly from | Select uniformly from |
Round 1 🔗
Alice -> Bob | Bob -> Alice |
---|---|
ZKP for and | ZKP for and |
Round 2 🔗
Alice -> Bob | Bob -> Alice |
---|---|
Verify received ZKP for and | Verify received ZKP for and |
ZKP for | ZKP for |
Compute Shared Key 🔗
Alice's Shared Key | Bob's Shared Key |
---|---|
Verify received ZKP for | Verify received ZKP for |
Here,
Using as an input, we can then apply a Key Derivation Function (KDF) to derive a common session key . In our implementation, we do this by doing:
JPake using elliptic curves 🔗
The discrete log problem 🔗
Let G be a group with binary operation .
Let g be any element of G. For any positive integer k, the expression denotes performing the operation on with itself times.
i.e. .
Any integer which solves the equation is termed to be a discrete logarithm of to the base , i.e. .
In the above setting, we used the group to perform our cryptographic operations. This is the group of multiplication modulo the prime .
Eg: In the group in the group , is calculated as: .
Note that the discrete log problem is only hard in certain carefully chosen groups. Other than the group of we saw earlier, another group which is useful to us in the cryptographic context is based on elliptic curves.
Elliptic curves 🔗
For cryptographic purposes, an elliptic curve is defined as a plane curve over a finite field which consists of points satisfying the equation
Combined with a group operation as an addition of 2 elements in the group, allows us to reformulate our discrete log problem as:
We can convert operations from the group to the elliptic curve setting by converting them as the following:
methods | Elliptic curve methods (over a finite field p) | |
---|---|---|
exponentiation | -> | multiplication |
multiplication | -> | point addition |
division | -> | point subtraction $(xG - yG) |
JPake using elliptic curves 🔗
With this knowledge, we can then convert our modular arithmetic operations into elliptic curve operations using the generator .
Round 0 🔗
Alice | Bob |
---|---|
Select uniformly from | Select uniformly from |
Select uniformly from | Select uniformly from |
Round 1 🔗
Alice -> Bob | Bob -> Alice |
---|---|
ZKP for and | ZKP for and |
Round 2 🔗
Alice -> Bob | Bob -> Alice |
---|---|
Verify received ZKP for and | Verify received ZKP for and |
ZKP for | ZKP for |
Compute Shared Key 🔗
Alice's Shared Key | Bob's Shared Key |
---|---|
Verify received ZKP for | Verify received ZKP for |