
The Carmichael Function
The Carmichael Function 관련
The Carmichael Function, represented by , also known as the reduced totient or least universal exponent, is defined as the smallest positive integer such that for every integer a co-prime to , .
To put this in easy terms, is the exponent of the multiplicative group modulo (the least common multiple of the orders of all elements). For RSA-style moduli (product of primes), the Carmichael function is guided by the formula:
where with and being the large primes.
You may now understand the Carmichael function better if we put it in the following way: is the least common multiple of of each prime power dividing . So for a prime , , and for two primes, we take the of and .
Mathematical Implication of The Carmichael function
The Carmichael function is a “tighter” bound. What this means is that divides (since the exponent of a finite group always divides the group order by Lagrange’s Theorem[1])
If and are both odd primes, then and are even, so their least common multiple is roughly half of . Mathematically:
We can observe that this is lesser than or equal to and often considerably smaller. This means provides the minimal exponent needed for RSA’s correctness, whereas might be a larger number that still works but isn’t necessary.
When you choose two large random primes and , you have:
because for large primes, the subtracted ones make only a small difference compared to and themselves.
Now, since both and are even, they each have a factor of . If those are their only common factors (which is often the case for random primes), then:
When you compute the private exponent as the modular inverse of e (a small number) modulo versus modulo , the range from which is chosen is roughly twice as large in the former case. That means the typical when computed modulo can be about twice as large as when computed modulo . A larger means that during decryption (or signing) the modular exponentiation cdmodn takes slightly more time.
Intuitively, using ensures we don’t “overshoot” the exponent required for the modular arithmetic to cycle back to 1. A smaller makes every RSA decryption and signature operation faster. For instance, if is roughly half of , then will have one less bit than it would otherwise, cutting the exponentiation work by about 50%. This is a free performance gain, as we aren’t changing the security assumptions or the key size , just using the mathematically tight value for the exponent. The RSA algorithm’s security is not weakened by this and now the is different but functionally equivalent.
The Carmichael Function in Modern Implementations
The critical property for RSA () is both necessary and sufficient for correct decryption, thanks to Carmichael’s theorem. So there’s no need for to also satisfy the stronger condition modulo .
By switching to computing modulo (i.e., ), we directly get the smallest working private exponent. Ronald Rivest himself noted this optimization in his 1999 seminal paper[2], stating that solving for using instead of is slightly preferable because it can result in a smaller value for .
Over time, the use of in RSA moved from an academic suggestion to an industry standard. Today’s cryptographic standards explicitly acknowledge or require the approach.
For example, the official RSA standard (PKCS #1 v2.2, RFC 8017[3]) defines the RSA key generation in terms of . It specifies that the private exponent is chosen such that (with ). In other words, PKCS #1 expects the Carmichael function to be used for the modulus of the exponent. Likewise, NIST’s FIPS 186-4 (Digital Signature Standard) mandates that be less than .
Any RSA key where is larger than is considered non-compliant in those strict contexts. This effectively forces implementations to use the smaller -based exponent, since any “oversized” can be reduced mod to meet the criterion.
Standards such as FIPS 186-4[4] (the Digital Signature Standard) and RFC 8017[3:1] (which specifies PKCS#1 v2.2 for RSA Cryptography) include requirements or recommendations that imply the private exponent should be as small as possible and ideally less than . Using (the least common multiple of and ) directly produces the smallest valid d, whereas using often results in a that is larger than necessary. This not only improves performance (by reducing the number of modular multiplications needed during decryption/signing) but also helps maintain interoperability with protocols that expect to be below a certain size.
The Python cryptography library (PyCA cryptography) explicitly documents[5] that it uses Carmichael’s totient to generate the “smallest working value of ,” noting that older implementations (including the original RSA paper) used Euler’s totient and ended up with larger exponents. OpenSSL also uses the Carmichael function in their low-level RSA API[6].
This shift to the Carmichael function ensures that under the hood your RSA key is a bit more efficient than the ones from the late 1970s while providing the same level of security.
Ronald L. Rivest, Robert D. Silverman: Are Strong Primes Needed for RSA? ↩︎
RFC 8017 PKCS #1: RSA Cryptography Specifications ↩︎ ↩︎
FIPS 186-5: Digital Signature Standard (DSS) ↩︎
OpenSSL Github (
openssl/openssl
):rsa_chk.c
↩︎