-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rsa_get_bitlen does not return correct number of bits #868
Comments
ARM Internal Ref: IOTSSL-1672 |
Whilst this is true the function in question is not part of the public API and is only used internally. This is not something we are looking to change in the near future and so will close this issue. |
What do you mean this isn't part of the public API? What other function is there to get key metadata? |
The public API is broadly what is in
|
|
@tom-daubney-arm As @jethrogb notes, this does have an impact on the public API. This limitation of RSA (no function to get the correct bit length) also restricts the PSA code: it refuses to create RSA keys whose bit-length is not a multiple of 8. I don't know how to interpret the fact that we've never lifted this limitation: either it shows that it's still relevant (since it applies to PSA and not just to classic APIs), or it shows that it's not important (since we've never bothered to fix it). One thing that made me not push to fix it is that we have a history of bugs around non-byte-aligned keys, with incorrect calculations of padding sizes which led at least once to a buffer overflow. On the other hand, functionally, it's a very easy fix. We'd just need to add |
So I'm reopening this issue, because it's a genuine bug. Maybe we don't intend to fix it (though it's not clear to me at this point whether anyone has made this decision with an understanding of the problem), but until we retire the corresponding API (which could mean until RSA is sufficiently restricted that you can't create non-byte-aligned keys anymore), it's a genuine, known bug so it should be documented by an open issue. |
This would break interoperability so I don't think that's a good direction for solutions. |
@jethrogb Our PSA interface blocks non-byte-aligned RSA modulus sizes and we haven't gotten any complaints so far. Have you encountered such keys in practice? In the HSM/SE world, a lot of implementations have even more stringent restrictions, like having to be of the form 2^n or 3*2^n. |
Generating 2046-bit keys and deserializing 2047-bit keys from PEM/DER both work fine in 2.28. Our HSM supports this. If 3.x no longer supports this we'll need to look at another crypto library as this would break backcompat. |
I will take this on and provide a fix |
@tom-daubney-arm Will this bug be fixed in the near future? |
@minosgalanakis does this fall into the MBEDTLS_PRIVATE work? |
@minosgalanakis I'm adding this to the |
mbedtls_pk_get_bitlen
rounds up the size of RSA keys to the nearest byte.The reason is that
rsa_get_bitlen
returns 8× the number of bytes required to store the modulus. This could be up to 7 bits higher than the actual number of bits.The text was updated successfully, but these errors were encountered: