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.com
14 @file der_length_short_integer.c
15 ASN.1 DER, get length of encoding, Tom St Denis
21 Gets length of DER encoding of num
22 @param num The integer to get the size of
23 @param outlen [out] The length of the DER encoding for the given integer
24 @return CRYPT_OK if successful
26 int der_length_short_integer(unsigned long num, unsigned long *outlen)
28 unsigned long z, y, len;
30 LTC_ARGCHK(outlen != NULL);
32 /* force to 32 bits */
35 /* get the number of bytes */
48 /* we need a 0x02 to indicate it's INTEGER */
57 /* see if msb is set */
58 len += (num&(1UL<<((z<<3) - 1))) ? 1 : 0;
68 /* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/short_integer/der_length_short_integer.c,v $ */
69 /* $Revision: 1.5 $ */
70 /* $Date: 2006/03/31 14:15:35 $ */