Settings

Settings other than “Default” will be saved in local storage to persist across pages, reloads, and sessions.

Homomorphic Encryption

Applied Cryptography

These slides are from a lecture I designed and repeatedly gave in the course on Applied Cryptography at TU Eindhoven.

Unlike the previous lecture on OCB2, this was always towards the end of the course with the goal of giving the students an idea of how much is possible with cryptography. These slides specifically are from the first half of the first half of the lecture, with further topics including Multi-Party Computation (MPC), and a discussion of requirements for security notions.

One issue this lecture always had is that there is so much to talk about with regards to those topics that it was always too long, to the point where this could fit most of two full lectures; because of this, and to give me more time to prepare the other parts separately, I’ve decided to split this part of, but note that I haven’t changed much otherwise.

Encryption Can Create Problems

“All the Things” meme: Encrypt all the things.
  • For Confidentiality in E-Voting:
    Encrypt all the votes!
    • But how do we then count them?
  • For Research on Confidential Data (say DNA databases):
    Encrypt all the data!
    • But how can we then do the research?
  • For Confidentiality in cloud-computing:
    Encrypt all your data!
    • But how would we then run computations in the cloud?

Homowhat?

Homomorphism = Structure Preserving Map

  • Let φ:ABφ: A → B

  • Let :A×AA∘: A × A → A

  • Let :B×BB∙: B × B → B

If a,bA\forall a,b ∊ A: φ(a)φ(b)=φ(ab)φ(a)∙φ(b) = φ(a∘ b), then φφ is “homomorphic” with regards to “” and called a Homomorphism.

  • Today: φ=𝖤𝗇𝖼φ = \mathsf{Enc}
  • For ElGamal: =∘ = ⋅ in 𝔾𝔾

Textbook RSA

Just for completeness: Yes, strictly speaking textbook-RSA is homomorphic.

For reasonable definitions of those words, it is however not an encryption- or signature-scheme, but rather a trapdoor one-way permutation. Using it as encryption- or signature-scheme is catastrophically insecure!

A vomiting person.
Typical Cryptographers reaction to inadequate use of textbook RSA.

ElGamal

  • Let g=:𝔾⟨ g⟩ =: 𝔾 be a group of prime order qq with hard DDH-problem.
    • That is for random x,y,zqx,y,z ∈ ℤ_{q}: (gx,gy,gz)(g^x,g^y,g^z) is indistinguishable from (gx,gy,gxy)(g^x,g^y,g^{x⋅y})
  • Key-Generation: Sample aqa ← ℤ_q, then sk=ask = a and pk=gapk = g^a.
  • Encryption: Sample rqr ← ℤ_q, then c=(gr,[ga]rm)c = (g^r, [g^a]^r⋅m)
  • Decryption: m=c[0]ac[1]=(gr)agram=gra+ram=g0m=1m=mm = c[0]^{−a} ⋅ c[1] = \left(g^r\right)^{-a} ⋅ g^{ra} ⋅ m = g^{-ra + ra} ⋅ m = g^0 ⋅ m = 1 ⋅ m = m
  • Let c:=(gr,grym)c₀ := \left(g^{r₀}, g^{r₀y}⋅ m₀\right) and c:=(gr,grym)c₁ := \left(g^{r₁}, g^{r₁y}⋅ m₁\right) be ElGamal ciphertexts encrypted for the public key gyg^y
  • Componentwise multiplication gives (grgr,grymgrym)=(gr+r,g(r+r)ymm)\left(g^{r₀}⋅ g^{r₁},\ g^{r₀y}⋅ m₀ ⋅ g^{r₁y}⋅ m₁\right) = \left(g^{r₀ +r₁},\ g^{(r₀+r₁)y}⋅ m₀⋅ m₁\right)
  • Let r:=r+rr := r₀ + r₁
  • (gr,gry(mm))\left(g^{r},\ g^{ry}⋅ (m₀⋅ m₁)\right) regular ciphertext containing mmm₀⋅ m₁

