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_bit_string.c 14 ASN.1 DER, get length of BIT STRING, Tom St Denis 15 */ 16 17 #ifdef LTC_DER 18 /** 19 Gets length of DER encoding of BIT STRING 20 @param nbits The number of bits 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_bit_string(unsigned long nbits,unsigned long * outlen)24int der_length_bit_string(unsigned long nbits, unsigned long *outlen) 25 { 26 unsigned long nbytes, x; 27 int err; 28 29 LTC_ARGCHK(outlen != NULL); 30 31 /* get the number of the bytes */ 32 nbytes = (nbits >> 3) + ((nbits & 7) ? 1 : 0) + 1; 33 34 if ((err = der_length_asn1_length(nbytes, &x)) != CRYPT_OK) { 35 return err; 36 } 37 *outlen = 1 + x + nbytes; 38 39 return CRYPT_OK; 40 } 41 42 #endif 43 44 45 /* ref: $Format:%D$ */ 46 /* git commit: $Format:%H$ */ 47 /* commit time: $Format:%ai$ */ 48