In RFC 8017 modBits
is the length in bits of the RSA modulus n
I am using 2048 RSA key
modBits
= 2048?
modBits
= 2048 % n
?
lets say n
= 10 decimal = 1010 binary
then modBits
= 4?
in my 2048 RSA key DER file n
uses 257 bytes
then modBits
= 257 *8 ?
which modBits
= ... is true?
1 Answer
$\text{modBits}$ is the length of RSA modulus $n$ for example if you have 17 as RSA modulus than it has $\texttt{10001}$ as base two representation and has $\text{modBits} = 5$
If you generate a modulus $n$ which is 2048-bit than the $\text{modBits} = 2048$. Keep in mind that, we say a number $n$ is 2048-bit when it is between $2^{2047} \leq n \leq 2^{2048}-1$
lets say n = 10 decimal = 1010 binary then modBits = 4?
Yes 4.
in my 2048 RSA key PEM file n uses 257 bytes then modBits = 257 *8 ?
The leading 00
is coming from ASN.1 encoding of integers. Therefore you have 256-byte key.
which one is the value of modBits?
8*256
-
$\begingroup$ this question
which one is the value of modBits?
is referring to which of all modBits = ? is the true one, not which DER file data definesn
$\endgroup$– porenteCommented Oct 26, 2019 at 19:15 -
$\begingroup$ Isn't clear? One byte is 00, this is part of the encoding. $\endgroup$– kelalakaCommented Oct 26, 2019 at 19:31
-
$\begingroup$ my question shows different values that
modBits
can have based on the RFC definition, then at the end asks which value is true, in your answermodBits = 8*256 if n uses 256 bytes
andmodBits = 4 if n = 10
butmodBits = 8*256 if n uses 256 bytes
is not true because the exact value ofn
isn't known, only if you know the exact value ofn
you can knowmodBits
$\endgroup$– porenteCommented Oct 26, 2019 at 19:54 -
$\begingroup$ That is why I've asked your file. $\endgroup$– kelalakaCommented Oct 26, 2019 at 19:55
-
1$\begingroup$ @porente If you know it all so well, then why post a question? Kelalaka is right, to show how the encoded key is structured, you should post an example private key that contains the modulus. $\endgroup$– Maarten Bodewes ♦Commented Oct 26, 2019 at 20:23
n
uses 257 bytes and yesn
has a 00 in the left most byte $\endgroup$