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_decode_object_identifier.c
13 ASN.1 DER, Decode Object Identifier, Tom St Denis
18 Decode OID data and store the array of integers in words
19 @param in The OID DER encoded data
20 @param inlen The length of the OID data
21 @param words [out] The destination of the OID words
22 @param outlen [in/out] The number of OID words
23 @return CRYPT_OK if successful
25 int der_decode_object_identifier(const unsigned char *in, unsigned long inlen,
26 unsigned long *words, unsigned long *outlen)
28 unsigned long x, y, t, len;
31 LTC_ARGCHK(in != NULL);
32 LTC_ARGCHK(words != NULL);
33 LTC_ARGCHK(outlen != NULL);
35 /* header is at least 3 bytes */
37 return CRYPT_INVALID_PACKET;
40 /* must be room for at least two words */
43 return CRYPT_BUFFER_OVERFLOW;
46 /* decode the packet header */
48 if ((in[x++] & 0x1F) != 0x06) {
49 return CRYPT_INVALID_PACKET;
56 if (in[x] < 0x81 || in[x] > 0x82) {
57 return CRYPT_INVALID_PACKET;
62 len = (len << 8) | (unsigned long)in[x++];
66 if (len < 1 || (len + x) > inlen) {
67 return CRYPT_INVALID_PACKET;
74 t = (t << 7) | (in[x] & 0x7F);
75 if (!(in[x++] & 0x80)) {
93 err = CRYPT_BUFFER_OVERFLOW;
104 /* ref: $Format:%D$ */
105 /* git commit: $Format:%H$ */
106 /* commit time: $Format:%ai$ */