1 // SPDX-License-Identifier: BSD-2-Clause
2 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
3  *
4  * LibTomCrypt is a library that provides various cryptographic
5  * algorithms in a highly modular and flexible manner.
6  *
7  * The library is free for all purposes without any express
8  * guarantee it works.
9  */
10 #include "tomcrypt_private.h"
11 
12 /**
13   @file der_length_octet_string.c
14   ASN.1 DER, get length of OCTET STRING, Tom St Denis
15 */
16 
17 #ifdef LTC_DER
18 /**
19   Gets length of DER encoding of OCTET STRING
20   @param noctets  The number of octets in the string to encode
21   @param outlen   [out] The length of the DER encoding for the given string
22   @return CRYPT_OK if successful
23 */
der_length_octet_string(unsigned long noctets,unsigned long * outlen)24 int der_length_octet_string(unsigned long noctets, unsigned long *outlen)
25 {
26    unsigned long x;
27    int err;
28 
29    LTC_ARGCHK(outlen != NULL);
30 
31    if ((err = der_length_asn1_length(noctets, &x)) != CRYPT_OK) {
32       return err;
33    }
34    *outlen = 1 + x + noctets;
35 
36    return CRYPT_OK;
37 }
38 
39 #endif
40 
41 
42 /* ref:         $Format:%D$ */
43 /* git commit:  $Format:%H$ */
44 /* commit time: $Format:%ai$ */
45