-
Notifications
You must be signed in to change notification settings - Fork 489
Description
Hi,
I would like to propose a set of changes to ECC part of libtomcrypt. I have already implemented all proposed changes in my something-like-fork of libtomcrypt which is available https://github.com/DCIT/perl-CryptX/tree/master/src/ltc
1/ Support for curves y^2 = x^3 + a*x + b
Currently libtomcrypt supports only y^2 = x^3 - 3*x + b.
Support for general case required changes to ltc_ecc_projective_dbl_point(), ltc_ecc_projective_add_point() and ltc_ecc_is_point() as you can see in my repo (please note that I have moved is_point function into a separate file ltc_ecc_is_point.c). Extending ltc_ecc_set_type + other small changes were also necessary.
2/ Support for compressed public keys
Already existing function ecc_ansi_x963_export() allows you to export EC public key in a format defined by X9.63 but only supports 'uncompressed' form.
I have added support for exporting compressed EC public keys (which was easy) as well as for import. The import part was a bit tricky as it was necessary to add mp_sqrtmod_prime to libtommath.
As I wanted to keep old interface I have created new functions:
- https://github.com/DCIT/perl-CryptX/blob/master/src/ltc/pk/ecc/ecc_export_raw.c
- https://github.com/DCIT/perl-CryptX/blob/master/src/ltc/pk/ecc/ecc_import_raw.c
NOTE: The new functions ecc_import_raw() / ecc_export_raw() also support import/export of private key (raw octects)
My implementation of mp_sqrtmod_prime (based on Tonelli–Shanks algorithm) is available here:
3/ DER format compatible with openssl
To support importing/exporting keys in DER format compatible with openssl we need to support the following:
- private key format: http://tools.ietf.org/html/rfc5915
- public key format: http://tools.ietf.org/html/rfc5480
Again, I wanted to keep old interface so I have created new functions:
- https://github.com/DCIT/perl-CryptX/blob/master/src/ltc/pk/ecc/ecc_import_full.c
- https://github.com/DCIT/perl-CryptX/blob/master/src/ltc/pk/ecc/ecc_export_full.c
A small trouble was with adding support for OPTIONAL items in ASN.1 sequences. A big trouble was with private keys which uses ASN.1 context specific tags which are not supported by current libtomcrypt. This part is more a hack/workaround than a systematic support but fully follow ASN.1 specification is not easy.
See the changes at https://github.com/DCIT/perl-CryptX/commits/master/src/ltc/pk/asn1
As my changes to libtomcrypt + libtommath are are quite huge I am not sending them as a pull request. However if you find it worth to be included in upstream libtomcrypt I can fork develop branch a port my changes (I mean those you will agree with) into it.
Any feedback welcome.
Karel