This repository was archived by the owner on Apr 20, 2025. It is now read-only.
This repository was archived by the owner on Apr 20, 2025. It is now read-only.
Private key operations don't use CRT #163
Closed
Description
The private key operations:
Lines 270 to 300 in 4beb68d
Lines 440 to 453 in 4beb68d
Lines 29 to 53 in 4beb68d
Use simple pow(x, d, n)
operation to calculate the signature or decrypt a message. Because n
is composite, it's possible to use Chinese remainder theorem. This will speed up the private key operations by a factor of 2 up to 4.
I.e. Instead of doing:
pow(message, ekey, n)
the code should precompute values for the CRT (with d
used instead of ekey
as the private exponent):
d_p = d % (p - 1)
d_q = d % (q - 1)
q_inv = rsa.common.inverse(q, p)
and then it can compute the power modulo like so:
s1 = pow(message, d_p, p)
s2 = pow(message, d_q, q)
h = ((s1 - s2) * q_inv) % p
c = s2 + q * h
return c
(or course, as the CRT parameters are closely related to p and q, they should be considered part of the private key and treated accordingly)
Metadata
Metadata
Assignees
Labels
No labels