How useful is this?

  • Over prime-order subgroups of p×ℤ_p^×: Very limited, 0 not in the group

  • Over elliptic curves: Even worse.

  • Still demonstrates the viability of the concept.

The “useless machine”, an art piece with a switch that is turned off by the machine if someone turns it on.

What about Security?

  • IND-CCA2 security is unachievable for any homomorphic encryption scheme!
    • Proof left as a simple exercise for you.
  • ElGamal is famously IND-CPA secure under standard assumptions.
    • Semantic Security is achievable and thou shalt not compromise on it.
  • ElGamal is also IND-CCA1 secure under reasonable assumptions.
    • If you can easily get IND-CCA1 security, go for it.
  • All sensible homomorphic encryption-schemes known today are also rerandomizable.
    • Encrypt neutral element and use homomorphism with it.

Exponential ElGamal

  • Let m,mqm₀', m₁' ∊ ℤ ≪ q
  • Let m:=gm,m:=gmm₀ := g^{m₀'},\ m₁ := g^{m₁'}.
  • Use ElGamal Encryption and apply the homomorphism as before
  • Decryption yields m=mm=gmgm=gm+mm = m₀⋅ m₁ = g^{m₀'}⋅ g^{m₁'} = g^{m₀' + m₁'}.
  • Compute m:=𝖽𝗅𝗈𝗀(m)=𝖽𝗅𝗈𝗀(gm+m)=m+mm' := \mathsf{dlog}(m) = \mathsf{dlog}\left(g^{m₀' + m₁'}\right) = m₀' + m₁'
  • Computing the discrete logarithm is possible if mm' is small.

    Homomorphic over (small) subsets of +ℤ^+

How useful is this?

  • Votes are added
  • Money is often added and subtracted

Paillier

  • Computing the discrete logarithm is still annoying though.
Portrait of Pascal Paillier
Pascal Paillier

Key-Generation:

  • p,qp,q \leftarrow Primes
  • n:=pqn := p⋅ q
  • φ(n)=(p1)(q1)φ(n) = (p-1)(q-1)
  • return nn (pk), φ(n))φ(n)) (sk)

Encrypt(mm; rr)

  • rn²r \leftarrow ℤ_{n²}
  • return (mn+1)rnmodn²(mn+1)\ ⋅\ r^n \mod n²
  • Equivalent: (n+1)mrnmodn²(n+1)^m\ ⋅\ r^n \mod n²

Decryption(cc)

  • L(x,n):=x1nL(x ∊ \mathbb{N}, n ∊ \mathbb{N}) := \frac{x-1}{n}
  • m:=L(cφ(n)modn²)φ(n)modnm := \frac{L\left(c^{φ(n)} \mod n²\right)}{φ(n)} \mod n
  • Works because: (rn)φ(n)=rnφ(n)=rφ(n²)r0=1modn²(r^n)^{φ(n)} = r^{n⋅φ(n)} = r^{φ(n²)} \equiv r^0 = 1 \mod n²

Homomorphic Property

  • 𝖤𝗇𝖼(m;r)𝖤𝗇𝖼(m;r)\mathsf{Enc}(m₀; r₀)⋅\mathsf{Enc}(m₁; r₁)

    =(n+1)mrn(n+1)mrn= (n+1)^{m₀} ⋅ r₀^n ⋅ (n+1)^{m₁} ⋅ r₁^n

    =(n+1)m+m(rr)n=(n+1)^{m₀+m₁} ⋅ (r₀⋅ r₁)^n

    =𝖤𝗇𝖼(m+m;(rrmodn²))=\mathsf{Enc}\left(m₀ + m₁; \left(r₀ ⋅ r₁ \mod n²\right)\right)

Correctness

  • Let λ=φ(n)λ = φ(n)

  • ((n+1)mrn)λmodn²\left((n+1)^m ⋅ r^n\right)^λ\mod n²

    =(n+1)mλrnλmodn²=(n+1)^{m⋅λ} ⋅ r^{n⋅ λ}\mod n²

    =(mλn+1)r0modn²=(m⋅λ⋅ n+1) ⋅ r^0 \mod n²

    =mλn+1=m⋅λ⋅ n+1

  • L(mλn+1)L(m⋅λ⋅ n+1)

    =mλn+11n=mλnn=mλ= \frac{m⋅λ⋅ n + 1 -1}{n} = \frac{m⋅λ⋅ n}{n} = m⋅λ

  • mλλ=m\frac{m⋅λ}{λ} = m

