Post · 8 min read· pp. 635–639

CS276 Lecture 25: Quadratic Residuosity and Zero Knowledge

Scribed by Alexandra Constantin

Summary

Today we show that the graph isomorphism protocol we defined last time is indeed a zero-knowledge protocol. Then we discuss the quadratic residuosity problem modulo a composite, and define a protocol for proving quadratic residuosity. (We shall prove that the protocol is zero knowledge next time.)

1. The Graph Isomorphism Protocol

Last time we considered the following protocol for the graph isomorphism problem.

  • Verifier’s input: two graphs G1=(V,E1){G_1=(V,E_1)}, G2=(V,E2){G_2= (V,E_2)};
  • Prover’s input: G1,G2{G_1,G_2} and permutation π∗{\pi^*} such that π∗(G1)=G2{\pi^*(G_1) = G_2}; the prover wants to convince the verifier that the graphs are isomorphic
  • The prover picks a random permutation πR:V→V{\pi_R:V\rightarrow V} and sends the graph G:=πR(G2){G:= \pi_R(G_2)}
  • The verifier picks at random b∈{1,2}{b\in \{1,2\}} and sends b{b} to the prover
  • The prover sends back πR{\pi_R} if b=2{b=2}, and πR(π∗(⋅)){\pi_R(\pi^*(\cdot))} otherwise
  • The verifier cheks that the permutation π{\pi} received at the previous round is such that π(Gb)=G{\pi(G_b) = G}, and accepts if so.

In order to prove that this protocol is zero knowledge, we have to show the existence of an efficient simulator.

Theorem 1 (Honest-Verifier Zero Knowledge) There exists an efficient simulator algorithm S∗{S^*} such that, for every two isomorphic graphs G1,G2{G_1,G_2}, and for every isomorphism π{\pi} between them, the distributions of transcripts

*

P(π,G1,G2)↔Ver(G1,G2)     (1)\displaystyle P(\pi,G_1,G_2) \leftrightarrow Ver(G_1,G_2) \ \ \ \ \ (1)

and

S(G1,G2)     (2)\displaystyle S (G_1,G_2) \ \ \ \ \ (2)
*

are identical, where P{P} is the prover algorithm and Ver{Ver} is the verifier algorithm in the above protocol.

Proof:

Algorithm S{S} on input G1,G2{G_1, G_2} is described as follows:

  • Input: graphs G1{G_1}, G2{G_2}
  • pick uniformly at random b∈{1,2}{b\in \{1,2\}}, πR:V→V{\pi_R : V \rightarrow V}
  • output the transcript:
      1. prover sends G=πR(Gb){G=\pi_R(G_b)}
      1. verifier sends b{b}
      1. prover sends πR{\pi_R}

At the first step, in the original protocol we have a random permutation of G2{G_2}, while in the simulation we have either a random permutation of G1{G_1} or a random permutation of G2{G_2}; a random permutation of G1{G_1}, however, is distributed as πR(π∗(G2)){\pi_R (\pi^*(G_2))}, where πR{\pi_R} is uniformly distributed and π∗{\pi^*} is fixed. This is the same as a random permutation of G2{G_2}, because composing a fixed permutation with a random permutation produces a random permutation.

The second step, both in the simulation and in the original protocol, is a random bit b{b}, selected independently of the graph G{G} sent in the first round. This is true in the simulation too, because the distribution of G:=πR(Gb){G := \pi_R(G_b)} conditioned on b=1{b=1} is, by the above reasoning, identical to the distribution of G{G} conditioned on b=0{b=0}.

Finally, the third step is, both in the protocol and in the simulation, a distribution uniformly distributed among those establishing an isomorphism between G{G} and Gb{G_b}. □\Box

To establish that the protocol satisfies the general zero knowledge protocol, we need to be able to simulate cheating verifiers as well.

Theorem 2 (General Zero Knowledge) For every verifier algorithm V∗{V^*} of complexity t{t} there is a simulator algorithm S∗{S^*} of expected complexity ≤2t+O(n2){\leq 2t + O(n^2)} such that, for every two isomorphic graphs G1,G2{G_1,G_2}, and for every isomorphism π{\pi} between them, the distributions of transcripts

*

P(π,G1,G2)↔V∗(G1,G2)     (3)\displaystyle P(\pi,G_1,G_2) \leftrightarrow V^*(G_1,G_2) \ \ \ \ \ (3)

and

S∗(G1,G2)     (4)\displaystyle S^* (G_1,G_2) \ \ \ \ \ (4)
*

are identical.

Proof:

Algorithm S∗{S^*} on input G1,G2{G_1, G_2} is described as follows:

