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
9 * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
14 @file der_length_sequence.c
15 ASN.1 DER, length a SEQUENCE, Tom St Denis
21 Get the length of a DER sequence
22 @param list The sequences of items in the SEQUENCE
23 @param inlen The number of items
24 @param outlen [out] The length required in octets to store it
25 @return CRYPT_OK on success
27 int der_length_sequence(ltc_asn1_list *list, unsigned long inlen,
28 unsigned long *outlen)
31 unsigned long size, x, y, z, i;
34 LTC_ARGCHK(list != NULL);
35 LTC_ARGCHK(outlen != NULL);
37 /* get size of output that will be required */
39 for (i = 0; i < inlen; i++) {
44 if (type == LTC_ASN1_EOL) {
49 case LTC_ASN1_BOOLEAN:
50 if ((err = der_length_boolean(&x)) != CRYPT_OK) {
56 case LTC_ASN1_INTEGER:
57 if ((err = der_length_integer(data, &x)) != CRYPT_OK) {
63 case LTC_ASN1_SHORT_INTEGER:
64 if ((err = der_length_short_integer(*((unsigned long *)data), &x)) != CRYPT_OK) {
70 case LTC_ASN1_BIT_STRING:
71 if ((err = der_length_bit_string(size, &x)) != CRYPT_OK) {
77 case LTC_ASN1_OCTET_STRING:
78 if ((err = der_length_octet_string(size, &x)) != CRYPT_OK) {
88 case LTC_ASN1_OBJECT_IDENTIFIER:
89 if ((err = der_length_object_identifier(data, size, &x)) != CRYPT_OK) {
95 case LTC_ASN1_IA5_STRING:
96 if ((err = der_length_ia5_string(data, size, &x)) != CRYPT_OK) {
102 case LTC_ASN1_PRINTABLE_STRING:
103 if ((err = der_length_printable_string(data, size, &x)) != CRYPT_OK) {
109 case LTC_ASN1_UTCTIME:
110 if ((err = der_length_utctime(data, &x)) != CRYPT_OK) {
116 case LTC_ASN1_UTF8_STRING:
117 if ((err = der_length_utf8_string(data, size, &x)) != CRYPT_OK) {
125 case LTC_ASN1_SEQUENCE:
126 if ((err = der_length_sequence(data, size, &x)) != CRYPT_OK) {
134 err = CRYPT_INVALID_ARG;
139 /* calc header size */
143 } else if (y < 256) {
146 } else if (y < 65536UL) {
147 /* 0x30 0x82 LL LL */
149 } else if (y < 16777216UL) {
150 /* 0x30 0x83 LL LL LL */
153 err = CRYPT_INVALID_ARG;
167 /* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/sequence/der_length_sequence.c,v $ */
168 /* $Revision: 1.13 $ */
169 /* $Date: 2006/11/26 02:25:18 $ */