# Okamoto–Uchiyama cryptosystem

The Okamoto–Uchiyama cryptosystem is a public key cryptosystem proposed in 1998 by Tatsuaki Okamoto and Shigenori Uchiyama. The system works in the multiplicative group of integers modulo n, $(\mathbb {Z} /n\mathbb {Z} )^{*}$, where n is of the form p$^2$q and p and q are large primes.

## Background

Let $p$ be an odd prime. Define $\Gamma =\{x\in (\mathbb {Z} /p^{2}\mathbb {Z} )^{*}|x\equiv 1{\bmod {p}}\}$. $\Gamma$ is a subgroup of $(\mathbb {Z} /p^{2}\mathbb {Z} )^{*}$ with $|\Gamma |=p$ (the elements of $\Gamma$ are $1,1+p,1+2p\dots 1+(p-1)p$).
Define $L:\Gamma \to \mathbb {Z} /p\mathbb {Z}$ by $L(x)={\frac {x-1}{p}}$
$L$ is a homomorphism between $\Gamma$ and the additive group $\mathbb {Z} /p\mathbb {Z}$: that is, $L(ab)=L(a)+L(b){\bmod {p}}$. Since $L$ is bijective, it is an isomorphism.
One can now show the following as a corollary:
Let $x\in \Gamma$ such that $L(x)\neq 0{\bmod {p}}$ and $y=x^{m}{\bmod {p}}^{2}$ for $0\leq m<p$. Then
    $m={\frac {L(y)}{L(x)}}={\frac {y-1}{x-1}}{\bmod {p}}$
The corollary is a direct consequence of $L(x^{m})=m\cdot L(x)$.

## Operation

Like many public key cryptosystems, this scheme works in the group $(\mathbb {Z} /n\mathbb {Z} )^{*}$. This scheme is homomorphic and hence malleable.

### Key generation

A public/private key pair is generated as follows:
* Generate two large primes $p$ and $q$.
* Compute $n=p^{2}q$.
* Choose a random integer $g\in \{2\dots n-1\}$ such that $g^{p-1}\not \equiv 1\mod p^{2}$.
* Compute $h=g^{n}{\bmod {n}}$.
The public key is then $(n,g,h)$ and the private key is $(p,q)$.

### Encryption

A message $m<p$ can be encrypted with the public key $(n,g,h)$ as follows.
* Choose a random integer $r\in \{1\dots n-1\}$.
* Compute $c=g^{m}h^{r}{\bmod {n}}$.
The value $c$ is the encryption of $m$.

### Decryption

An encrypted message $c$ can be decrypted with the private key $(p,q)$ as follows.
* Compute $a=L(c^{p-1}{\bmod {p^{2}}})$.
* Compute $b=L(g^{p-1}{\bmod {p^{2}}})$. $a$ and $b$ will be integers.
* Using the Extended Euclidean Algorithm, compute the inverse of $b$ modulo $p$:
    $b'=b^{-1}{\bmod {p}}$.
* Compute $m=ab'{\bmod {p}}$.
The value $m$ is the decryption of $c$.

## Example

Let $p=3$ and $q=5$. Then $n=3^{2}\cdot 5=45$. Select $g=22$. Then $h=22^{45}{\bmod {4}}5=37$.
Now to encrypt a message $m=2$, we pick a random $r=13$ and compute $c=g^{m}h^{r}{\bmod {n}}=22^{2}37^{13}{\bmod {4}}5=43$.
To decrypt the message 43, we compute
    $a={\frac {(43^{2}{\bmod {3}}^{2})-1}{3}}=1$.
    $b={\frac {(22^{2}{\bmod {3}}^{2})-1}{3}}=2$.
    $b'=2^{-1}{\bmod {3}}=2$.
And finally $m=ab'=2$.

## Proof of correctness

We wish to prove that the value computed in the last decryption step, $ab'{\bmod {p}}$, is equal to the original message $m$. We have
    $(g^{m}h^{r})^{p-1}\equiv (g^{m}g^{nr})^{p-1}\equiv (g^{p-1})^{m}g^{p(p-1)rpq}\equiv (g^{p-1})^{m}\mod p^{2}$
So to recover $m$ we need to take the discrete logarithm with base $g^{p-1}$. This can be done by applying $L$, as follows.
By Fermat's little theorem, $g^{p-1}\equiv 1{\bmod {p}}$. Since $g^{p-1}\not \equiv 1{\bmod {p}}^{2}$ one can write $g^{p-1}=1+pr$ with $0<r<p$. Then $L(g^{p-1})\not \equiv 0{\bmod {p}}$ and the corollary from earlier applies: $m={\frac {L((g^{p-1})^{m})}{L(g^{p-1})}}{\bmod {p}}$.

## Security

Inverting the encryption function can be shown to be as hard as factoring n, meaning that if an adversary could recover the entire message from the encryption of the message they would be able to factor n. The semantic security (meaning adversaries cannot recover any information about the message from the encryption) rests on the p-subgroup assumption, which assumes that it is difficult to determine whether an element x in $(\mathbb {Z} /n\mathbb {Z} )^{*}$ is in the subgroup of order p. This is very similar to the quadratic residuosity problem and the higher residuosity problem.