No Key: a simple library for Shamir’s no-key protocol
Shamir’s no-key protocol is a way to encrypt a communication using finite exponentiation. It is similar to Diffie-Hellman in that it depends on the difficulty of solving the discrete logarithm problem, but unlike DH, where both parties agree on a previously unkown datum, the no-key protocol is used to share information (party A transmit some data to party B).
The algorithm is as follows. Assume A wants to transmit message m (which is an integer number) to B. Both parties have previuosly agreed on a prime number p, which can be public.
- A chooses a random number
0<=q1<psuch thatq1and(p-1)are relatively prime, and computes
m1 = pow(m,q1) mod (p), wherepow(a,b)is the exponentiationato the powerb.
Then A sends m1 to B. - B chooses a random number
0<=q2<psuch thatq1and(p-1)are relatively prime and computes
m2 = pow(q1,q2) mod (p)
and sendsm2back to A. - A computes
q1*, the inverse ofq1modulo(p-1)(not modulo p) and sendsm3 = pow(m2,q1*) mod (p)to B. - B comptues
q2*, the inverse ofq2 modulo (p-1)andm4 = pow(m3,q2*) mod (p).
This lastm4is equal tomand B has the initial message