If we are given a message m, we can encrypt and decrypt the message using the
public and private keys of a user.
Encryption: Cipher text is computed by:
c = me mod n
Decryption: The original message is computed by:
p = cd mod n
How do we know that the decrypted message p is the same as the original message m? We can use Euler's theorem:
We can also use RSA to cryptographically sign messages. We do this by computing a cryptographic hash (like MD5 or SHA1) on a message m to obtain a digest, which we'll call s. Then the signed digest is computed as r = sd mod n. Then the public can verify that the message is properly signed if re mod n==s.
Normally you want to keep information about your keys private. However, if you know the factorization of n, then you have an advantage. You can use the Extended GCD. The EGCD is like the GCD, but it gives three outputs, w, z, and g. The value g = GCD(x,y), while EGCD also finds
w*x + z*y = gSo that if we ask for EGCD(e, phi(n)), we know that g=1 with high probability. (g=1 means that e and phi(n) are coprime. In the unlikely circumstance that g > 1, just choose another random e and try again.) and we get
w*e + z*phi(n) = g = 1where w is the multiplicative inverse mod phi(n). We use w as the secret decryption exponent (usually called d).
If you wanted to get access to the crypto keys in the library, how could you do that? Having access to the system helps. It turns out that you can compute statistics on the time and/or power required for the processor to compute crypto routines by running the routines many times. Those statistics can give insight into finding the values of the keys. Next time we will see more on how this is done. Until then, here is the code to compute exponentiation mod n.
Int modexp(x, e, n) {
Int y = 1, z = x;
while (e != 0) {
if (e is odd) {
y = y * z mod n;
}
z = z * z mod n;
e = e div 2;
}
return y;
}
bsy+cse127w02@cs.ucsd.edu, last updated
email bsy.