Why RSA Decryption process takes longer time than the Encryption process?

后端 未结 8 757
长发绾君心
长发绾君心 2021-02-08 15:19

I have some idea that it is due to some complex calculation, but i want to know about what exactly happens which takes long time than the corresponding encryption process. Any l

8条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-08 15:22

    In theory, it doesn't have to be. The encryption and decryption algorithms are essentially identical. Given:

    d = decryption key
    e = encryption key
    n = modulus (product of primes)
    c = encrypted code group
    m = plaintext code group
    

    Then:

    1. Encryption ci = mie (mod n)
    2. Decryption mi = cid (mod n)

    The normal algorithm for raising to a power is iterative, so the time taken depends on the size of the exponent. In most cases, the pair works out with the decryption key being (usually considerably) larger than the encryption key.

    It is possible to reverse that though. Just for a toy example, consider:

    p=17
    q=23
    n=391
    

    Here's a list of some valid encryption/decryption key pairs for this particular pair of primes:

    e = 17, d = 145
    e = 19, d = 315
    e = 21, d = 285
    e = 23, d = 199
    e = 25, d = 169
    e = 27, d = 339
    e = 29, d = 85
    e = 31, d = 159
    e = 35, d = 171
    e = 37, d = 333
    e = 39, d = 343
    e = 41, d = 249
    e = 43, d = 131
    e = 45, d = 133
    e = 47, d = 15   
    e = 49, d = 273
    e = 51, d = 283
    e = 53, d = 93
    e = 57, d = 105
    e = 59, d = 179 
    

    Out of those 20 key pairs, only one has a decryption key smaller than the encryption key. In the other cases, the decryption key ranges from just under twice as big to almost 17 times as large. Of course, when the modulus is tiny like this, it's quick and easy to generate a lot of key pairs, so finding a small decryption key would be fairly easy -- with a real RSA key, however, it's not quite so trivial, and we generally just accept the first pair we find. As you can see from the list above, in that case, you're quite likely to end up with a decryption key that's considerably larger than your encryption key, and therefore decryption will end up slower than encryption. When working with ~100 digit numbers, we'd have to be quite patient to find a pair for which decryption was going to be (even close to) as fast as encryption.

提交回复
热议问题