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_object_identifier.c
13 ASN.1 DER, get length of Object Identifier, Tom St Denis
18 unsigned long der_object_identifier_bits(unsigned long x)
32 Gets length of DER encoding of Object Identifier
33 @param nwords The number of OID words
34 @param words The actual OID words to get the size of
35 @param outlen [out] The length of the DER encoding for the given string
36 @return CRYPT_OK if successful
38 int der_length_object_identifier(unsigned long *words, unsigned long nwords, unsigned long *outlen)
40 unsigned long y, z, t, wordbuf;
42 LTC_ARGCHK(words != NULL);
43 LTC_ARGCHK(outlen != NULL);
46 /* must be >= 2 words */
48 return CRYPT_INVALID_ARG;
51 /* word1 = 0,1,2,3 and word2 0..39 */
52 if (words[0] > 3 || (words[0] < 2 && words[1] > 39)) {
53 return CRYPT_INVALID_ARG;
56 /* leading word is the first two */
58 wordbuf = words[0] * 40 + words[1];
59 for (y = 1; y < nwords; y++) {
60 t = der_object_identifier_bits(wordbuf);
61 z += t/7 + ((t%7) ? 1 : 0) + (wordbuf == 0 ? 1 : 0);
68 /* now depending on the length our length encoding changes */
73 } else if (z < 65536UL) {
76 return CRYPT_INVALID_ARG;
85 /* ref: $Format:%D$ */
86 /* git commit: $Format:%H$ */
87 /* commit time: $Format:%ai$ */