Cryptography

Definition

Symmetric vs. Asymmetric

Symmetric

++ fast

- based on heuristics (no proofs)

- 1 key per user-pair (lots of keys)

- must be kept a secret by both ends

  • Examples
    • AES, based on Rijndael Cipher STANDARD
    • electronik cook-book ECB ALWAYS AVOID
    • cipherblock chaining BC
    • cipher feedback CFB
    • output feedback OFB
    • countermode CTR

Asymmetric

- slow

++ Based on security proofs

++ One pkpk for all users

++ only sksk must be kept a secret

  • Examples
    • CBC-MAC (similar to block cipher)

    has 2 keys, would otherwise be vulnerable

MAC vs. Digital Signature

Both are similar in that they provide message integrity : attacker cannot change message, ie. generate any valid pair (m,t)(m,t)

Message Authentication Code MAC

  • Symmetric
  • Same key kk used to sign and verify

Digital signature

  • Asymmetric
  • sksk for signature, pkpk for verification
  • public verifiability through pkpk
  • non-repudation: only signer has sksk , can not deny having signed (legal evidence)

Hash Functions

H:MTH: \cal M \mapsto \cal T (any message always mapped to a hash with the same size)

ie: MD5 (broken), SHA1 (broken), SHA2 family, SHA3 family,\dots

One-way functions Easy to compute output, infeasible to find the input from output

Collision-resistance Infeasible to find different inputs that map to the same output

called collision-resistant-hash-function CRHF

Collision(H(m1)=H(m2))(m1m2)\big(H(m_1) = H(m_2)\big) \wedge \big(m_1 \not = m_2 \big)

Attack Models

Passive Attack

Ciphertext only Observation of ciphertexts

Known plaintext Observation of plaintexts

Active Attacks

Chosen plaintext CPA Access to encryption algorithm

Chosen ciphertext CCA Access to decryption algorithm

Perfect Secrecy of Ciphers

= information theoretic security of encryption schemes

Perfect Secrecy

Cipher cc should reveal nothing about plaintext mm .

If for any probability distribution over M\mathcal{M} with random Variable MM :

mM,cC:Pr(M=mC=c)=Pr(M=m) \forall m \in \mathcal M, c \in \mathcal C: \quad \mathbf{Pr}(M=m \mid C =c)=\mathbf{Pr}(M=m) 

That means: cipher occurence = message occurence

Proof: For perfect secrecy we needKM|\mathcal{K}| \geq |\mathcal{M}|

Assume uniformly distributed MM with any kKk \in \mathcal K :

M(c)={mm=Dec(k,c)}M(c)=\{ m \mid m=\operatorname{Dec}(k, c)\}(= set ofcc's that can be decoded tomm')

If K<M|\mathcal{K}| < |\mathcal{M}| then

mM(c)\exists m^{\prime} \notin M(c) \Lrarr

Pr(M=mC=c)=0Pr(M=m)\mathbf{Pr}(M=m' \mid C=c)=0 \neq \mathbf{Pr}(M=m')

Therefore the message could not occur - no perfect secrecy.

____________

Symmetric Encryption

(Syntactic) Correctness of symmetric encryption(for all examples)

kK,mM:Enc(k,m)=c  Dec(k,c)=m \forall k \in \mathcal{K}, m \in \mathcal{M}: \quad \text{Enc}(k,m) = c ~~\Rarr ~~\text{Dec}(k,c) = m 

Ancient example: Substitution Cipher / Caesar Encryption

Cyphertext-only-attack: Letter, letter-pair frequency analysis

One-Time-Pad OTP

++ fast encryption and decryption

++ perfect secrecy

- the key must be as long as the message (key size = message size, requires too much storage)

- needs generation of lots of true-randomness

Definition

All spaces are n-bit boolean strings.

Gen()=k\text{Gen}() = k(k.length = m.length)

Enc(k,m)=km=c\text{Enc}(k, m) = k \oplus m = c

Dec(k,c)=kc=m\text{Dec}(k,c) = k \oplus c= m

Proof of perfect secrecy

Pr(C=cM=m)=\operatorname{Pr}(C=c \mid M=m)=

Pr(KM=cM=m)=\text{Pr}(K \oplus M = c \mid M = m ) =

Pr(Km=c)=\text{Pr}(K \oplus \textcolor{pink}m = c) =

Pr(K=mc)=\text{Pr}(K = m \oplus c ) =(just a property of\oplus)

=12n= \frac{1}{2^n}(2n2^nis the number of all possible keys / values of random variableKK)

Important: Key must be used once for entiremm

To save storage, one might try to split mm up in smaller pieces and encrypt them with the same cc .

c1=Enc(k,m1)=km1c_1=\operatorname{Enc}(k,m_1)= k \oplus m_1

c2=Enc(k,m2)=km2c_2=\operatorname{Enc}(k,m_2)= k \oplus m_2

c1c2=(km1)(km2)=m1m2 c_{1} \oplus c_{2}= ( k \oplus m_1)\oplus(k \oplus m_2)= m_{1} \oplus {m}_{2} 

which is vulnerable to frequency analysis.

Stream Cipher

Pseudo random number generator PRG

Small bit sequence \mapsto Large pseudorandom bit sequence (by Linear Feedback Shift Register LSFR)

To be secure the seed should be private and truly random (not chosen from a known message part like the email header)

Stream Cipher

PRG(seed)m=c\text{PRG}(seed) \oplus m = c

means no perfect secrecy because PRG is not truly random.

Stream Cipher usage

  1. Generate a truly random seed, send with asymmetric encryption (using pkpk of receiver)
  1. Then use PRG from that point on

No integrity for OTP and Stream Cipher

We perserve confidentiality but not the integrity.

Example:

Voting system, where a vote m{0,1}m \in\{0,1\} , and we have result-predictions.

Voter — {m}k — {m1}kVotingSys \text{Voter} ~— ~\{m\}_k \longrightarrow \bigcirc~— ~\{m \oplus 1\}_k \longrightarrow \text{VotingSys} (flips votes)

Message Authentication Code MAC

Gen()=k\text{Gen}() = k randomized key generation algorithm

Sig(k,m)=t\text{Sig}(k, m) = t (often randomized) signing / encryption algor. that generates a tag

Ver(k,m,t)={0,1}\text{Ver}(k,m,t) = \{0,1\} verification algorithm (the decryption algorithm would takeccnotkk)

Used to provide message integrity: attacker cannot change message, ie. generate any valid pair(m,t)(m,t)

Correctness

k,m,t{Sig(k,m)}:Ver(k,m,t)=1 \forall k, m, t\in \{\text{Sig}(k,m) \}: \quad \text{Ver}(k,m,t)=1 

____________

Asymmetric Encryption

Public-Key Encryption

Gen()=(pk,sk)\text{Gen}() = (pk,sk) randomized key generation algorithm

Enc(pk,m)=c\text{Enc}(pk, m) = c (often randomized) encryption algorithm

Dec(sk,c)=m\text{Dec}(sk,c) =m decryption algorithm

Correctness

ks,ps,m:Enc(pk,m)=c  Dec(sk,c)=m \forall ks,ps, m: \quad \text{Enc}(pk,m) = c ~~\Rarr ~~\text{Dec}(sk,c) = m 

CPA-Security

Ciphertext indistinguishability under CPA(= Chosen Plaintext attack) for any public-key-encryption.

An experiment between challenger and adversary / attacker:

  1. Generate a key pair, send pkpk to attacker (attacker has access to encryption algorithm - but it is usually randomized)
  1. Receive m1,m2m_1, m_2 from attacker
  1. Randomly choose one of them, encrypt it and send it back

Attacker should only be able to guess which of the two messages he received 50%50\% of the time.

Definition

nn= number of attackers attempty / "security parameter" that is bounded polynomially

ExpPE,ACPA(b)\operatorname{Exp}_{P E, A}^{C P A}(b)= experiment where the challenger choseb{1,2}b \in \{1,2\}

A series of ciphers under a CPA-attack is indistinguishable if for all adversaries if the following expression is very small:

AdvPE,ACPA=Pr(ExpPE,ACPA(0)=1)Pr(ExpPE,ACPA(1)=1) \operatorname{Adv}_{P E, A}^{C P A}=\left|\operatorname{Pr}\left(\operatorname{Exp}_{P E, A}^{C P A}(0)=1\right)-\operatorname{Pr}\left(\operatorname{Exp}_{P E, A}^{C P A}(1)=1\right)\right| 

The probability that attacker chose00while reality is11vs. the opposite.

1-CPA

This extension does not strengthen the definition - he already had access to encryption algorithm.

  1. Generate key pair, send pkpk to attacker
  1. Receive m∉{m0,m1}m \not\in \{m_0,m_1\} from attacker and immediately return it in the encrypted form (E(pk,m))(E(pk, m))(encryption algorithm is usually randomized)
  1. \dotsprevious experiment from this point

ElGamal Encryption Scheme

Example for public key encryption - withinZp\Z_p^*

Gen()\text{Gen}()

pick random g,xg,x and prime pp- forZp\Z_p^*

pk:=(p,g,gx)p k:=\left(p, g, \textcolor{pink}{g^x}\right)

sk:=(p,g,x)s k:=(p, g, \textcolor{pink}{x})-xxis private and can not be computed feasiblyx=Dlogg(gx)x = \text{Dlog}_g(g^x)

Enc(pk,m)\text{Enc}(pk, m)

pk:=(p,g,gx)p k:=\left(p, \textcolor{pink}g, \textcolor{pink}{g^x}\right)

pick random yy

return c:=(gy,m(gx)y)=(gy,mgxy) c := \textcolor{grey}{(g^y,m\cdot (g^x)^y) = }(g^y,m\cdot g^{xy}) 

Dec(sk,c)\text{Dec}(sk, c)

sk=(p,g,x)sk =(p, g, \textcolor{pink}x)

receivedc=(gyundefinedA,mgxyundefinedB)c=(\overbrace{g^y}^A,\overbrace{m\cdot g^{xy}}^B)

return m:=AxBm:=A^{-x} \cdot B

Correctness

BAx=B\cdot A^{\textcolor{pink}{-x}} =

mgxy(gy)x= m\cdot g^{xy} ~~\cdot ~~ (g^{{y}})^{\textcolor{pink}{-x}} = 

mgxy(gxy)=m\cdot g^{xy} ~~\cdot ~~ (g^{\textcolor{pink}{-xy}}) =

mgxyxy=mg0=m m\cdot g^{\textcolor{pink}{xy-xy}} = m\cdot g^{\textcolor{pink}{0}} = m 

Proof of Correctness

ElGamal has CPA security if the DDH Decisional Diffie-Hellman Assumption assumption holds in G:=ZpG := \Z_p^* .

Decisional Diffie-Hellman Assumption

(= One can not compute the discrete logarithm in polynomially boundednn= inn\textcolor{pink}nattempts).

G2n|G| \approx 2^{\textcolor{pink}n} and we choose random gZpg\in \Z_p^* .

With given gx,gy,Zg^x, g^y, Z we can not decide whether Z=gxyZ = g^{xy} for any x,y,Z{1,,Zp}x,y,Z \in \{1,\dots,|\Z_p^*|\} .

Proof by contradiction

We can break ElGamal if we can break the DDH assumption.

If A\exists A algorithm that breaks ElGamal with any pkpk then we imitate the challenger to break DDH with his advantage Adv>0\operatorname{Adv} >0 of distinguishing correctly.


We havegx,gyg^x, g^yand want to know whetherZ=gxyZ = g^{xy}

  1. Generate keys:

    pk:=(p,g,gx)p k:=\left(p, g, \textcolor{pink}{g^x}\right)

    sk:=(p,g,x)s k:=(p, g, \textcolor{pink}{x})

    and sendpkpktoAA.

  1. receive m0,m1m_0, m_1 randomly choose one and encrypt with yy .

    return c:=(gy,m(gx)y)=(gy,mgxy) c := \textcolor{grey}{(g^y,m\cdot (g^x)^y) = }(g^y,m\cdot g^{xy}) 

  1. Receive attackers guess bb' of bb . (which is correct because of his advantage)

    If (b=b)(Z=gxy)(b = b') \Rarr (Z=g^{xy})

    If (bb)(Zgxy)(b \not = b') \Rarr (Z \not=g^{xy})means it was just a random number.

Naive RSA

Also called "textbook RSA" because it is simplified - but not secure.

Gen()\text{Gen}()

  1. Pick two random primes p,qp,q

    pq=Np \cdot q = N

    calculate φ(N)=ZN \varphi(N) \textcolor{grey}{=\left|\mathbb{Z}_{N}^{*}\right|} (size of set where all elements have an inverse)


  1. Choose an random e\textcolor{pink}e so that it has an inverse in Zφ(N):gcd(e,φ(N))=1\Z_{\varphi(N)}: ~~~\gcd(\textcolor{pink}e,\varphi(N))=1

    eehas an inverse inZφ(N)\Z_{\varphi(N)}but does not necessarily one inZN\Z_N.

    d:=e1\textcolor{pink}d:=\textcolor{pink}{e^{-1} }inZφ(N)\Z_{\varphi(N)}

    return key pair

    pk:=(N,e)p k:=(N, \textcolor{pink}e)

    sk:=(p,q,d)s k:=(p, q, \textcolor{pink}d)

    You can not figure outddjust fromeeandNNunless you knowp,qp,q- this is a simplified version.

EncryptionEnc(pk,m)\text{Enc}(pk, m)

pk=(N,e)p k =\left(N,\textcolor{pink}e\right)

return cipher c:=mec:=m^{\textcolor{pink}e}inZN\Z_N.

DecryptionDec(sk,c)\text{Dec}(sk, c)

sk=(p,q,d)sk =(p, q,\textcolor{pink} d)

return m:=cdm:=c^{\textcolor{pink}d}inZN\Z_N.

Correctness

Decryption: c=mec=m^{\textcolor{pink}e}

cd=(me)d=med=mee1=m1=mc^d = (m^e)^d = m^{ed} = m^{ee^{-1}}= m^1 = minZN\Z_N

What still needs to be proven:

We know thated=ee1=1ed = ee^{-1} = 1inZφ(N)\Z_{\varphi(N)}- but what aboutZN\Z_N? See below.

This version is insecure: No randomization ofEnc\text{Enc}

Not secure against passive attacks because it is deterministic.

Same messages result in the same ciphers:

m=mEnc(pk,m)=Enc(pk,m) m=m^{\prime} \Rightarrow \operatorname{Enc}(p k, m)=\operatorname{Enc}\left(p k, m^{\prime}\right) 

Secure usage of RSA

Proof of Correctness

Chinese remainder theorem CRT

Let pqp \not = q be primes and N=pqN = p\cdot q .

Two numbers are equal in ZN\Z_{N}\Leftrightarrow they are also equal in Zp\Z_{p} and Zq\Z_{q} .

Proof of Correctness

ee has an inverse in Zφ(N)\Z_{\varphi(N)} , now we want to prove that it also has an inverse in ZN\Z_N .

It is sufficient to prove that med=mee1=mm^{ed} = m^{e\cdot e^{-1}} = m in Zp\Z_{p} and Zq\Z_{q} .

case 1:m=0m = 0

then med=0ed=0m^{ed} = 0^{ed} = 0 in Zp\Z_{p} and Zq\Z_{q} .

case 2:m0m \not= 0

If ed=ee1=1e\cdot d = e \cdot e^{-1}= 1 in Zφ(N)=Z(p1)(q1)\Z_{\varphi(N)}= \Z_{(p-1)(q-1)}

mZp,Zqm \in \Z^*_p, \Z^*_q because: k:ee1=k(p1)(q1)+1=1\exists k:~ e \cdot e^{-1}=k(p-1)(q-1)+1 = 1 also in ZN\Z_{N}

Digital signature

M\mathcal{M} message space, where mMpkm \in \mathcal{M}_{pk}

Mpk={m:Sig(sk,m)↦̸(error)} \cal M_{pk} = \{\forall m: \text{Sig}(sk,m) \not\mapsto (\text{error}\downarrow) \} 

Gen()=(pk,sc)\text{Gen}() = (pk, sc) randomized key generation algorithm

Sig(sk,m)=t\text{Sig}(\textcolor{pink}{sk}, m) = t (often randomized) signing / encryption algor. that generates a tag

Ver(pk,m,t)={0,1}\text{Ver}(\textcolor{pink}{pk},m,t) = \{0,1\} verification algorithm - decryptstt and if it is equal to mm returns 11

Correctness

k,m,t{Sig(sk,m)}:Ver(pk,m,t)=1 \forall k, m, t\in \{\text{Sig}(sk,m) \}: \quad \text{Ver}(pk,m,t)=1 

CMA-Security

Chosen message attack CMA: access to decryption algorithm..

Goal: forging a signature - if attacker is successful in then the verifier must return 11 .

Pr(ExpIn,AnCMA=1)0 \operatorname{Pr}(\operatorname{Exp}_{I_{n}, A_{n}}^{\mathrm{CMA}}=1) \approx 0 

Naive RSA-based Digital Signatures

Same as naive RSA but

pk:=(N,e)p k:=(N, \textcolor{pink}e)

sk:=ds k:=\textcolor{pink}d

with encryption being the signing algorithm just returning t:=mdt:=m^{\textcolor{pink}d} and der Verifier returning 11 if the decrypted tt is equal to mm .

Correctness

te=med=mt^{e} = m^{e d} = minZN\Z_N

This is a simplified version. Not secure.

Would be secure if the signing algorithm would also hash the messages:

Sig(m)=(H(m))dmodN\text {Sig}(m)=(\mathrm{H}(m))^{d} \bmod \mathrm{N}