Soundness

  • IND-CPA follows from the “Decisional Composite Residuosity Assumption”:

    Let nn be an RSA-modulus, xx, yy random in n2×ℤ_{n^2}^\times, then xnx^n and yy are computationally indistinguishable.

  • Stronger (“more daring”) assumption than the RSA-assumption.

  • Random-self-reducible problem ⇒ Average case hardness = Worst case hardness

The CGS Voting Scheme

  • Ronald Cramer, Rosario Gennaro and Berry Schoenmakers
  • Assume (for now!) a trusted authority 𝒜𝒜 and voters 𝒱i𝒱_i.
  • Basic idea:
    • 𝒜𝒜 generates keypar 𝗉𝗄𝒜,𝗌𝗄𝒜\mathsf{pk}_{𝒜},\ \mathsf{sk}_{𝒜}
    • Users 𝒱i𝒱_i encrypt their vote viv_i: ci:=𝖤𝗇𝖼(𝗉𝗄𝒜,vi)c_i := \mathsf{Enc}(\mathsf{pk}_{𝒜}, v_i)
    • Everyone publishes their encrypted vote cic_i with a signature to proof that it is theirs.
    • C:=ciC := ∑ c_i
    • 𝒜𝒜 computes M:=𝖣𝖾𝖼(𝗌𝗄𝒜,C)M := \mathsf{Dec}(\mathsf{sk}_{𝒜}, C)
    • MM is the sum of all votes

This works if all involved parties are honest!

  • Add signatures and proof honest execution of all algorithms.
    • Reasonably efficient zero-knowledge-proofs exist for this.
  • Assuming many assumptions this provides a verifiably correct result!
  • Trusted authority can learn all individual votes!

Voting with Trusted Authorities

Distributing the Authority

  • Assume a set of Parties 𝒜,,𝒜n𝒜₀,…,𝒜_n that are unlikely to collude (e.g. Nazis, Social Democrats and Tankies)
    • No need to trust any of them individually!
  • Each generates a DH-keypair (gxi,xi)(g^{x_i}, x_i) and publishes the public key gxig^{x_i}
  • Compute gxi=gxi𝗉𝗄𝒜∏ g^{x_i} = g^{∑x_i} ≕ \mathsf{pk}_𝒜
    • 𝗌𝗄𝒜\mathsf{sk}_𝒜 is distributed amongst (by assumption) non-colluding parties.
  • To decrypt (gr,grxi+v)(g^r, g^{r⋅∑x_i+ v}) each party 𝒜i𝒜_i publishes grxig^{rx_i} with a proof of correctness.
    • gv=grxi+v(grxi)1g^v = g^{r⋅∑x_i+ v} ⋅ \left(∏g^{rx_i}\right)^{-1}

Fairness

  • Problem: Last party to publish grxig^{rx_i} can use the already published values to compute the result.
    • If the result is not what they like, they can just not publish their share.
      • Can be resolved with an honest majority
    • Can always simply refuse to publish as an act of obstruction.
  • Possible Solution: Require kk out of nn parties to participate in encryption.
    • So called Treshold Encryption
    • Possible with Shamir’s Secret Sharing (next slide)

Shamir’s Secret Sharing

  • Every degree-kk polynomial pp is uniquely defined by any k+1k+1 points on it.
  • Let pp be a large enough prime so that every possible secret key can be encoded into pℤ_p.
  • Sample any degree-k+1k+1 polynomial over pℤ_p, such that p(0)=𝗌𝗄p(0) = \mathsf{sk}.
  • Party 𝒜i𝒜_i receives p(i+1)p(i+1) as share.
  • Any subset of at least kk parties can now recover 𝗌𝗄\mathsf{sk} and use it to decrypt.
  • Use Multi-Party Computation (→Second half) to do so without revealing shares.

