Skip to content

Slow Public Key Generation #673

Description

@therealOri

Introduction

So, As the title says, I am trying to generate a key using the following.
key = ElGamal.generate(4098, Random.new().read)

And it's been about an hour now and it still isn't done..

I am using pycryptodomex as perhaps maybe it'd be a bit faster or maybe something would be different, but I can confirm that it doesn't matter if I use pycryptodome or pycryptodomex. It's just not generating a key.




Here is my code:

import os
from Cryptodome import Random
from Cryptodome.Random import random
from Cryptodome.PublicKey import ElGamal
from Cryptodome.Util.number import GCD

def clear():
	os.system('clear||cls')


clear()
message = input("Message to encrypt: ")
bmsg = bytes(message, 'utf-8')
clear()

print('Generating key...Please be patient...')
key = ElGamal.generate(4098, Random.new().read) # <--- Code never gets past this point. It's been 1hr+...
clear()

# debugging
print(key) # <--- This is never called/executed.
input()

while 1:
    k = random.StrongRandom().randint(1, key.p - 1)

    if GCD(k, key.p - 1) == 1:
        break

h = key.encrypt(bmsg, k)
print(h)
d = key.decrypt(h)
print(d)

What I am trying to achieve here is an encrypted message (just playing around with stuff). And a decrypted message.
However, I am never able to get to the rest of the code to be able to test things and mess around as the key just never generates.

Any info on why this may be the case would be very helpful and if you have any ways to fix this, It'd also be really helpful and i'd appreciate it.




Extra info:

version:

  • pycryptodomex==3.15.0

System Info: (from neofetch)

  • OS: Manjaro Linux x86_64
  • Host: HP Pavilion Laptop 15-cs2xxx
  • Kernel: 5.15.72-1-MANJARO
  • CPU: Intel i7-8565U (8) @ 4.600GHz
  • GPU: Intel WhiskeyLake-U GT2 [UHD Graphics 620]
  • Memory: 5166MiB / 7835MiB (laptop has 8GB of ram)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions