-
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
Backport 2.x: Fix non-uniform random generation in a range #4276
Backport 2.x: Fix non-uniform random generation in a range #4276
Conversation
50fe56a
to
f8b66e3
Compare
f8b66e3
to
79d0b53
Compare
79d0b53
to
5201c52
Compare
I have rebased this pull request due to add/add conflicts with #4297. |
The prerequisite PR #4297 has now been merged, removing the label and changing the base branche twice in order to force-refresh github's cache. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks very good overall but I have a number of comments, mainly about readability / internal documentation, plus what looks like to typos in test data.
Thank you very much for cleanly isolating "moving code" in specific commits that do just that, it makes those commits so much easier to review with git show --color-moved --color-moved-ws=allow-indentation-change <commit>
(tip for the other reviewer).
71ea745
to
78c8e2b
Compare
78c8e2b
to
b9bbd14
Compare
1893e5b
to
ee340d9
Compare
The idiom "resize an mpi to a given size" appeared 4 times. Unify it in a single function. Guarantee that the value is set to 0, which is required by some of the callers and not a significant expense where not required. Signed-off-by: Gilles Peskine <[email protected]>
ee340d9
to
3130ce2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reviewed the changes (rebases and new commits) since my previous approval, and this looks good to me.
Signed-off-by: Gilles Peskine <[email protected]>
Signed-off-by: Gilles Peskine <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for addressing my comments. This looks good to me as well now.
mbedtls_mpi_read_binary{,_le} (in Mbed-TLS#4276) and mbedtls_mpi_read_string (in Mbed-TLS#4644) changed their behavior on an empty input from constructing an MPI object with one limb to not allocating a limb. In principle, this change should be transparent to applications, however it caused a bug in the library and it does affect the value when writing back out, so list the change in the changelog. Signed-off-by: Gilles Peskine <[email protected]>
mbedtls_mpi_read_binary{,_le} (in Mbed-TLS#4276) and mbedtls_mpi_read_string (in Mbed-TLS#4644) changed their behavior on an empty input from constructing an MPI object with one limb to not allocating a limb. In principle, this change should be transparent to applications, however it caused a bug in the library and it does affect the value when writing back out, so list the change in the changelog. Signed-off-by: Gilles Peskine <[email protected]>
mbedtls_mpi_read_binary{,_le} (in Mbed-TLS#4276) and mbedtls_mpi_read_string (in Mbed-TLS#4644) changed their behavior on an empty input from constructing an MPI object with one limb to not allocating a limb. In principle, this change should be transparent to applications, however it caused a bug in the library and it does affect the value when writing back out, so list the change in the changelog. Signed-off-by: Gilles Peskine <[email protected]>
mbedtls_mpi_read_binary{,_le} (in Mbed-TLS#4276) and mbedtls_mpi_read_string (in Mbed-TLS#4644) changed their behavior on an empty input from constructing an MPI object with one limb to not allocating a limb. In principle, this change should be transparent to applications, however it caused a bug in the library and it does affect the value when writing back out, so list the change in the changelog. Signed-off-by: Gilles Peskine <[email protected]>
mbedtls_mpi_read_binary{,_le} (in Mbed-TLS#4276) and mbedtls_mpi_read_string (in Mbed-TLS#4644) changed their behavior on an empty input from constructing an MPI object with one limb to not allocating a limb. In principle, this change should be transparent to applications, however it caused a bug in the library and it does affect the value when writing back out, so list the change in the changelog. Signed-off-by: Gilles Peskine <[email protected]>
mbedtls_ecp_gen_privkey
and extract the part that generates a random number uniformly in a range [2, P-1].mbedtls_mpi_random
to generate a random number uniformly in a range [m, P-1] with m small.dhm.c
.mbedtls_mpi_random
in places where a random number was generated in a non-uniform way (key generation and blinding in both ECP and DHM). Fix [BUG] Bias in private key generation in Diffie-Hellman #4245.Needs backports: yes, the non-uniform generation should be fixed in 2.16. However, the refactorings in this pull request are far too invasive for an LTS branch, so we need to figure out a more targeted fix in 2.16.
Given the complexity of this PR, I'll make the 3.0 forward-port once it has two approvals.
There is a conflict with #4297 because both introduce
library/ecp_invasive.h
. Since #4297 fixes newly-introduced bugs, it should go in first, then this PR should be rebased. The conflict is trivial so this PR can be reviewed even before the rebase.