Mercurial > dropbear
diff libtomcrypt/src/pk/asn1/der/sequence/der_length_sequence.c @ 1511:5916af64acd4 fuzz
merge from main
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sat, 17 Feb 2018 19:29:51 +0800 |
parents | 6dba84798cd5 |
children |
line wrap: on
line diff
--- a/libtomcrypt/src/pk/asn1/der/sequence/der_length_sequence.c Tue Jan 23 23:27:40 2018 +0800 +++ b/libtomcrypt/src/pk/asn1/der/sequence/der_length_sequence.c Sat Feb 17 19:29:51 2018 +0800 @@ -5,8 +5,6 @@ * * The library is free for all purposes without any express * guarantee it works. - * - * Tom St Denis, [email protected], http://libtom.org */ #include "tomcrypt.h" @@ -18,17 +16,24 @@ #ifdef LTC_DER /** - Get the length of a DER sequence + Get the length of a DER sequence @param list The sequences of items in the SEQUENCE @param inlen The number of items - @param outlen [out] The length required in octets to store it + @param outlen [out] The length required in octets to store it @return CRYPT_OK on success */ int der_length_sequence(ltc_asn1_list *list, unsigned long inlen, - unsigned long *outlen) + unsigned long *outlen) { - int err, type; - unsigned long size, x, y, z, i; + return der_length_sequence_ex(list, inlen, outlen, NULL); +} + +int der_length_sequence_ex(ltc_asn1_list *list, unsigned long inlen, + unsigned long *outlen, unsigned long *payloadlen) +{ + int err; + ltc_asn1_type type; + unsigned long size, x, y, i, z; void *data; LTC_ARGCHK(list != NULL); @@ -41,7 +46,7 @@ size = list[i].size; data = list[i].data; - if (type == LTC_ASN1_EOL) { + if (type == LTC_ASN1_EOL) { break; } @@ -52,7 +57,7 @@ } y += x; break; - + case LTC_ASN1_INTEGER: if ((err = der_length_integer(data, &x)) != CRYPT_OK) { goto LBL_ERR; @@ -68,6 +73,7 @@ break; case LTC_ASN1_BIT_STRING: + case LTC_ASN1_RAW_BIT_STRING: if ((err = der_length_bit_string(size, &x)) != CRYPT_OK) { goto LBL_ERR; } @@ -99,6 +105,13 @@ y += x; break; + case LTC_ASN1_TELETEX_STRING: + if ((err = der_length_teletex_string(data, size, &x)) != CRYPT_OK) { + goto LBL_ERR; + } + y += x; + break; + case LTC_ASN1_PRINTABLE_STRING: if ((err = der_length_printable_string(data, size, &x)) != CRYPT_OK) { goto LBL_ERR; @@ -113,6 +126,13 @@ y += x; break; + case LTC_ASN1_GENERALIZEDTIME: + if ((err = der_length_generalizedtime(data, &x)) != CRYPT_OK) { + goto LBL_ERR; + } + y += x; + break; + case LTC_ASN1_UTF8_STRING: if ((err = der_length_utf8_string(data, size, &x)) != CRYPT_OK) { goto LBL_ERR; @@ -129,8 +149,11 @@ y += x; break; - - default: + + case LTC_ASN1_CHOICE: + case LTC_ASN1_CONSTRUCTED: + case LTC_ASN1_CONTEXT_SPECIFIC: + case LTC_ASN1_EOL: err = CRYPT_INVALID_ARG; goto LBL_ERR; } @@ -155,6 +178,7 @@ } /* store size */ + if (payloadlen) *payloadlen = z; *outlen = y; err = CRYPT_OK; @@ -164,6 +188,6 @@ #endif -/* $Source$ */ -/* $Revision$ */ -/* $Date$ */ +/* ref: $Format:%D$ */ +/* git commit: $Format:%H$ */ +/* commit time: $Format:%ai$ */