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.org
16
@file der_length_sequence.c
17
ASN.1 DER, length a SEQUENCE, Tom St Denis
23
Get the length of a DER sequence
24
@param list The sequences of items in the SEQUENCE
25
@param inlen The number of items
26
@param outlen [out] The length required in octets to store it
27
@return CRYPT_OK on success
29
int der_length_sequence(ltc_asn1_list *list, unsigned long inlen,
30
unsigned long *outlen)
33
unsigned long size, x, y, z, i;
36
LTC_ARGCHK(list != NULL);
37
LTC_ARGCHK(outlen != NULL);
39
/* get size of output that will be required */
41
for (i = 0; i < inlen; i++) {
46
if (type == LTC_ASN1_EOL) {
51
case LTC_ASN1_INTEGER:
52
if ((err = der_length_integer(data, &x)) != CRYPT_OK) {
58
case LTC_ASN1_SHORT_INTEGER:
59
if ((err = der_length_short_integer(*((unsigned long *)data), &x)) != CRYPT_OK) {
65
case LTC_ASN1_BIT_STRING:
66
if ((err = der_length_bit_string(size, &x)) != CRYPT_OK) {
72
case LTC_ASN1_OCTET_STRING:
73
if ((err = der_length_octet_string(size, &x)) != CRYPT_OK) {
83
case LTC_ASN1_OBJECT_IDENTIFIER:
84
if ((err = der_length_object_identifier(data, size, &x)) != CRYPT_OK) {
90
case LTC_ASN1_IA5_STRING:
91
if ((err = der_length_ia5_string(data, size, &x)) != CRYPT_OK) {
97
case LTC_ASN1_PRINTABLE_STRING:
98
if ((err = der_length_printable_string(data, size, &x)) != CRYPT_OK) {
104
case LTC_ASN1_SEQUENCE:
105
if ((err = der_length_sequence(data, size, &x)) != CRYPT_OK) {
113
err = CRYPT_INVALID_ARG;
118
/* calc header size */
122
} else if (y < 256) {
125
} else if (y < 65536UL) {
126
/* 0x30 0x82 LL LL */
128
} else if (y < 16777216UL) {
129
/* 0x30 0x83 LL LL LL */
132
err = CRYPT_INVALID_ARG;