CSS411 Cryptography

ECC Sample Problems 1

Worked solutions for the first ECC problem set: RSA key, Diffie-Hellman, EC point addition and membership tests.

19 min read

Tools needed before the problemsSearch on YouTube

This page solves Assignment 1 (25 marks). It has four problems. Each problem needs one of three computations. Learn the setup lines first. Then each problem is only arithmetic.

RSA key generationSearch on YouTube

Given primes pp and qq and a public key ee:

n=p⋅q,φ(n)=(p−1)(q−1)n = p \cdot q, \qquad \varphi(n) = (p-1)(q-1)

The private key dd satisfies e⋅d≡1(modφ(n))e \cdot d \equiv 1 \pmod{\varphi(n)}, so d=e−1 mod φ(n)d = e^{-1} \bmod \varphi(n).

Diffie-Hellman key exchangeSearch on YouTube

Common open parameters are a prime qq and a primitive root α\alpha of qq. Party A picks a private key XAX_A and publishes:

YA=αXA mod qY_A = \alpha^{X_A} \bmod q

Party B does the same with XBX_B and secretly computes:

K=YBXA mod q=YAXB mod qK = Y_B^{X_A} \bmod q = Y_A^{X_B} \bmod q

Both raise the other party's public key to their own private key, so the shared key is equal on both sides.

Elliptic curve point additionSearch on YouTube

For P=(xP,yP)P = (x_P, y_P) and Q=(xQ,yQ)Q = (x_Q, y_Q) with P≠QP \neq Q on the curve y2=x3+ax+by^2 = x^3 + ax + b over a field of modulus pp:

λ=yQ−yPxQ−xP mod p\lambda = \frac{y_Q - y_P}{x_Q - x_P} \bmod p

xR=(λ2−xP−xQ) mod px_R = (\lambda^2 - x_P - x_Q) \bmod p

yR=(λ(xP−xR)−yP) mod py_R = \left(\lambda(x_P - x_R) - y_P\right) \bmod p

P+Q=(xR,yR)P + Q = (x_R, y_R)

The slope λ\lambda contains a division modulo pp. To divide, multiply by the inverse: 57 mod p=5⋅(7−1) mod p\dfrac{5}{7} \bmod p = 5 \cdot (7^{-1}) \bmod p. For point doubling, with P=QP = Q:

λ=3xP2+a2yP mod p\lambda = \frac{3x_P^2 + a}{2y_P} \bmod p

Membership test: a point (x,y)(x, y) lies on y2=x3+ax+b mod py^2 = x^3 + ax + b \bmod p when y2 mod p=(x3+ax+b) mod py^2 \bmod p = (x^3 + ax + b) \bmod p.

Problem 1: RSA private key (5 marks)Search on YouTube

Statement. Participant A in an RSA cryptosystem uses primes p=13p = 13 and q=17q = 17. The public key of A is e=35e = 35. Find the private key of A.

Step 1, modulus and totient.

n=13×17=221n = 13 \times 17 = 221

φ(n)=(13−1)(17−1)=12×16=192\varphi(n) = (13-1)(17-1) = 12 \times 16 = 192

Step 2, invert ee modulo φ(n)\varphi(n). Find dd with 35 d≡1(mod192)35\,d \equiv 1 \pmod{192}.

dd35d35d35d mod 19235d \bmod 192
5175175
724553
9315123
11385385 − 384 = 1\mathbf{1}

Step 3, answer.

d=11d = 11

35×11=385=2×192+135 \times 11 = 385 = 2 \times 192 + 1, so 35⋅11≡1(mod192)35 \cdot 11 \equiv 1 \pmod{192} and the private key of A is 11.

To find dd quickly, test the values k⋅192+1k \cdot 192 + 1 for k=1,2,…k = 1, 2, \dots. Stop at the first value that 35 divides exactly. 2×192+1=385=35×112 \times 192 + 1 = 385 = 35 \times 11, so d=11d = 11.

Problem 2: Diffie-Hellman key exchange (5 marks)Search on YouTube

Statement. A and B agree on prime q=17q = 17 and primitive root α=5\alpha = 5. A chooses XA=4X_A = 4 and B chooses XB=6X_B = 6. Find the key they exchange.

Step 1, public key of A.

YA=54 mod 17=625 mod 17Y_A = 5^4 \bmod 17 = 625 \bmod 17

17×36=61217 \times 36 = 612, so 625−612=13625 - 612 = 13:

YA=13Y_A = 13

Step 2, public key of B.

YB=56 mod 17=15625 mod 17Y_B = 5^6 \bmod 17 = 15625 \bmod 17

17×919=1562317 \times 919 = 15623, so 15625−15623=215625 - 15623 = 2:

YB=2Y_B = 2

Step 3, shared key from B's side. A computes K=YBXA mod qK = Y_B^{X_A} \bmod q:

K=24 mod 17=16K = 2^4 \bmod 17 = 16

