Advanced Topics in Public-Key Cryptography

Saravanan Vijayakumaran

Department of Electrical Engineering, IIT Bombay

November 1, 2024

Quadratic Residues Modulo a Prime

Quadratic Residues

  • In a group G, an element y \in G is called a quadratic residue if there exists an x \in G with x^2 = y

    • Such an x is called a square root of y
  • In an abelian group, the set of quadratic residues form a group

Quadratic Residues Modulo a Prime

  • Proposition: Let p > 2 be prime. Every quadratic residue in \mathbb{Z}_p^* has exactly two square roots

  • The integers 1,2,\ldots, \frac{p-1}{2} have distinct squares

    • Let S be the set of these squares
  • Since x^2 = (p-x)^2 \bmod p, the squares of \left\{\frac{p+1}{2},\frac{p+3}{2},\ldots, p-1\right\} already appear in S

  • Lemma: Exactly half the elements of \mathbb{Z}_p^* are quadratic residues

Jacobi Symbol Modulo a Prime

  • Let \mathcal{QR}_p denote the set of quadratic residues modulo p
  • Let \mathcal{QNR}_p denote the set of quadratic non-residues modulo p
  • For prime p>2 and x \in \mathbb{Z}_p^*, the Jacobi symbol of x modulo p is given by \mathcal{J}_p(x) = \begin{cases} +1 & \text{ if } x \in \mathcal{QR}_p, \\ -1 & \text{ if } x \in \mathcal{QNR}_p. \end{cases}

Computing the Jacobi Symbol Modulo a Prime

  • Proposition: Let p > 2 be a prime. Then \mathcal{J}_p(x) = x^{\frac{p-1}{2}} \bmod p

  • Core idea of proof

    • \mathbb{Z}_p^* is cyclic \implies There exists a g \in \mathbb{Z}_p^* such that \mathbb{Z}_p^* = \{g^0, g^1, \ldots,g^{\frac{p-1}{2}-1},g^{\frac{p-1}{2}},g^{\frac{p-1}{2}+1},\ldots,g^{p-2}\}

    • \mathcal{QR}_p is exactly those g^i where i \in \{0,1,\ldots,p-2\} is an even integer

