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_object_identifier.c
15 ASN.1 DER, get length of Object Identifier, Tom St Denis
20 unsigned long der_object_identifier_bits(unsigned long x)
34 Gets length of DER encoding of Object Identifier
35 @param nwords The number of OID words
36 @param words The actual OID words to get the size of
37 @param outlen [out] The length of the DER encoding for the given string
38 @return CRYPT_OK if successful
40 int der_length_object_identifier(unsigned long *words, unsigned long nwords, unsigned long *outlen)
42 unsigned long y, z, t, wordbuf;
44 LTC_ARGCHK(words != NULL);
45 LTC_ARGCHK(outlen != NULL);
48 /* must be >= 2 words */
50 return CRYPT_INVALID_ARG;
53 /* word1 = 0,1,2,3 and word2 0..39 */
54 if (words[0] > 3 || (words[0] < 2 && words[1] > 39)) {
55 return CRYPT_INVALID_ARG;
58 /* leading word is the first two */
60 wordbuf = words[0] * 40 + words[1];
61 for (y = 1; y < nwords; y++) {
62 t = der_object_identifier_bits(wordbuf);
63 z += t/7 + ((t%7) ? 1 : 0) + (wordbuf == 0 ? 1 : 0);
70 /* now depending on the length our length encoding changes */
75 } else if (z < 65536UL) {
78 return CRYPT_INVALID_ARG;
87 /* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/object_identifier/der_length_object_identifier.c,v $ */
88 /* $Revision: 1.4 $ */
89 /* $Date: 2006/04/16 20:17:42 $ */