Dominik Farhan

RSA

an asymmetric cipher

primes p,qp, q n=pqn = pq

now the encryption is as follows, let there be a message xx. We have y=xemodny = x^e \mod{n}

The decryption: x=yd=(xe)d=xed=xx = y^d =(x^{e})^d = x^{ed} = x

It is not that obvious why e,φ(n)e, \varphi(n) are coprime. So let’s think about it. We know that xφ(n)=1modnx^{\varphi(n)} = 1 \mod{n} for xx and nn coprime, therefore xφ(n)+1=xmodnx^{\varphi(n) + 1} = x \mod{n} we want xed=x=xkφ(n)+1x^{ed} = x = x^{k\varphi(n) + 1} edkφ(n)=1ed - k\varphi(n)= 1 Assume that e,φ(n)e, \varphi(n) aren’t coprime, the left side would be divisible by some dd which implies that 1d1 | d, which is obviously wrong.

The decryption as shown with φ\varphi wouldn’t work for xx not coprime to nn and there is a way to show that the decryption is still possible through CTR but in such case, there are other problems. Mainly because nn is publicly known, we can just compute gcd(n,y)gcd(n, y)

Getting faster

Choosing small e. (3,17,216+13,17, 2^{16}+1) — too small e is bad.

Decryption using CRT, smaller numbers faster arithmetic. How to do it is described here

Important properties

Commutativity

E1(E2(x))=E2(E1(x))E_1(E_2(x)) = E_2(E_1(x)) it is not safe to interchange keys although possible.

Homomorphism (kind of)

Used in chosen-ciphertext attack E(xy)=E(x)E(y)E(xy) = E(x)E(y) allows for blind signatures.

What if there is some creature who loves to give signatures? You can make it sign whatever you want!

Here is how: you obviously know (d,n)(d, n) that is public. You create the following xzdx z^d where zdz^d is a blinding factor. And after the signature is finished xezx^e z and because zz was chosen so that it has a multiplicative inversemodn\mod n it is easy.

Attacks

Small e

x<n1/ex < n^{1/e} Simply compute the eeth root in Z\mathbb{Z}.

Known φ(n)\varphi(n)

We get the following system which we can solve n=pqn = pq φ(n)=(p1)(q1)\varphi(n) = (p-1)(q-1)

Wiener

when d<13n1/4d < \frac{1}{3}n^{1/4} it is possible to calculate it from ee with the continued fraction method.

How it works? This is interesting but not that simple. But the idea is quite easy. If attacker got φ(n),e\varphi(n), e we lost. Attacker knows eN\frac{e}{N} and with this he can approximate eφ(n)\frac{e}{\varphi(n)} so that when dd is small enough he can recover it.

Randomized algorithms for calculating φ(n)\varphi(n)

When d,ed, e are both known, it is possible to calculate φ(n)\varphi(n).

Meet in the middle

How to do meet in the middle?, board from the 10th lecture, by Martin Mareš, http://mj.ucw.cz/vyuka/2021/kry/

Similar messages

Given c=me,c=(m+δ)ec = m^e, c' = (m+\delta)^e and not that large ee we can recover mm. Note that mm is a root of the following polynomials. p(x)=mec,q(x)=(m+δ)ecp(x) = m^e - c, q(x) = (m+\delta)^e - c'

There is a good chance that gcd(p,q)gcd(p,q) is linear. If that is the case we won.

Partially known messages

All we need to know is to guess unknown bits. Untrivial.

Similar p,qp, q

Let q=p+2dq = p + 2d then n=p2+2pdn = p^2 + 2pd

This is similar to (p+d)2=p2+2pd+d2(p+d)^2 = p^2 + 2pd + d^2 dd is guessable.

Chosen-ciphertext attack

Suppose the attacker wants to know the message mem^e but can’t decrypt it. Sometimes the victim will decrypt messages which look unsuspicious. The attacker can then ask the victim to decrypt merem^{e}r^e if she chose rZnr \in \mathbb{Z}^*_n she can then recover mm like m=mrr1m = m r r^{-1}

Chosen-plaintext attack

RSA without padding is not semantically secure. It is attackable by the chosen-plaintext attack, but this is impractical.

The same message but different moduly

We can use CRT. For e=3e = 3 for example x3=a1modn1x^3 =a_1 \mod{n_1} x3=a2modn2x^3 =a_2 \mod{n_2} x3=a3modn3x^3 =a_3 \mod{n_3} This is solvable and we can obtain x3Znx^3 \in \mathbb{Z_n} finding the root is then easy.

Miscalculation

When using CRT it is possible to leak one of the primes if encrypting the same message multiple times. WTLOG when there is a mistake in calculating remaindermodp\text{remainder} \mod p, it gives out the multiple of qq from the following gcd(resultxemodn,n)gcd(\text{result} - x^e \mod{n}, n)

Semantic security

There does not exist a property efficiently testable from plaintext that is contained in cipher text and is efficiently possible to test for it.

Jacobi symbol leak

Jacoby symbol is defined with Legendre symbol for aa integer and nn odd integer: (an)=(ap1)e1...(apk)ek\left(\frac{a}{n}\right) = \left(\frac{a}{p_1}\right)^{e_1} \cdot ... \cdot \left(\frac{a}{p_k}\right)^{e_k} where the primes are from the factorization of nn.

It has some interesting properties similar to the Legendre symbol. For example (abn)=(an)(bn)\left(\frac{ab}{n}\right) = \left(\frac{a}{n}\right) \left(\frac{b}{n}\right) Some other properties (anm)=(an)(am)\left(\frac{a}{nm}\right) = \left(\frac{a}{n}\right) \left(\frac{a}{m}\right) And when aa is a quadratic residue the Jacobi symbol is also 11. But not necessarily the other way around. This holds because when aa is a quadratic residue in nn it must also be QR in all it’s prime factors.

Parity and half

if we knew how to compute parity or half function from encrypted message (had oracle for it) we would be able to decrypt.

Half and parity are equivalent because.

Padding

We do pad because otherwise, it is possible that mm is too small, someone tries CPT against us and we are prone to multimoduly attacks.

PKCS #1

Public-Key Crypto Standard.
Overview of PKCS, board from the 10th lecture, by Martin Mareš, http://mj.ucw.cz/vyuka/2021/kry/. />

Bleichenbacher (million message attack) uses adaptive-chosen ciphertext attack and padding oracle. It usually takes around a day to recover the key.

There are no known padding oracle attacks on PKCS #1 v2.0.

Notes about the security of RSA

Be careful with using it. It uses the hardness of factorization as its strength but is not equivalent to it.