RSA
RSA, which is an abbreviation of the author's names (Rivest–Shamir–Adleman), is a cryptosystem which allows for asymmetric encryption. Asymmetric cryptosystems are alos commonly referred to as Public Key Cryptography where a public key is used to encrypt data and only a secret, private key can be used to decrypt the data.
Definitions
- The Public Key is made up of
- The Private Key is made up of
- The message is represented as
and is converted into a number - The encrypted message or ciphertext is represented by
and are prime numbers which make up is the public exponent is the modulus and its length in bits is the bit length (i.e. 1024 bit RSA) is the private exponent- The totient
is used to compute and is equal to the , another definition for is that
What makes RSA viable?
If public
Note
The triple equals sign in this case refers to modular congruence which in this case means that there exists an integer k such that
RSA is viable because it is incredibly hard to find
Implementation
RSA is implemented in 3 steps:
Key Generation
We are going to follow along Wikipedia's small numbers example in order to make this idea a bit easier to understand.
Note
In this example we are using Carmichael's totient function where
but Euler's totient function is perfectly valid to use with RSA. Euler's totient is
- Choose two prime numbers such as:
and
- Find
: -
Calculate
-
Choose a public exponent such that
and is coprime (not a factor of) . The standard is most cases is , but we will be using: - Calculate
as the modular multiplicative inverse or in english find such that:
Now we have a public key of
Encryption
With the public key,
The ciphertext is equal to
Decryption
With the private key,
The plaintext is equal to
Exploitation
From the RsaCtfTool README
Attacks:
- Weak public key factorization
- Wiener's attack
- Hastad's attack (Small public exponent attack)
- Small
- Common factor between ciphertext and modulus attack
- Fermat's factorisation for close
and - Gimmicky Primes method
- Past CTF Primes method
- Self-Initializing Quadratic Sieve (SIQS) using Yafu
- Common factor attacks across multiple keys
- Small fractions method when p/q is close to a small fraction
- Boneh Durfee Method when the private exponent d is too small compared to the modulus (i.e
) - Elliptic Curve Method
- Pollards
for relatively smooth numbers - Mersenne primes factorization