- Notifications
You must be signed in to change notification settings - Fork2.8k
Added a function that decompresses EC public keys#521
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
deade1e commentedNov 5, 2016
bump |
mwarning commentedJul 3, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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.. |
deade1e commentedJul 3, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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 :) |
mwarning commentedJul 3, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@pfrankw: I am no crypto expert at all. :-) Anyway, I pushed my code herehttps://github.com/mwarning/mbedtls_ecp_compression, but in this new test environment, the code fails rather often. So there is definitely a (memory?) bug. |
mwarning commentedJul 3, 2017
@pfrankw do you know if mod P needs to be performed after every mpi operation? |
mwarning commentedJul 4, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
mwarning commentedJul 5, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Ok, I was able to fix my code :-) |
deade1e commentedJul 7, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Thank you very much@mwarning ! |
mwarning commentedJul 7, 2017
@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 :-) |
mwarning commentedJul 7, 2017
Relevant:#861 |
deade1e commentedJul 8, 2017
I have seen the code and made a pull request (mwarning/mbedtls-ecp-compression#1) about one superfluous operation. |
mpg left a comment
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>intmain(void){constmbedtls_ecp_curve_info*info;mbedtls_ecp_groupgrp;mbedtls_mpi_uintr;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 4brainpoolP512r1: p = 3 mod 4secp384r1: p = 3 mod 4brainpoolP384r1: p = 3 mod 4secp256r1: p = 3 mod 4secp256k1: p = 3 mod 4brainpoolP256r1: p = 3 mod 4secp224r1: p = 1 mod 4secp224k1: p = 1 mod 4secp192r1: p = 3 mod 4secp192k1: p = 3 mod 4| /* | ||
| * Decompresses an EC Public Key | ||
| */ | ||
| intmbedtls_ecp_decompress_pubkey(constmbedtls_ecp_group*grp,constunsignedchar*input,size_tilen,unsignedchar*output,size_t*olen,size_tosize ){ |
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.
mpg commentedFeb 7, 2019
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