Voting with Exponential ElGamal

  • Number of votes is small enough for brute-force search
  • Distributing decryption is quite easy
  • Somewhat practical NIZK proofs.

Attacking Weak Groups

But what if |g|\left|⟨g⟩\right| is not prime?

  • Let g=𝔾=p×⟨ g⟩ = 𝔾 = ℤ_p^× for p=2q+1p = 2q + 1 with pp and qq prime. Then |𝔾|=2q|𝔾| = 2q
  • 𝔾𝔾 has four subgroups: {1}\{1\}, 𝔾𝔾, {1,1}\{1,\ -1\}) and {h²|h𝔾}\left\{h² |h ∊ 𝔾\right\} (the “squares”).
  • All elements can be mapped into the order-2 subgroup ({1,1}\{−1,1\}) by raising them to p12\frac{p-1}{2} (Legendre-symbol)
    • For non-squares hh: hp12=hq=1h^{\frac{p-1}{2}} = h^q = -1
    • For squares hh: hp12=hq=1h^{\frac{p-1}{2}} = h^q = 1
  • gxg^x is a square if and only if xx is even; there are exactly q=p12q = \frac{p-1}{2} squares
  • Let gxg^x be a public key and (gr,grx+v)(g^r, g^{rx+v}) an exponential ElGamal Ciphertext.
  • Using the Legendre-Symbol extract xx, rr and rx+vrx + v modulo 2.
  • Compute v(rx+v)xrmod2v ≡ (rx + v) − x⋅r \mod 2

From provably secure to broken in one plaintext-bit.

  • Nothing magic about 2, except that it always factors p1p-1; attack reveals even more with bigger factors of p1p-1 if there are any. (Second part of the CTF.)

Extracing a Yes/No-vote

Let ppffdhe3072, as defined in rfc 7919, but set g5g ≔ 5.

Let gxg^x be the authority’s public key, and (gr,grx+v)\left(g^r, g^{r⋅x + v}\right) be the vote;

ffdhe3072 5809605995369958062758586654274580047791722104970656507438869740087793294939022179753100900150316602414836960597893531254315756065700170507943025794723871619068282822579148207659984331724286057133800207014820356957933334364535176201393094406964280368146360322417397201921556656310696298417414318434929392806928868314831784332237038568260988712237196665742900353512788403877776568945491183287529096888884348887176901995757588549340219807606149955056871781046117195453427070254533858964729101754281121787330325506574928503501334937579191349178901801866451262831560570379780282604068262795024384318599710948857446185134652829941527736472860172354516733867877780829051346167153594329592339252295871976889069885964128038593002336846153522149026229984394781638501125312676451837144945451331832522946684620954184360294871798125320434686136230055213248587935623124338652624786221871129902570119964134282018641257113252046271726747647
gxg^x 1178422411924486958310518240424821423040957188687825057555659830550378263510073306107826979544796575581092864474013859848411683110722461050524985535903633267933181649449521492140619218190781017834141057813996864031540673127077260750562976883056933265299524235879517573522680152812762038788571588762969840540459358973658480304807631153501906537924864957165401501433029412118442995605830313482463502502611043476703721906336742557389097631604837824007057894990710151627388543409148631930102190218822566302711720142222891200239944222450611688678907361499075375542224708939911163827928094457401814485596390766702817007700506763687293635562017790104498759031039920234675912623036025508035266193042054655551018340474532335243964280335581101768295546418789778720097444072051193680655163299476318431723372529905023123598295034508594560332985609322215259523161622741652739241422734569926920887821903929220695977470881014091083161936497
grg^r 4391994992610190319761449423767558518287000603245015644061861968679879933337395995429756128961352401863780868474236878652870242607882799062369358925651987215239410611308619408087876420713598003194048378754945497590284890820077288736035873337993256978522181661688946519984569922761353732835113526226029750825838812660117533998736797535557556410205726216629493883843853203085360508003871567520804422137558521937428953984073787478727608587818371443939806961148299427728514263951625957282663618146244114379853035041193337725332563682083900915059496335423262906532905696023570562596603494105746473558018253933459521477116630109743166505878873669721663774512137675064450410776198632736987001294081430110777572089316530344511484242018477683933728607336968422554102152043942737684665009459102328694144745524015741187437105408651421671925483097972699414030058069235142954282491047924744808340833880546775727942983678131147663439447709
grx+vg^{r⋅x + v} 5395416124159647852232053526888393879470035232885404715821474458723296253865500209247073839556053288575953298332048662616216656063245701775482656576939598611157858792608541167492306188208191737104682763662891236061367927020485765715282045810686491717965013085514719091288047370378638177850483310244998761743341955636446177708689672802618220061539470560431452184170627175614843771618345320897499929749589681937943153125034657123338945309361175952082354149816407275782478032361990297631827451164722092243937473539235664730836409837283440318166725738525759585833190163728094416505668926031712944518562785349495799335306706887922893135632101334647955977364415120025138102280729172829522688508535240963566716776803003424540328548627396245236166759995547053443637697617303536790324197962909441609724344467008965246110304923044935561966769054021248304317000428404682799132820685369364288090193400890270137366516610436388585339230955

What is the value of 𝑣?

v ∊ {0, 1}; Use a computer to solve this.

0 Bar depicting 50% for “ 0” 0%
0 Bar depicting 50% for “ 1” 0%
0 Bar depicting 50% for “ No idea.” 0%

Extracing a lot more

Let’s look at another case with a modulus that is merely a strong prime, but not a safe prime. (We say that a prime pp is strong if p1p - 1 has a large prime-factor).

In our case p1p - 1 is divisible by 2, 3, 19, 29, and one more very large prime-factor; we set g3g ≔ 3.

pp 39427225484355975102122600527167302777805510048781168392636183693013851243149270836739456524825801432201096199599098837095124524178989165662152572613751755039167267056414754728944498770643037152808863262177629669439832711280387073579264571863375293058926284173351179703389057202165646232990957198441854659340513518404920247358713319869533563202860005285693572620182090544469728768558369196539592053834936634362896039654693258365850287567082105126090534698108468407005216489068184924395507401289092087150151804123009972300008624145519860441350665518426857193464224049197310434176217485695053226283892054946252281144445763
grg^r 36981052468204015342814738886535889262303816373942871782354072965419111977428988029591751718593750303549486532165596737396639074163765723792999775542824594983641080378960918791705467496105793562432494134172049602654797267947073315992738363352297441290445038812540973419812886087905175206734035088338782951307817177031996038671276499176546378702002550363471057798900060392802512722265250574768121113861555344142836128806956289892118658119853137096658853880215859575012370051967344193602399685489342306558859327433334550192742467618712050597491566408592255067448165452574459357391258520026968084348560186898996649757308090
gxg^x 10795413919299506427910466223527337935363002929252676398876302508914409257071944905678346360861475901850033320533149685589748011158474408784139478481429894796234833051864312509042526078156253354562165666142023950977152193014586642217821653627539196186628753880916943903639574952034303131136200946250409944309207038682275431290465184032752904723996966822707995758294205800296398056896937621111736251437580020809350620943102808896919589693593540652151149724735965648542177534454301093886394663729124484185167537965968550285629874212870411593675629916011609742678132687506145645337617959446411096354221785455353316440864701
grx+vg^{r⋅x+v} 33330859593184613696230395939031978408958334719631475004006216203461834696669154109969917408468331667777451411924184668888812972058260019937437412653703592015018635183892166957401945680089327654695532867266658656727546030404543158736654804738955611390461390401929507979512798110723528678746579365902727283615390104670367729787555345614021454181564723496934578804290920348904864533192734294938083789040237018298087291666348051784970318609853771343985719715621814596725541349201296285190582915066558517067680055317813080518519870242506507387177985994926804123608504149321685825212437457708928295386859542357104381968254250

To make things more interesting, we allow more than just voting 0 or 1, but allow all options from 0 to 9 inclusive.

What is the value of 𝑣?

