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_octet_string.c
13 ASN.1 DER, get length of OCTET STRING, Tom St Denis
18 Gets length of DER encoding of OCTET STRING
19 @param noctets The number of octets in the string to encode
20 @param outlen [out] The length of the DER encoding for the given string
21 @return CRYPT_OK if successful
23 int der_length_octet_string(unsigned long noctets, unsigned long *outlen)
25 LTC_ARGCHK(outlen != NULL);
28 /* 04 LL DD DD DD ... */
29 *outlen = 2 + noctets;
30 } else if (noctets < 256) {
31 /* 04 81 LL DD DD DD ... */
32 *outlen = 3 + noctets;
33 } else if (noctets < 65536UL) {
34 /* 04 82 LL LL DD DD DD ... */
35 *outlen = 4 + noctets;
36 } else if (noctets < 16777216UL) {
37 /* 04 83 LL LL LL DD DD DD ... */
38 *outlen = 5 + noctets;
40 return CRYPT_INVALID_ARG;
49 /* ref: $Format:%D$ */
50 /* git commit: $Format:%H$ */
51 /* commit time: $Format:%ai$ */