David Wong

cryptologie.net

cryptography, security, and random thoughts

Hey! I'm David, cofounder of zkSecurity, research advisor at Archetype, and author of the Real-World Cryptography book. I was previously a cryptography architect of Mina at O(1) Labs, the security lead for Libra/Diem at Facebook, and a security engineer at the Cryptography Services of NCC Group. Welcome to my blog about cryptography, security, and other related topics.

← back to all posts

Paillier's additively homomorphic cryptosystem

blog

Pascal Paillier released his asymmetric encryption algorithm in 1999, which had the particularity of being homomorphic for the addition. (And unlike RSA, the homomorphism was secure.)

Homomorphic encryption, if you haven’t heard of it, is the ability to operate on the ciphertext without having to decrypt it. If that still doesn’t ring a bell, check my old blogpost on the subject. In this post I will just explain the intuition behind the scheme, for a less formal overview check Lange’s excellent video.

Paillier’s scheme is only homomorphic for the addition, which is still useful enough that it’s been used in different kind of cryptographic protocols. For example, cryptdb was using it to allow some types of updates on encrypted database rows. More recently, threshold signature schemes have been using Paillier’s scheme as well.

The actual algorithm

As with any asymmetric encryption scheme, you have the good ol’ key gen, encryption, and decryption algorithms:

Key generation. Same as with RSA, you end up with a public modulus N=pq where p and q are two large primes.

Encryption. This is where it gets weird, encryption looks more like a Pedersen commitment (which does not allow decryption). To encrypt, sample a random r and produce the ciphertext as:

(N+1)m·rNmodN2

where m is the message to be encrypted. My thought at this point was “WOOT. A message in the exponent? How will we decrypt?

Decryption. Retrieve the message from the ciphertext c as

cφ(N)1N·φ(N)1modN2

Wait, what? How is this recovering the message which is currently the discrete logarithm of (N+1)m?

How decryption works

The trick is in expanding this exponentiation (using the Binomial expansion).

The relevant variant of the Binomial formula is the following:

(1+x)n=(n0)x0+(n1)x1++(nn)xn

where (ab)=a!b!(ab)!

So in our case, if we only look at (N+1)m we have:

(N+1)m&=(m0)+(m1)N+(m2)N2++(mm)Nm&=(m0)+(m1)NmodN2&=1+m·NmodN2

Tada! Our message is now back in plain sight, extracted from the exponent. Isn’t this magical?

This is of course not exactly what’s happening. If you really want to see the real thing, read the next section, otherwise thanks for reading!

The deets

If you understand that, you should be able to reverse the actual decryption:

cφ(N)&=((N+1)m·rN)φ(N)&=(N+1)m·φ(N)·rNφ(N)modN2

It turns out that the rNφ(N)=1modN2 because Nφ(N) is exactly the order of our group modulo N2. You can visually think about why by looking at my fantastic drawing:

On the other hand, we get something similar to what I’ve talked before:

(N+1)mφ(N)=(1+mN)φ(N)=1+mφ(N)NmodN2

Al that is left is to cancel the terms that are not interesting to us, and we get the message back.

← back to all posts blog • 2023-03-31
currently reading:
Paillier's additively homomorphic cryptosystem
03-31 blog
📖 my book
Real-World Cryptography is available from Manning Publications.
A practical guide to applied cryptography for developers and security professionals.
🎙️ my podcast
Two And A Half Coins on Spotify.
Discussing cryptocurrencies, databases, banking, and distributed systems.
📺 my youtube
Cryptography videos on YouTube.
Video explanations of cryptographic concepts and security topics.