Search code examples
cryptographyrsapublic-key-encryptionpycrypto

PyCrypto: How much random data is considered secure?


I'm using the RSA implementation in PyCrypto. With regard to the encrypt(self, plaintext, K) method K is a parameter of random data. I want to know how much random data needs to be passed in order for the encryted data to be considered secure. For example in my implementation I am passing a strong prime number of 1024 bits via the Crypto.Util.number module like so:

enc_data = public_key.encrypt(data, number.getPrime(1024))

Is this considered 'secure enough'?

Thanks


Solution

  • The RSA implementation does not use the K parameter. You may ignore it; the RSA implemention does.

    Looking at lines 59-60 of pycrypto-2.3/lib/Crypto/PublicKey/RSA.py you see the following:

    def _encrypt(self, c, K):
        return (self.key._encrypt(c),)
    

    Which proves that K, if supplied, is ignored.

    Official documentation

    Plus, the developers declare this explicitly in the documentation. In fact, if you create a public key public_key and you type

    help(public_key.encrypt)
    

    you will obtain their documentation, which explicitly says:

    encrypt(self, plaintext, K) method of Crypto.PublicKey.RSA._RSAobj instance
    Encrypt a piece of data with RSA.
    
    ...
    ...
    
    :Parameter K: A random parameter (*for compatibility only. This
     value will be ignored*)
    :Type K: byte string or long