Multiplicative Properties

  • Proposition: Let p > 2 be a prime, and x,y \in \mathbb{Z}_p^*. Then \mathcal{J}_p(xy) = \mathcal{J}_p(x) \cdot\mathcal{J}_p(y).

  • Corollary: Let p > 2 be a prime, x, x' \in \mathcal{QR}_p and y, y' \in \mathcal{QNR}_p. Then

    1. [xx' \bmod p] \in \mathcal{QR}_p
    2. [yy' \bmod p] \in \mathcal{QR}_p
    3. [xy \bmod p] \in \mathcal{QNR}_p

Quadratic Residues Modulo a Composite

Quadratic Residues Modulo a Composite

  • We consider quadratic residues in \mathbb{Z}_N^*, where N = pq for distinct odd primes p,q

  • From the CRT, we have \mathbb{Z}_N^* \simeq \mathbb{Z}_p^* \times \mathbb{Z}_q^*

    • Let y \leftrightarrow (y_p, y_q) denote the correspondence where y_p = [y \bmod p] and y_q = [y \bmod q]
  • Proposition: Let y \in \mathbb{Z}_N^*. Then y \in \mathcal{QR}_N \iff y_p \in \mathcal{QR}_p and y_q \in \mathcal{QR}_q

  • Exactly 1/4 of the elements of \mathbb{Z}_N^* are quadratic residues

Square Roots Modulo a Composite

  • Each y \in \mathcal{QR}_N has exactly four square roots
  • Let y \leftrightarrow (y_p, y_q) and let x_p, x_q be square roots of y_p and y_q modulo p and q, respectively
  • The four square roots of y are given by (x_p, x_q),\ (-x_p, x_q),\ (x_p, -x_q),\ (-x_p, -x_q)
  • These are distinct as long as p and q are odd primes
  • Example: Consider 4 \in \mathbb{Z}_{15}^*

Jacobi Symbol Modulo a Composite

  • Let N = pq where p,q are distinct, odd primes

  • For x \in \mathbb{Z}_N^*, we define \mathcal{J}_N(x) = \mathcal{J}_p([x \bmod p]) \cdot \mathcal{J}_q([x \bmod q])

  • Lemma: If x is a quadratic residue modulo N, then \mathcal{J}_N(x) = +1

    • But the converse is not true
  • \mathcal{J}_N(x) = +1 even when \mathcal{J}_p(x) = \mathcal{J}_q(x) = -1

Composition of \mathbb{Z}_N^*

  • Proposition: Let N=pq with p,q distinct, odd primes. Then

    1. Exactly half the elements of \mathbb{Z}_N^* are in \mathcal{J}_N^{+1}
    2. \mathcal{QR}_N is contained in \mathcal{J}_N^{+1}
    3. Exactly half the elements of \mathcal{J}_N^{+1} are in \mathcal{QR}_N (the other half are in \mathcal{QNR}_N^{+1})

Multiplicative Properties

  • Proposition: Let N=pq be a product of distinct, odd primes, and x,y \in \mathbb{Z}_N^*. Then \mathcal{J}_N(xy) = \mathcal{J}_N(x) \cdot\mathcal{J}_N(y).

  • Corollary: If x, x' \in \mathcal{QR}_N and y, y' \in \mathcal{QNR}_N^{+1}. Then

    1. [xx' \bmod N] \in \mathcal{QR}_N
    2. [yy' \bmod N] \in \mathcal{QR}_N
    3. [xy \bmod N] \in \mathcal{QNR}_N^{+1}

Deciding Quadratic Residuosity

  • For a prime p > 2, checking if x is a quadratic residue is easy

  • When the factorization of N=pq is known, checking if x is a quadratic residue modulo N is also easy

  • When the factorization of N is unknown, there is no known polynomial-time algorithm for deciding if x is a quadratic residue modulo N or not

Partial Quadratic Residuosity Test

  • \mathcal{J}_N(x) can be calculated in polynomial-time even when N has unknown factorization

  • If \mathcal{J}_N(x) = -1, then x is not a quadratic residue

  • But if \mathcal{J}_N(x) = +1, then there is no known polynomial-time algorithm for deciding quadratic residuosity of x

Computing the Jacobi symbol

  • Let m,n be odd, positive integers, and let a,b \in \mathbb{Z}. Then

    • \mathcal{J}_n(ab) = \mathcal{J}_n(a) \mathcal{J}_n(b)
    • If a = b \bmod n, then \mathcal{J}_n(a) = \mathcal{J}_n(b)
    • \mathcal{J}_n(2) = (-1)^{\frac{n^2-1}{8}}
    • \mathcal{J}_n(m) = (-1)^{\frac{m-1}{2}\frac{n-1}{2}}\mathcal{J}_m(n)
  • See chapter 12 of Shoup

The Quadratic Residuosity Assumption

  • Let \textsf{GenModulus} be a PPT algorithm that, on input 1^n, outputs (N,p,q) where N = pq, and p and q are n-bit primes except with probability negligible in n.
  • Definition: We say deciding quadratic residuosity is hard relative to \textsf{GenModulus} if for all PPT algorithms D there exists a negligible function \textsf{negl} such that \bigg| \Pr\left[ D(N, \textsf{qr}) = 1\right] - \Pr\left[ D(N, \textsf{qnr}) = 1\right]\bigg| \\ \le \textsf{negl}(n) where \textsf{qr} is chosen uniformly from \mathcal{QR}_N and \textsf{qnr} is chosen uniformly from \mathcal{QNR}^{+1}_N

The Goldwasser-Micali Encryption Scheme

  • Proposed in 1982
  • First scheme to be proven CPA-secure

The Goldwasser-Micali Encryption Scheme

  • To encrypt a 0 bit, send a uniform quadratic residue
  • To encrypt a 1 bit, send a uniform quadratic non-residue with Jacobi symbol +1
  • The receiver can decrypt the ciphertext by using the factorization of N

Choosing a uniform quadratic residue

  • Pick a uniform x \in \mathbb{Z}_N^*
  • Set y = x^2 \bmod N
  • y \in \mathcal{QR}_N, but is it uniformly distributed in the set?
  • Let \hat{y} \in \mathcal{QR}_N with square roots \pm \hat{x}, \pm \hat{x}'
  • Then \begin{align*} \Pr[y = \hat{y}] & =\Pr[x \text{ is a square root of }\hat{y}] \\ & = \Pr[ x \in \{\pm \hat{x}, \pm \hat{x}'\}]\\ & = \frac{4}{|\mathbb{Z}_N^*|} = \frac{1}{|\mathcal{QR}_N|} \end{align*}

Choosing uniformly from \mathcal{QNR}_N^{+1}

  • There is no known method for directly choosing uniformly from \mathcal{QNR}_N^{+1} if the factorization of N is unknown

  • But it is possible if the receiver can help

  • The receiver picks a uniform z \in \mathcal{QNR}_N^{+1} and includes it as part of the public key

  • To generate a uniform element y from \mathcal{QNR}_N^{+1}, the sender

    • Picks a uniform x \in \mathbb{Z}_N^*
    • Sets y = z \cdot x^2 \bmod N

The Goldwasser-Micali Encryption Scheme

  • The public key is \langle N, z \rangle where z \in \mathcal{QNR}_N^{+1}

  • The private key is \langle p, q \rangle where N=pq

  • To send a message m = m_1m_2 \cdots m_l \in \{0,1\}^l

    • Pick l integers x_1, x_2, \ldots, x_l uniformly from \mathbb{Z}_N^*
    • Send c_i = z^{m_i} x_i^2 for i=1,2,\ldots,l
  • Receiver decrypts message bits as \hat{m}_i as 0 or 1 depending on whether \left( c_i^{\frac{p-1}{2}} \bmod p, c_i^{\frac{q-1}{2}} \bmod q\right) equals (1,1) or (-1,-1)

GM Scheme is CPA-Secure

  • Theorem: If the quadratic residuosity problem is hard relative to \textsf{GenModulus}, then the Goldwasser-Micali encryption scheme is CPA-secure.

Coin Flipping over Telephone

The Setting

  • Alice and Bob are getting a divorce in the 1980s
  • They live in different cities
  • They want to flip a coin to decide who gets their cat
  • They want to use a telephone to do the coin flip
  • They don’t trust each other to honestly report the result of the coin flip

The Protocol

  • Alice picks two large primes p,q such that p = q = 3 \bmod 4
  • She sends Bob N = pq
  • Bob picks a random positive integer x < N and sends the integer a to Alice where a = x^2 \bmod N
  • Alice finds four solutions of x^2 = a \bmod N
  • She picks one of these four at random and sends it to Bob

The Solutions of x^2 = a \bmod N

  • Bob started with one solution of x^2 = a \bmod N
  • This x corresponds to (x_p, x_q) \in \mathbb{Z}_p^* \times \mathbb{Z}_q^*
  • Alice has four solutions in \mathbb{Z}_N^* corresponding to (\pm x_p, \pm x_q) \in \mathbb{Z}_p^* \times \mathbb{Z}_q^*
  • (-x_p, -x_q) corresponds to -x in \mathbb{Z}_N^*
  • Let y \in \mathbb{Z}_N^* correspond to (-x_p, x_q). Then N-y corresponds to (x_p,-x_q)

Bob Can Sometimes Factor N

  • Alice does not know which square root of a Bob has
  • Suppose Alice sends Bob y or N-y
  • These correspond to (-x_p,x_q) and (x_p, -x_q)
  • The solution x Bob has corresponds to (x_p, x_q)
  • p divides x+y and q divides x+N-y
  • Bob can factor N if Alice sends y or N-y
  • Bob cannot factor N if Alice sends x or N-x

The Fair Coin Flip

  • Bob wins the coin flip if he can factor N
  • Alice wins if Bob cannot factor N
  • Bob has an equal chance of doing either

Why p=q=3 \bmod 4?

  • Alice has to compute the four square roots of a modulo N
  • If p=3 \bmod 4, then p = 4k+3 for some k \in \mathbb{N}
  • Then \frac{p+1}{4} is an integer
  • Claim: a^{\frac{p+1}{4}} is a square root of a modulo p
  • \left( a^{\frac{p+1}{4}}\right)^2 \bmod p = a^{\frac{p+1}{2}} \bmod p= a^{\frac{p-1}{2}} \cdot a \bmod p = a \bmod p
  • Similarly, a^{\frac{q+1}{4}} is a square root of a modulo q
  • Alice can calculate \left( a^{\frac{p+1}{4}} \bmod p, a^{\frac{q+1}{4}} \bmod q\right) and use CRT to get the square root of a modulo N

Further reading

  • Section 15.4 of Katz & Lindell
  • Sections 12.1, 12.2 of Shoup
  • Section 11.1 of Elementary Number Theory by Kenneth H. Rosen