1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
3 * LibTomCrypt is a library that provides various cryptographic
4 * algorithms in a highly modular and flexible manner.
6 * The library is free for all purposes without any express
12 @file der_length_sequence.c
13 ASN.1 DER, length a SEQUENCE, Tom St Denis
19 Get the length of a DER sequence
20 @param list The sequences of items in the SEQUENCE
21 @param inlen The number of items
22 @param outlen [out] The length required in octets to store it
23 @return CRYPT_OK on success
25 int der_length_sequence(ltc_asn1_list *list, unsigned long inlen,
26 unsigned long *outlen)
28 return der_length_sequence_ex(list, inlen, outlen, NULL);
31 int der_length_sequence_ex(ltc_asn1_list *list, unsigned long inlen,
32 unsigned long *outlen, unsigned long *payloadlen)
36 unsigned long size, x, y, i, z;
39 LTC_ARGCHK(list != NULL);
40 LTC_ARGCHK(outlen != NULL);
42 /* get size of output that will be required */
44 for (i = 0; i < inlen; i++) {
49 if (type == LTC_ASN1_EOL) {
54 case LTC_ASN1_BOOLEAN:
55 if ((err = der_length_boolean(&x)) != CRYPT_OK) {
61 case LTC_ASN1_INTEGER:
62 if ((err = der_length_integer(data, &x)) != CRYPT_OK) {
68 case LTC_ASN1_SHORT_INTEGER:
69 if ((err = der_length_short_integer(*((unsigned long *)data), &x)) != CRYPT_OK) {
75 case LTC_ASN1_BIT_STRING:
76 case LTC_ASN1_RAW_BIT_STRING:
77 if ((err = der_length_bit_string(size, &x)) != CRYPT_OK) {
83 case LTC_ASN1_OCTET_STRING:
84 if ((err = der_length_octet_string(size, &x)) != CRYPT_OK) {
94 case LTC_ASN1_OBJECT_IDENTIFIER:
95 if ((err = der_length_object_identifier(data, size, &x)) != CRYPT_OK) {
101 case LTC_ASN1_IA5_STRING:
102 if ((err = der_length_ia5_string(data, size, &x)) != CRYPT_OK) {
108 case LTC_ASN1_TELETEX_STRING:
109 if ((err = der_length_teletex_string(data, size, &x)) != CRYPT_OK) {
115 case LTC_ASN1_PRINTABLE_STRING:
116 if ((err = der_length_printable_string(data, size, &x)) != CRYPT_OK) {
122 case LTC_ASN1_UTCTIME:
123 if ((err = der_length_utctime(data, &x)) != CRYPT_OK) {
129 case LTC_ASN1_GENERALIZEDTIME:
130 if ((err = der_length_generalizedtime(data, &x)) != CRYPT_OK) {
136 case LTC_ASN1_UTF8_STRING:
137 if ((err = der_length_utf8_string(data, size, &x)) != CRYPT_OK) {
145 case LTC_ASN1_SEQUENCE:
146 if ((err = der_length_sequence(data, size, &x)) != CRYPT_OK) {
153 case LTC_ASN1_CHOICE:
154 case LTC_ASN1_CONSTRUCTED:
155 case LTC_ASN1_CONTEXT_SPECIFIC:
157 err = CRYPT_INVALID_ARG;
162 /* calc header size */
166 } else if (y < 256) {
169 } else if (y < 65536UL) {
170 /* 0x30 0x82 LL LL */
172 } else if (y < 16777216UL) {
173 /* 0x30 0x83 LL LL LL */
176 err = CRYPT_INVALID_ARG;
181 if (payloadlen) *payloadlen = z;
191 /* ref: $Format:%D$ */
192 /* git commit: $Format:%H$ */
193 /* commit time: $Format:%ai$ */