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_short_integer.c
13 ASN.1 DER, get length of encoding, Tom St Denis
19 Gets length of DER encoding of num
20 @param num The integer to get the size of
21 @param outlen [out] The length of the DER encoding for the given integer
22 @return CRYPT_OK if successful
24 int der_length_short_integer(unsigned long num, unsigned long *outlen)
26 unsigned long z, y, len;
28 LTC_ARGCHK(outlen != NULL);
30 /* force to 32 bits */
33 /* get the number of bytes */
46 /* we need a 0x02 to indicate it's INTEGER */
55 /* see if msb is set */
56 len += (num&(1UL<<((z<<3) - 1))) ? 1 : 0;
66 /* ref: $Format:%D$ */
67 /* git commit: $Format:%H$ */
68 /* commit time: $Format:%ai$ */