Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat task 2905 bug in 3072 bit keys #24

Merged
merged 2 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading