ECC-step3: extra import/export (ASN.1 related) #187
No reviewers
Labels
No labels
bug
duplicate
enhancement
feature
help wanted
improve API
invalid
needs documentation
not-planned
rtfm
stale
support
wishlist
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-libtom/libtomcrypt!187
Loading…
Reference in a new issue
No description provided.
Delete branch "pr/ecc-asn1-part"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This PR was extracted from #65
I have written this code in 2014 (just an excuse in case it starts to seem that I am not completely sure what these changes are good for).
The main reason for this patch was ASN.1 support for importing/exporting EC keys which are stored in ASN.1 structures using esoteric stuff like context specific tags and optional items in ASN.1 sequences.
You will notice on the first sight the ugly duplication in API that I have introduced (to keep backwards compatibility of "non *_ex" functions):
and
was this a bug before or this one now?
👍 I like this change!
https://github.com/libtom/libtomcrypt/pull/65#discussion_r108974027
fixed
Well, I am not sure.
Coverage decreased (-0.2%) to 87.605% when pulling c666bc4acd45c57cf9d30ddb75f0e5e323f648f6 on pr/ecc-asn1-part into
fbe7d222c3on develop.IIUC this implements context-specific tag encoding differently than in the flexi decoder (it's stored in
tagand we currently use theusedfield to store). Should we then also adjust the flexi decoder or is this not the same?Ad context-specific tag encoding - when I added
tagI probably did not notice thatusedmight already exist for the same reason.I am in no way an expert at ASN.1, when I created the patch back in 2014 the only goal was to be able to load/save EC keys which I somehow managed. But some parts are rather hacks/workarounds.
If you want some testing keys, go to https://github.com/DCIT/perl-CryptX/tree/master/t/data and take any of ECC related
*.derfiles.XMEMMOVE()?As of the comment on the
usedfield we could just re-use it instead of addingtag. Most likely it'd make sense to rename it to something else. Initially it was just kind of a hack so the struct definition won't change. As I don't see a way to somehow mangle theoptionalpart without changing the struct I think a rename would be fine.I'm also no expert at ASN.1 but I'll have a look when I have the time.
Would it probably make sense to split this PR up into two parts? One with the changes for
tagand one foroptionaland 'the rest'?Looking at the code I believe that missing
if (!ordered) { continue; }was a bugis this one correct? this looks fishy to me as the
usedfield is only used when decoding butder_length_sequence_ex()is used when encodingThe
der_length_sequence(which callsder_length_sequence_ex) is called during decoding - seeder_decode_sequence_ex.c.Possible theory: it seems that during decode operation I use
optionalto indicate that it is ok if the item is missing andusedto indicate whether it was really decoded.Yeah sure, I missed that. Sorry.
Now rebased on top of
ECC enhancements part 1 (curves y^2 = x^3 + ax + b)#236Can I extract this single change as a separate "small fix" PR?
sure!
UPDATE: this PR adds the following functions to the public API
@sjaeckel I want to load the following ASN.1 structure using your new API:
This seems to fail:
What is the right way?
@sjaeckel here is the ASN1 which I am trying to load:
Can you please read the doc and give feedback if it is sufficient to fix the issue?
My patch to
ecc_import_openssl()has this summary:I can also patch it but I'd like to know if the doc is good enough to understand what to do.
@sjaeckel we should rebase this one onto a develop
I have created a branch
pr/ecc-asn1-part-BACKUPbecause AFAIK you have some uncommitted stuff related to this PR.IIUC that's only 1 commit which is left
and I've already rebased locally, so go ahead
Don't you have some pkcs8 changes/improvements locally?
I have not done any coding in this PR/branche since you have asked me whether you can work on pkcs8. Therefore I think it would be better if you
push --forceyour local changes.yeah, but nothing ready for publishing yet as I didn't really have the time ...
OK, now rebased.
Is it worth splitting this PR into:
ecc_export_openssl+ecc_import_openssl+ecc_import_x509(which is IMO ready for being merged into develop, except maybe a discussion whether the name_opensslis proper here or we can find something better)ecc_import_pkcs8(here are definitely some opportunities for improvement + I think thersa_import_pkcs8deserves a similar facelift as well)?
@sjaeckel could you please review: ecc_export_openssl + ecc_import_openssl + ecc_import_x509?
@sjaeckel I have moved pkcs8 stuff to #403 - could you please review/approve what's left in this PR? (ecc_export_openssl + ecc_import_openssl + ecc_import_x509)
@ -0,0 +1,130 @@/* LibTomCrypt, modular cryptographic library -- Tom St DenisWhat do you think about factoring-out those tries in their own functions?
This would also allow to call
ecc_import_subject_public_key_info()fromecc_import_x509()instead of this multi-purpose import function.@ -0,0 +1,130 @@/* LibTomCrypt, modular cryptographic library -- Tom St DenisFrankly, it looks like too much work for more of less no gain. As it will not be part of public API we can change it any-time later.
My doubts here are more about whether
ecc_export_opensslorecc_export_<something_else>(and the same forecc_import_openssl) would be better. Or generally whether the new API is fine as changing/renaming it later will be a pain.As you can see from the code the available options for saving/loading an ecc key are pretty wide. For
ecc_import_opensslI have chosen the approach "load whatever DER the openssl is able to save" therefore the name and therefore a single, maybe slightly overloaded, import function.@ -0,0 +1,130 @@/* LibTomCrypt, modular cryptographic library -- Tom St DenisI think 30 minutes for a bit more readability is well invested.
Why I really did it was that I didn't like the fact that it would've been possible to import a private-key from a
SubjectPublicKeyInfo.@ -0,0 +1,130 @@/* LibTomCrypt, modular cryptographic library -- Tom St Denis👍 Looks good. Thank you.