Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Homomorphic Encryption In Python

Homomorphic Encryption In Python

Slides of my talk given at PyData London's 86th meet-up

Sefik Serengil

July 03, 2024
Tweet

Other Decks in Programming

Transcript

  1. PyData London ‘24 PyData London’s 74th Meetup 2023, May 2

    2024, June 16 Billion-Scale Facial Recognition The Art and Science of Deep Face Recognition in Python
  2. sefiks.com @serengil @sefiks serengil On-Prem Cloud encrypted_salary encrypted_salary We cannot

    use the computation power of cloud in this design! encrypted_salary
  3. RSA sefiks.com @serengil @sefiks serengil 𝜀(𝑚) = 𝑚𝑒𝑚𝑜𝑑𝑛 𝜀(𝑚1 )

    = (𝑚1 )𝑒𝑚𝑜𝑑𝑛 𝜀(𝑚2 ) = (𝑚2 )𝑒𝑚𝑜𝑑𝑛 𝜀(𝑚1 ) × 𝜀(𝑚2 ) = (𝑚1 )𝑒 × (𝑚2 )𝑒𝑚𝑜𝑑𝑛 𝜀(𝑚1 ) × 𝜀(𝑚2 ) = (𝑚1 × 𝑚2 )𝑒𝑚𝑜𝑑𝑛 𝜀(𝑚1 × 𝑚2 ) = (𝑚1 × 𝑚2 )𝑒𝑚𝑜𝑑𝑛 𝜀(𝑚1 × 𝑚2 ) = 𝜀(𝑚1 ) × 𝜀(𝑚2 ) RSA is multiplicatively homomorphic! https://sefiks.com/2018/05/21/the-math-behind-rsa-algorithm/
  4. Paillier sefiks.com @serengil @sefiks serengil 𝜀(𝑚, 𝑟) = 𝑔𝑚 ×

    𝑟𝑛𝑚𝑜𝑑𝑛2 𝜀(𝑚1 , 𝑟1 ) = 𝑔𝑚1 × (𝑟1 )𝑛𝑚𝑜𝑑𝑛2 𝜀(𝑚2 , 𝑟2 ) = 𝑔𝑚2 × (𝑟2 )𝑛𝑚𝑜𝑑𝑛2 𝜀(𝑚1 , 𝑟1 ) × 𝜀(𝑚2 , 𝑟2 ) = 𝑔𝑚1 × (𝑟1 )𝑛 × 𝑔𝑚2 × (𝑟2 )𝑛𝑚𝑜𝑑𝑛2 𝜀(𝑚1 , 𝑟1 ) × 𝜀(𝑚2 , 𝑟2 ) = 𝑔𝑚1+𝑚2 × (𝑟1 × 𝑟2 )𝑛𝑚𝑜𝑑𝑛2 𝜀(𝑚1 + 𝑚2 , 𝑟1 × 𝑟2 ) = 𝑔𝑚1+𝑚2 × (𝑟1 × 𝑟2 )𝑛𝑚𝑜𝑑𝑛2 𝜀(𝑚1 + 𝑚2 , 𝑟1 × 𝑟2 ) = 𝜀(𝑚1 , 𝑟1 ) × 𝜀(𝑚2 , 𝑟2 ) Paillier is additively homomorphic sefiks.com/2023/04/03/a-step-by-step-partially-homomorphic-encryption-example-with-paillier-in-python/
  5. LightPHE A Hybrid Partially Homomorphic Encryption Library for Python •

    Open sourced at github.com/serengil/LightPHE under MIT license • Can be installed with command `pip install lightphe` • Wrapping RSA, ElGamal, Exponential ElGamal, Elliptic Curve ElGamal, Paillier, Damgard-Jurik, Okamoto–Uchiyama, Benaloh, Naccache–Stern, Goldwasser–Micali • Stars are welcome! sefiks.com @serengil @sefiks serengil LightPHE
  6. PHE vs FHE • Notably faster • Demands fewer computational

    resources • Generating much smaller ciphertexts • Distributing much smaller keys • Well-suited for memory-constrained environments • Strikes a favorable balance for practical use cases sefiks.com @serengil @sefiks serengil