-
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
mbedtls_ecp_group_cmp in test_suite_ecp is fragile #6707
Comments
Can I Take This Issue ? @gilles-peskine-arm I want to contribute to this issue |
@bleakprestiger Sure, thanks! |
@gilles-peskine-arm, I have opened a PR - (#6715). |
The code managing Regarding the implications here, it should be noted that the situations in 3.x and 2.28 are very different. The situation in 3.0
Not really. The code that may set I fully intend to remove this non-trivially-dead code: not only does it harm readability, it also prevents us from making So, I believe in 3.0 it is fully correct compare T by reference when comparing groups. Currently, it's correct for reasons that are not obvious at all from reading the code, and after I've cleaned up the code, it should be obviously correct: for Montgomery it's always The situation in 2.28In 2.28 we don't have static arrays in From a quick look at the test code, it happens to work only because it's only called on groups that were never used for multiplying I think in 2.28 we should fix the test code: |
In
test_suite_ecp
, there's a functionmbedtls_ecp_group_cmp
(added in 3.2 but backported to 2.28) which compares two group structures. It compares by value except forT
which is compared by reference. This looks wrong.The goal of this issue is to compareT
by value.Actually, diving deeper, I think that comparing
T
by address is correct, but under some assumption about whenmbedtls_ecp_group_cmp
is called.T
is not a value like the other fields, it's a pointer to a cache. The cache should be shared between all the instances of ambedtls_ecp_group_cmp
structure. Looking at how group structures are constructed:ecp_use_curve25519
orecp_use_curve448
setgrp->T_size = 0
andgrp->T = NULL
.ecp_load_group
setgrp->T
to a pointer to static data, andgrp->T_size = 0
to indicate that the group structure does not own the memory thatT
points to.So initially comparing the
T
pointers is correct. However, afterecp_mul_comb
has been called,grp->T
may be set to some dynamically allocated memory. After that,grp->T
is unique. I don't thinkmbedtls_ecp_group_cmp
is intended to validate the contents of the cache. But now I don't understand how the tests usingmbedtls_ecp_group_cmp
are passing — shouldn't each group have its ownT
?The goal of this issue is to understand what's going on and document it. (And fix if it turns out something needs fixing.)
The text was updated successfully, but these errors were encountered: