-
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
Added a function that decompresses EC public keys #521
Conversation
bump |
I was looking for this feature. :-) Some things I noticed:
@pfrankw I hope this helps somewhat. I'm not sure how the developers imagine how this feature should be included, if at all.. |
Hello :) Sadly I am not a crypto expert so my interpretation of the problem may be a bit uncorrect. Anyway thanks for the suggestions, I hope this feature will be added :) |
@pfrankw: I am no crypto expert at all. :-) Anyway, I pushed my code here https://github.com/mwarning/mbedtls_ecp_compression, but in this new test environment, the code fails rather often. So there is definitely a (memory?) bug. |
@pfrankw do you know if mod P needs to be performed after every mpi operation? |
Ok, I was able to fix my code :-)
|
Thank you very much @mwarning ! |
@pfrankw that would be great. Anyway, the best location might be to implement this feature here: https://github.com/ARMmbed/mbedtls/blob/development/library/ecp.c#L522 I do not know if the mbedtls devs prefer to have this feature. Afaik, TLS itself does not need it. So it would be nice to have a decision here. :-) Also, consider to implement a general square root algorithm, as this only works for this special kind of curve. have fun :-) |
Relevant: #861 |
I have seen the code and made a pull request (mwarning/mbedtls-ecp-compression#1) about one superfluous operation. |
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 your contribution. Unfortunately the chosen computation method doesn't work with all curves supported by Mbed TLS, and also some unit tests would be required (which would have caught that).
MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &zexp, &grp->P) ); // Z exponent | ||
MBEDTLS_MPI_CHK( mbedtls_mpi_add_int( &zexp, &zexp, 1 ) ); // Z exponent + 1 | ||
MBEDTLS_MPI_CHK( mbedtls_mpi_div_int( &zexp, 0, &zexp, 4 ) ); // Z exponent / 4 | ||
MBEDTLS_MPI_CHK( mbedtls_mpi_exp_mod( &y, &z, &zexp, &grp->P, 0 ) ); // Z^Zexp % P |
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 way of extracting square roots mod P only works for some Ps (those that are congruent to 3 mod 4), but will not work for all curves supported by Mbed TLS.
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.
@mpg what curves use Ps that are congruent to 3 mod 4? I would like to add that to my readme here: https://github.com/mwarning/mbedtls_ecp_compression
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.
It's easy to check:
#include "mbedtls/ecp.h"
#include <stdio.h>
int main(void)
{
const mbedtls_ecp_curve_info *info;
mbedtls_ecp_group grp;
mbedtls_mpi_uint r;
for( info = mbedtls_ecp_curve_list(); info->name != NULL; info++ )
{
mbedtls_ecp_group_init( &grp );
mbedtls_ecp_group_load( &grp, info->grp_id );
mbedtls_mpi_mod_int( &r, &grp.P, 4 );
printf( "%s: p = %u mod 4\n", info->name, (unsigned) r );
mbedtls_ecp_group_free( &grp );
}
}
then
% make lib && gcc -Iinclude p-mod-4.c library/libmbedcrypto.a -o p-mod-4 && ./p-mod-4 git|development|
secp521r1: p = 3 mod 4
brainpoolP512r1: p = 3 mod 4
secp384r1: p = 3 mod 4
brainpoolP384r1: p = 3 mod 4
secp256r1: p = 3 mod 4
secp256k1: p = 3 mod 4
brainpoolP256r1: p = 3 mod 4
secp224r1: p = 1 mod 4
secp224k1: p = 1 mod 4
secp192r1: p = 3 mod 4
secp192k1: p = 3 mod 4
/* | ||
* Decompresses an EC Public Key | ||
*/ | ||
int mbedtls_ecp_decompress_pubkey( const mbedtls_ecp_group *grp, const unsigned char *input, size_t ilen, unsigned char *output, size_t *olen, size_t osize ){ |
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 line length and the following indentation don't match our coding style.
Support for compressed format has been deprecated by RFC 8422 in the context of TLS, which reflects a more general sentiment in the ECC community to prefer uncompressed format. Also, implementing it correctly for all supported curves would require substantial code, impacting our footprint - and the present PR would require non-trivial rework (values of P not congruent to 3 mod 4, unit tests) before if would be ready for merge. At this point, we're unlikely to want to add that amount of code for a feature that's formally deprecated in TLS and being abandoned more generally, so I'm closing this PR. Thanks for your contribution and interest in Mbed TLS anyway. |
remove references to dtls from libsrtp
I implemented what was discussed on this thread: https://crypto.stackexchange.com/questions/20627/point-decompression-on-an-elliptic-curve