Skip to content

Commit

Permalink
Merge pull request #24 from serengil/feat-task-2905-bug-in-3072-bit-keys
Browse files Browse the repository at this point in the history
Feat task 2905 bug in 3072 bit keys
  • Loading branch information
serengil authored May 29, 2024
2 parents e3c49a7 + a7ea661 commit d24108a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pylint
pip install pylint==3.0.2
pip install black
pip install .
Expand Down
10 changes: 8 additions & 2 deletions lightphe/cryptosystems/ElGamal.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# built-in dependencies
import random
import math
import decimal
from typing import Optional

# 3rd party dependencies
import sympy

# project dependencies
from lightphe.models.Homomorphic import Homomorphic
from lightphe.commons.logger import Logger

Expand Down Expand Up @@ -45,7 +50,8 @@ def generate_keys(self, key_size: int):
p = sympy.randprime(100, 2 ** int(key_size / 2) - 1)

# picking a generator g
g = random.randint(2, int(math.sqrt(p)))
# g = random.randint(2, int(math.sqrt(p))) # reaches int limit for 3072-bit key
g = int(random.uniform(2, float(decimal.Decimal(p).sqrt())))

# picking a private key x
x = random.randint(1, p - 2)
Expand Down
7 changes: 6 additions & 1 deletion lightphe/cryptosystems/GoldwasserMicali.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,12 @@ def decrypt(self, ciphertext: list) -> int:
xp = i % p
xq = i % q

if pow(xp, int((p - 1) / 2), p) == 1 and pow(xq, int((q - 1) / 2), q) == 1:
# reaches int limit for 3072-bit key
# if pow(xp, int((p - 1) / 2), p) == 1 and pow(xq, int((q - 1) / 2), q) == 1:
if (
pow(xp, int((p - 1) // 2), p) == 1
and pow(xq, int((q - 1) // 2), q) == 1
):
m_binaries.append("0")
else:
m_binaries.append("1")
Expand Down

0 comments on commit d24108a

Please sign in to comment.