v ∊ {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; Use a computer to solve this.

0 Bar depicting 50% for “ 0” 0%
0 Bar depicting 50% for “ 1” 0%
0 Bar depicting 50% for “ 2” 0%
0 Bar depicting 50% for “ 3” 0%
0 Bar depicting 50% for “ 4” 0%
0 Bar depicting 50% for “ 5” 0%
0 Bar depicting 50% for “ 6” 0%
0 Bar depicting 50% for “ 7” 0%
0 Bar depicting 50% for “ 8” 0%
0 Bar depicting 50% for “ 9” 0%
0 Bar depicting 50% for “ No idea.” 0%

Fully Homomorphic Encryption (FHE)

  • Addition is nice, but insufficient for cloud-computing.
  • We need the ability to run arbitrary circuits!
Craig Gentry. CC-BY(?) John D. and Catherine T. MacArthur Foundation

Situation before 2009

  • Lattice based schemes support both addition and multiplication

  • They are noisy however; every operation will increase that noise

    • Ciphertexts grew exponentially in size.
    • Decryption becoming unreliable.
  • Additions add a little, multiplications a lot of noise.

Only practical for circuits with limited depth, existence of a “proper” scheme dubious.

2009: Craig Gentry publishes his PhD-thesis

  • “A Fully Homomorphic Encryption Scheme”
  • First plausible scheme
  • Foundation of everything we have seen since then

Gentrys idea: Bootstrapping

  • Encrypt the secret key with its public key, giving 𝖾𝗌𝗄𝖤𝗇𝖼(𝗌𝗄)\mathsf{esk} ≔ \mathsf{Enc}(\mathsf{sk})).
    • Not guaranteed to be secure by IND-CPA! (Adversary doesn’t know it.)

      ⇒ Requires extra analysis!

  • Encrypt the ciphertext c=𝖤𝗇𝖼(m)c = \mathsf{Enc}(m) a second time, giving c𝖤𝗇𝖼(𝖤𝗇𝖼(m))c' ≔ \mathsf{Enc}(\mathsf{Enc}(m)).
  • Run 𝖣𝖾𝖼\mathsf{Dec} homomorphically on 𝖾𝗌𝗄\mathsf{esk} and cc'.
  • The resulting cc'' now contains mm with less noise.
  • Perform at least one more operation towards the actual goal.
  • Rinse and Repeat.
Bootstrapping of lattice based FHE schemes. Enc(SK) , PK , Enc(m) Enc Enc( Enc(m) ) Homomorphic Decryption Enc( m ) ≥ 1 more Operation Enc( m’ ) repeat Noise Level Leftover Capacity
As long as the capacity is enough for one arbitrary computation, bootstrapping will eventually arrive at the goal.

Performance

  • Homomorphic decrypting needs many operations
  • Huge parameters necessary
  • Combined SLOW and HUGE!
  • Initial scheme roughly a hundred trillion times slower compared to operations on the plaintext! (one hundred trillion = 100000000000000)

FHE: State of the Art

Wonkyung Jung, Sangpyo Kim1, Jung Ho Ahn, Jung Hee Cheon and Younho Lee in “Over 100x Faster Bootstrapping in Fully Homomorphic Encryption through Memory-centric Optimization with GPUs”, April 2021:

The wall-clock time for bootstrapping is reduced to 526.96ms in a 173-bit security parameter set with 65,536 slots and 19-bit precision bit, which translates into 0.423us in terms of amortized time per bit.

[…]

The amortized FHE-mult time of our implementation is 24.35 ms, through which we believe that practical privacy-preserving applications can be developed.

This is clearly going somewhere.

Conclusions about FHE

Theoretical

  • Existence is an amazing result!
  • Super-useful for cloud-computing.
  • Potential building-block for MPC.

Practical

  • Performance still unusable for cloud-computing.
  • Getting better.
  • Current research topic.
  • Already usable for specific applications.

Main Problems

  • Bootstrapping very expensive
  • Multiplications require frequent bootstrapping
  • Large size terrible for communication

If somebody wants to sell it to you as a solution to an actual problem, stay sceptical but don’t dismiss it right away!

References

Images