Step 4, cross-check from A's side. B computes K=YAXB mod qK = Y_A^{X_B} \bmod q:

K=136 mod 17=(132)3 mod 17=1693 mod 17=163 mod 17=4096 mod 17=16K = 13^6 \bmod 17 = (13^2)^3 \bmod 17 = 169^3 \bmod 17 = 16^3 \bmod 17 = 4096 \bmod 17 = 16

17×240=408017 \times 240 = 4080, and 4096−4080=164096 - 4080 = 16. Both paths give the same value:

K=16K = 16

Reduce after each multiplication to keep the numbers small. 132=169=17×9+1613^2 = 169 = 17 \times 9 + 16, so 132≡16(mod17)13^2 \equiv 16 \pmod{17}. Then 136=(132)3≡163≡16(mod17)13^6 = (13^2)^3 \equiv 16^3 \equiv 16 \pmod{17}.

Problem 3: point addition on an elliptic curve (10 marks)Search on YouTube

Statement. An elliptic curve is defined over a finite field of integer modulus 23: y2=x3+3x+8y^2 = x^3 + 3x + 8, with p=23p = 23. Given P=(0,10)P = (0, 10) and Q=(7,2)Q = (7, 2), compute P+QP + Q.

Step 1, slope λ\lambda.

λ=yQ−yPxQ−xP mod p=2−107−0 mod 23=−87 mod 23\lambda = \frac{y_Q - y_P}{x_Q - x_P} \bmod p = \frac{2 - 10}{7 - 0} \bmod 23 = \frac{-8}{7} \bmod 23

Step 2, invert 7 modulo 23. Solve 7x≡1(mod23)7x \equiv 1 \pmod{23} by trial:

xx7x7x7x mod 237x \bmod 23
177
21414
32121
107070 − 69 = 1\mathbf{1}

So 7−1 mod 23=107^{-1} \bmod 23 = 10. Then:

λ=−8×10 mod 23=−80 mod 23\lambda = -8 \times 10 \bmod 23 = -80 \bmod 23

Add a multiple of the modulus: −80+92=12-80 + 92 = 12, so:

λ=12\lambda = 12

Step 3, xRx_R.

xR=(λ2−xP−xQ) mod p=(144−0−7) mod 23=137 mod 23=22x_R = (\lambda^2 - x_P - x_Q) \bmod p = (144 - 0 - 7) \bmod 23 = 137 \bmod 23 = 22

Because 137−115=22137 - 115 = 22.

Step 4, yRy_R.

yR=(λ(xP−xR)−yP) mod p=(12(0−22)−10) mod 23=(−264−10) mod 23y_R = \left(\lambda(x_P - x_R) - y_P\right) \bmod p = \left(12(0 - 22) - 10\right) \bmod 23 = (-264 - 10) \bmod 23

264=23×11+11264 = 23 \times 11 + 11, so −264≡−11≡12(mod23)-264 \equiv -11 \equiv 12 \pmod{23}, hence 12−10=212 - 10 = 2:

yR=2y_R = 2

Answer.

P+Q=(22,2)P + Q = (22, 2)

PP and QQ have different xx values here, so the addition formula applies. When P=QP = Q the line becomes a tangent and the doubling slope λ=(3xP2+a)/(2yP)\lambda = (3x_P^2 + a)/(2y_P) replaces the secant slope. When xP=xQx_P = x_Q and yQ=−yPy_Q = -y_P, the sum is the point at infinity OO.

Problem 4: membership on an elliptic curve (5 marks)Search on YouTube

Statement. Check whether the points (1,6)(1, 6) and (1,5)(1, 5) lie on the elliptic curve y2=x3+5x+7y^2 = x^3 + 5x + 7 over the finite field with modulus 23.

Test for (1,6)(1, 6). Left side and right side, both reduced by 23:

y2 mod 23=62 mod 23=36 mod 23=13y^2 \bmod 23 = 6^2 \bmod 23 = 36 \bmod 23 = 13

x3+5x+7 mod 23=(1+5+7) mod 23=13x^3 + 5x + 7 \bmod 23 = (1 + 5 + 7) \bmod 23 = 13

13=1313 = 13, so (1,6)(1, 6) is on the curve.

Test for (1,5)(1, 5).

y2 mod 23=52=25 mod 23=2y^2 \bmod 23 = 5^2 = 25 \bmod 23 = 2

The right side is again 1313, and 2≠132 \neq 13, so (1,5)(1, 5) is not on the curve.

Membership: square the yy, cube the xx, add axax plus bb, reduce both by pp. Equal, keep. Different, drop.

Error pattern to avoidSearch on YouTube

The four problems share one trap. Each division is a multiplication by a modular inverse. Each result must be in the range 0 to p−1p-1: −80 mod 23-80 \bmod 23 is 1212, 137 mod 23137 \bmod 23 is 2222, −274 mod 23-274 \bmod 23 is 22.

−80+4×23=12-80 + 4 \times 23 = 12. Do not leave a negative remainder. Add multiples of pp until the value is in [0,p−1][0, p-1].