Input G1{G_1}, G2{G_2}

    1. pick uniformly at random b∈{1,2}{b\in \{1,2\}}, πR:V→V{\pi_R : V \rightarrow V}
  • G:=πR(Gb){G := \pi_R(G_b)}
  • let b′{b'} be the second-round message of V∗{V^*} given input G1{G_1}, G2{G_2}, first message G{G}
  • if b≠b′{b\neq b'}, abort the simulation and go to 1.
  • else output the transcript
    • prover sends G{G}
    • verifier sends b{b}
    • prover sends πR{\pi_R}

As in the proof of Theorem 1, G{G} has the same distribution in the protocol and in the simulation.

The important observation is that b′{b'} depends only on G{G} and on the input graphs, and hence is statistically independent of b{b}. Hence, P[b=b′]=12{\mathop{\mathbb P} [b = b'] = \frac{1}{2}} and so, on average, we only need two attempts to generate a transcript (taking overall average time at most 2t+O(n2){2t + O(n^2)}). Finally, conditioned on outputting a transcript, G{G} is distributed equally in the protocol and in the simulation, b{b} is the answer of V∗{V^*}, and πR{\pi_R} at the last round is uniformly distributed among permutations establishing an isomorphism between G{G} and Gb{G_b}. □\Box

2. The Quadratic Residuosity Problem

We review some basic facts about quadratic residuosity modulo a composite.

If N=p⋅q{N=p\cdot q} is the product of two distinct odd primes, and ZN∗{{\mathbb Z}^*_N} is the set of all numbers in {1,…,N−1}{\{1,\ldots,N-1\}} having no common factor with N{N}, then we have the following easy consequences of the Chinese remainder theorem:

  • ZN∗{{\mathbb Z}^*_N} has (p−1)⋅(q−1){(p-1) \cdot (q-1)} elements, and is a group with respect to multiplication;

    Proof:

    Consider the mapping x→(x mod p,x mod q){x \rightarrow (x \bmod p, x \bmod q)}; it is a bijection because of the Chinese remainder theorem. (We will abuse notation and write x=(x mod p,x mod q){x= (x \bmod p, x\bmod q)}.) The elements of ZN∗{{\mathbb Z}^*_N} are precisely those which are mapped into pairs (a,b){(a,b)} such that a≠0{a\neq 0} and b≠0{b\neq 0}, so there are precisely (p−1)⋅(q−1){(p-1) \cdot (q-1)} elements in ZN∗{{\mathbb Z}^*_N}.

    If x=(xp,xq){x = (x_p, x_q)}, y=(yp,yq){y = (y_p, y_q)}, and z=(xp×yp mod p,xq×yq mod q){z = (x_p \times y_p \bmod p, x_q \times y_q \bmod q)}, then z=x×y mod N{z = x \times y \bmod N}; note that if x,y∈ZN∗{x,y\in {\mathbb Z}^*_N} then xp,yp,xq,yq{x_p,y_p,x_q,y_q} are all non-zero, and so z mod p{z \bmod p} and z mod q{z\bmod q} are both non-zero and z∈ZN∗{z\in {\mathbb Z}^*_N}.

    If we consider any x∈ZN∗{x\in {\mathbb Z}^*_N} and we denote x′=(xp−1 mod p,xq−1 mod q){x' = (x_p ^{-1} \bmod p, x_q ^{-1} \bmod q)}, then x⋅x′ mod N=(xpxp−1,xqxq−1)=(1,1)=1{x\cdot x' \bmod N = (x_p x_p^{-1}, x_q x_q^{-1} ) = (1,1) =1}.

    Therefore, ZN∗{{\mathbb Z}^*_N} is a group with respect to multiplication. □\Box

  • If r=x2 mod N{r = x^2 \bmod N} is a quadratic residue, and is an element of ZN∗{{\mathbb Z}^*_N}, then it has exactly 4 square roots in ZN∗{{\mathbb Z}^*_N}

    Proof:

    If r=x2 mod N{r = x^2 \bmod N} is a quadratic residue, and is an element of ZN∗{{\mathbb Z}^*_N}, then:

    r≡x2 mod p{r \equiv x^2 \bmod p}

    r≡x2 mod q{r \equiv x^2 \bmod q}.

    Define xp=x mod p{x_p = x \bmod p} and xq=x mod q{x_q = x \bmod q} and consider the following four numbers:

    x=x1=(xp,xq){x = x_1 = (x_p, x_q)}

    x2=(−xp,xq){x_2 = (-x_p, x_q)}

    x3=(xp,−xq){x_3 = (x_p, -x_q)}

    x4=(−xp,−xq){x_4 = (-x_p, -x_q)}.

    x2≡x12≡x22≡x32≡x42≡r mod N{x^2 \equiv x_1^2 \equiv x_2^2 \equiv x_3^2 \equiv x_4^2 \equiv r \bmod N}.

    Therefore, x1,x2,x3,x4{x_1, x_2, x_3, x_4} are distinct square roots of r{r}, so r{r} has 4 square roots.

    □\Box

  • Precisely (p−1)⋅(q−1)/4{(p-1)\cdot (q-1) / 4} elements of ZN∗{{\mathbb Z}^*_N} are quadratic residues

    Proof:

    According to the previous results, ZN∗{{\mathbb Z}^*_N} has (p−1)⋅(q−1){(p-1) \cdot (q-1)} elements, and each quadratic residue in ZN∗{{\mathbb Z}^*_N} has exactly 4 square roots. Therefore, (p−1)⋅(q−1)/4{(p-1)\cdot (q-1) / 4} elements of ZN∗{{\mathbb Z}^*_N} are quadratic residues. □\Box

  • Knowing the factorization of N{N}, there is an efficient algorithm to check if a given y∈ZN∗{y\in {\mathbb Z}^*_N} is a quadratic residue and, if so, to find a square root.

It is, however, believed to be hard to find square roots and to check residuosity modulo N{N} if the factorization of N{N} is not known.

Indeed, we can show that from any algorithm that is able to find square roots efficiently mod N{N} we can derive an algorithm that factors N{N} efficiently.

Theorem 3 If there exists an algorithm A{A} of running time t{t} that finds quadratic residues modulo N=p⋅q{N=p\cdot q} with probability ≥ϵ{\geq \epsilon}, then there exists an algorithm A∗{A^*} of running time t+O(log⁡N)O(1){t + O(\log N)^{O(1)}} that factors N{N} with probability ≥ϵ2{\geq \frac{\epsilon}{2}}.

Proof: Suppose that, for a quadratic residue r∈ZN∗{r\in {\mathbb Z}^*_N}, we can find two square roots x,y{x,y} such that x≠±y(modN){x\neq \pm y \pmod N}. Then x2≡y2≡r mod N{x^2 \equiv y^2 \equiv r \bmod N}, then x2−y2≡0 mod N{x^2-y^2 \equiv 0 \bmod N}. Therefore, (x−y)(x+y)≡0 mod N{(x-y)(x+y) \equiv 0 \bmod N}. So either (x−y){(x-y)} or (x+y){(x+y)} contains p{p} as a factor, the other contains q{q} as a factor.

The algorithm A∗{A^*} is described as follows:

Given N=p×q{N = p \times q}

  • pick x∈{0…N−1}{x \in \{0 \dots N-1\}}
  • if x{x} has common factors with N{N}, return gcd⁡(N,x){\gcd (N,x)}
  • if x∈ZN∗{x \in {\mathbb Z}_N^*}
    • r:=x2{r := x^2} mod N{N}
    • y:=A(N,r){y := A(N, r)}
    • if y≠±x{y \neq \pm x } mod N{N} return gcd(N,x+y){gcd(N, x+y)}

WIth probability ϵ{\epsilon} over the choice of r{r}, the algorithm finds a square root of r{r}. Now the behavior of the algorithm is independent of how we selected r{r}, that is which of the four square roots of r{r} we selected as our x{x}. Hence, there is probability 1/2{1/2} that, conditioned on the algorithm finding a square root of r{r}, the square root y{y} satisfies x≠±y(modN){x\neq \pm y \pmod N}, where x{x} is the element we selected to generate r{r}. □\Box

3. The Quadratic Residuosity Protocol

We consider the following protocol for proving quadratic residuosity.

  • Verifier’s input: an integer N{N} (product of two unknown odd primes) and a integer r∈ZN∗{r \in {\mathbb Z}^*_N};
  • Prover’s input: N,r{N,r} and a square root x∈ZN∗{x\in Z^*_N} such that x2 mod N=r{x^2 \bmod N = r}.
  • The prover picks a random y∈ZN∗{y \in Z_N^*} and sends a:=y2 mod N{a := y^2 \bmod N} to the verifier
  • The verifier picks at random b∈{0,1}{b\in \{0,1\}} and sends b{b} to the prover
  • The prover sends back c:=y{c:= y} if b=0{b=0} or c:=y⋅x mod N{c:= y\cdot x \bmod N} if b=1{b=1}
  • The verifier cheks that c2 mod N=a{c^2 \bmod N = a} if b=0{b=0} or that c2≡a⋅r(modN){c^2 \equiv a \cdot r \pmod N} if b=1{b=1}, and accepts if so.

We show that:

  • If r{r} is a quadratic residue, the prover is given a square root x{x}, and the parties follow the protocol, then the verifier accepts with probability 1;
  • If r{r} is not a quadratic residue, then for every cheating prover strategy P∗{P^*}, the verifier rejects with probability ≥1/2{\geq 1/2}.

Proof:

Suppose r{r} is not a quadratic residue. Then it is not possible that both a{a} and a×r{a \times r} are quadratic residues. If a=y2 mod N{a = y^2 \bmod N} and a×r=w2 mod N{a \times r = w^2 \bmod N}, then r=w2(y−1)2 mod N{r = w^2(y^{-1})^2 \bmod N}, meaning that r{r} is also a perfect square.

With probability 1/2{1/2}, the verifier rejects no matter what the Prover’s strategy is.

□\Box

Next time we shall prove that the protocol is zero knowledge.