-
Notifications
You must be signed in to change notification settings - Fork 484
ECC-step1: ASN.1 changes required for future ECC enhancements #309
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
Conversation
src/headers/tomcrypt_pk.h
Outdated
| /** Flag used to indicate optional items in ASN.1 sequences */ | ||
| int optional; | ||
| /** Flag used to indicate context specific tags on ASN.1 sequence items */ | ||
| unsigned char tag; |
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.
I'd say unsigned char is inappropriate here as
0is a valid context-specific tag- tags can be longer than 1 byte (yes this is currently nowhere taken into account so I think it's the time now to do it better)
I think we have two possibilities now:
- introduce a flags field that would then for now include Class and P/C of the ASN.1 identifier and optional of our implementation. Then have an
unsigned long tag;which is taken into account when Class indicates a context-specific tag. - we can use one of the signed types where
-1indicatesinvalid/unused
| /** The used flag, this is used by the CHOICE ASN.1 type to indicate which choice was made */ | ||
| int used; | ||
| /** Flag used to indicate optional items in ASN.1 sequences */ | ||
| int optional; |
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.
if we go for possibility 2 regarding the tag: How about starting to use <stdbool.h>? as this is clearly a boolean :-)
| } | ||
|
|
||
| /* some items may be optional during import */ | ||
| if (!list[i].used && list[i].optional) continue; |
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.
most likely a dumb comment, but ... we're taking the optional flag here into account and this function is called as well from der_encode_sequence_ex() where it is used to determine if we would BOF but der_encode_sequence_ex() itself ignores the optional flag...
| return der_decode_subject_public_key_info_ex(in, inlen, algorithm, public_key, public_key_len, | ||
| parameters_type, parameters, parameters_len, NULL); | ||
| } | ||
|
|
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 is a "private" function, just change the default signature and adapt all its invocations
2e58def to
c6a0cee
Compare
34cb489 to
22fc31b
Compare
22fc31b to
62291e0
Compare
|
I would like to have also the following commit as a part of this PR 6bb9661 I am not sure if it is worth to rename couple of things here to be more correct e.g.
|
62291e0 to
418e8b5
Compare
I first thought why not, now I think this change belongs to #187 as this would add code here which isn't used anywhere yet.
I think we should keep it like that as long there's not really a need and it still kinda completely represents the functionality :)
Do you see the need to make this public?
OID doesn't belong to DER, it's a general ASN.1 feature and it's spec'ed in X.660. As nobody knows X.660 (compared to X.509) I would propose to move
me neither |
|
OK, let's solve OID stuff later. To move forward we should polish/finetune and merge this PR to develop. |
yep, so let's get #335 ready and merged so we can finish this one |
418e8b5 to
3f7e2a9
Compare
|
@sjaeckel could you please rebase |
3f7e2a9 to
87899ec
Compare
done, doc&some tests still missing but hopefully I'll finish that in the next days |
|
Thank you, I have also rebased other ECC branches so that now we have the following chain:
I still need to adjust the new import/export functions in "ECC-step-3 #187" to your new API (I mean ecc_import_openssl, ecc_export_openssl and ecc_import_pkcs8). |
7217f44 to
19cabc1
Compare
|
That should be it, please feel free to review. |
|
@sjaeckel the following simple ASN1 sequence somehow confuses void *x, *y;
ltc_asn1_list seq[2];
unsigned char der[] = {
0x30,0x41,0x02,0x84,0x7f,0xff,0xff,0xff,0x1e,0x41,0xb4,0x79,0xad,0x57,0x69,
0x05,0xb9,0x60,0xfe,0x14,0xea,0xdb,0x91,0xb0,0xcc,0xf3,0x48,0x43,0xda,0xb9,
0x16,0x17,0x3b,0xb8,0xc9,0xcd,0x02,0x1d,0x00,0xad,0xe6,0x59,0x88,0xd2,0x37,
0xd3,0x0f,0x9e,0xf4,0x1d,0xd4,0x24,0xa4,0xe1,0xc8,0xf1,0x69,0x67,0xcf,0x33,
0x65,0x81,0x3f,0xe8,0x78,0x62,0x36
};
mp_init_multi(&x, &y, NULL);
LTC_SET_ASN1(seq, 0, LTC_ASN1_INTEGER, x, 1UL);
LTC_SET_ASN1(seq, 1, LTC_ASN1_INTEGER, y, 1UL);
der_decode_sequence(der, sizeof(der), seq, 2); |
|
What about to simplify this: to something like: I would also prefer shorter names for macros/constants (e.g. LTC_ASN1_CL_CONTEXT_SPECIFIC, LTC_ASN1_PC_CONSTRUCTED) |
I'll have a look into the crash, that shouldn't happen, but even
proposals? TBH I prefer speaking macros/enum names instead of cryptic abbreviations, but probably someone else can come up with something better... and regarding the length... well auto-completion does the typing for me in these cases... regarding |
251b7b6 to
498291a
Compare
As `der_decode_asn1_length()` will now also decode a uint64 with all 0xff the old style would overflow in that check which "wouldn't be good"^TM. The old way the length-checks were written were kind of fine when building on 64bit architectures, but have the same problem on 32bit.
This merges der_decode_sequence_ex() into a new der_decode_custom_type_ex() which can decode SEQUENCEs, SETs and custom types.
498291a to
d89326b
Compare
[edited by @sjaeckel]
re-work OID handlingwill be done later(c.f. ECC-step1: ASN.1 changes required for future ECC enhancements #309 (comment))This breaks backwards compatibility as it removes
LTC_ASN1_CONSTRUCTEDandLTC_ASN1_CONTEXT_SPECIFICwhich were somehow nonsense anyways...Please review as there's some new code, biggest parts of the
der_*_custom_type.cfiles are c&p fromsequence.If you don't like some of the naming feel free to propose something better!
All comments very welcome!