Quick self-testSearch on YouTube

In the RSA problem, what are nn, φ(n)\varphi(n) and dd for p=13p = 13, q=17q = 17, e=35e = 35?

n=221n = 221, φ(n)=12×16=192\varphi(n) = 12 \times 16 = 192, and d=11d = 11, because 35×11=385=2×192+135 \times 11 = 385 = 2 \times 192 + 1.

In the Diffie-Hellman problem with q=17q = 17, α=5\alpha = 5, XA=4X_A = 4, XB=6X_B = 6, what are YAY_A, YBY_B and KK?

YA=54 mod 17=13Y_A = 5^4 \bmod 17 = 13, YB=56 mod 17=2Y_B = 5^6 \bmod 17 = 2, K=24 mod 17=16K = 2^4 \bmod 17 = 16, and the same 1616 follows from 136 mod 17=1613^6 \bmod 17 = 16.

How do you divide 5 by 7 in the field of modulus 23?

Find 7−1 mod 23=107^{-1} \bmod 23 = 10, because 70≡1(mod23)70 \equiv 1 \pmod{23}. Then 5⋅10=50≡7(mod23)5 \cdot 10 = 50 \equiv 7 \pmod{23}.

Give the three element formulas for P+QP + Q on y2=x3+ax+b mod py^2 = x^3 + ax + b \bmod p.

λ=(yQ−yP)/(xQ−xP) mod p\lambda = (y_Q - y_P)/(x_Q - x_P) \bmod p, then xR=(λ2−xP−xQ) mod px_R = (\lambda^2 - x_P - x_Q) \bmod p, then yR=(λ(xP−xR)−yP) mod py_R = (\lambda(x_P - x_R) - y_P) \bmod p, and the sum is (xR,yR)(x_R, y_R).

For P=(0,10)P = (0,10) and Q=(7,2)Q = (7,2) on y2=x3+3x+8y^2 = x^3 + 3x + 8 with p=23p = 23, what is P+QP + Q?

λ=−8⋅7−1=−80 mod 23=12\lambda = -8 \cdot 7^{-1} = -80 \bmod 23 = 12, xR=144−7=137 mod 23=22x_R = 144 - 7 = 137 \bmod 23 = 22, yR=12(0−22)−10=−274 mod 23=2y_R = 12(0-22) - 10 = -274 \bmod 23 = 2. The sum (22,2)(22, 2) follows.

Which of (1,6)(1,6) and (1,5)(1,5) lies on y2=x3+5x+7y^2 = x^3 + 5x + 7 mod 23, and why?

(1,6)(1, 6) lies on it: 36 mod 23=1336 \bmod 23 = 13 equals (1+5+7) mod 23=13(1 + 5 + 7) \bmod 23 = 13. (1,5)(1, 5) does not: 25 mod 23=225 \bmod 23 = 2 differs from 1313.

When must the doubling slope λ=(3xP2+a)/(2yP)\lambda = (3x_P^2 + a)/(2y_P) be used instead of the secant slope?

When P=QP = Q, that is point doubling. The secant λ=(yQ−yP)/(xQ−xP)\lambda = (y_Q - y_P)/(x_Q - x_P) divides by xQ−xPx_Q - x_P, which is zero there.

What is the slope formula for doubling, and how is it different from the addition slope?

Doubling uses λ=(3xP2+a)/(2yP) mod p\lambda = (3x_P^2 + a)/(2y_P) \bmod p, where aa is the xx-coefficient of the curve. Addition uses the difference of the yy values over the difference of the xx values.

  • RSA private keys: n=pqn = pq, φ(n)=(p−1)(q−1)\varphi(n) = (p-1)(q-1), d=e−1 mod φ(n)d = e^{-1} \bmod \varphi(n). With p=13p = 13, q=17q = 17, e=35e = 35: d=11d = 11.
  • Diffie-Hellman: publish Y=αX mod qY = \alpha^X \bmod q, then K=Yotherown mod qK = Y_{other}^{own} \bmod q. With q=17q = 17, α=5\alpha = 5, XA=4X_A = 4, XB=6X_B = 6: YA=13Y_A = 13, YB=2Y_B = 2, K=16K = 16.
  • A fraction modulo pp needs a modular inverse: 7−1 mod 23=107^{-1} \bmod 23 = 10. Then λ=−80 mod 23=12\lambda = -80 \bmod 23 = 12.
  • Point addition: λ\lambda, then xR=λ2−xP−xQx_R = \lambda^2 - x_P - x_Q, then yR=λ(xP−xR)−yPy_R = \lambda(x_P - x_R) - y_P, all reduced by pp. Here P+Q=(22,2)P + Q = (22, 2).
  • Membership: compare y2 mod py^2 \bmod p with (x3+ax+b) mod p(x^3 + ax + b) \bmod p. (1,6)(1, 6) passes, (1,5)(1, 5) fails.