How to encode [0] IMPLICIT SET OF? #622
Labels
No labels
bug
duplicate
enhancement
feature
help wanted
improve API
invalid
needs documentation
not-planned
rtfm
stale
support
wishlist
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-libtom/libtomcrypt#622
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
Prerequisites
LTC_ARGCHK 'ltc_mp.name != NULL' failure ...). c.f. Ch. "Math Descriptors" of the developer manual.Description
How can I construct, using libtomcrypt release 1.18.2, a struct of type
ltc_asn1_listthat, when nested inside a SEQUENCE and encoded, will produce an encoded DER SET OF with an IMPLICIT CONTEXT SENSITIVE [0] tag (as in CMS SignedData certificates, for example)?If I set
list.type = LTC_ASN1_SETOF, I get a properly encoded SET but the tag is 0x31 (UNIVERSAL SET). I can manually change the tag after encoding to 0xA0, except that the SET is nested inside layers of ASN.1 data. If I uselist.type = LTC_ASN1_CUSTOM_TYPE, I can get the tag I want, but the functionder_encode_custom_type()encodes the items like a SEQUENCE, not in sorted order like a DER SET. If I use the macroLTC_SET_ASN1_CUSTOM_CONSTRUCTED, I can nest a SET inside a custom typed SEQUENCE, creating an EXPLICIT tag.Am I missing something? Is there a solution in the latest developer version? It seems that I must either change the tag manually after encoding, or else pre-sort the items manually within the array
list.data. A fix would be to look duringder_encode_custom_type()forlist.used=LTC_ASN1_SETOF.Steps to Reproduce
Version
Release 1.18.2
Additional Information
It's possible that this currently can't be done with any ltc version.
Can you provide an example "CMS SignedData certificate" in encoded format (i.e. the expected output)?
The CMS spec RFC 5652 uses a CONTEXT SENSITIVE [0] IMPLICIT SET OF for the certificates member of a SignedData structure. A second example in CMS is the signedAttrs member of a SignerInfo structure.
But, maybe a toy example will be more useful here. In the example below, the integers are sorted by their DER encoding. This is implemented in
der_encode_setof()but it isn't called fromder_encode_custom_type().When the data type
LTC_ASN1_CUSTOM_TYPErepresents a primitive ASN.1 data type, the memberusedindicates the structure of thedatamember. Maybe that API could work also for a constructed ASN.1 data type, to distinguish SEQUENCE, SET and SET OF.The function
der_encode_set()overwrites the memberltc_asn1_list.used, then passes the list to the functionder_encode_sequence_ex(). Maybeder_encode_set()should use the memberltc_asn1_list.optionalinstead for set ordering.It wouldn't be a bad idea to modify
ltc_asn1_listto use an anonymous union to rename the membersusedandoptional(for decoding) tocustom_typeandset_order(for encoding).I just had a look at #624, and it does appear to answer this issue.