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.org
14
@file der_decode_object_identifier.c
15
ASN.1 DER, Decode Object Identifier, Tom St Denis
20
Decode OID data and store the array of integers in words
21
@param in The OID DER encoded data
22
@param inlen The length of the OID data
23
@param words [out] The destination of the OID words
24
@param outlen [in/out] The number of OID words
25
@return CRYPT_OK if successful
27
int der_decode_object_identifier(const unsigned char *in, unsigned long inlen,
28
unsigned long *words, unsigned long *outlen)
30
unsigned long x, y, t, len;
32
LTC_ARGCHK(in != NULL);
33
LTC_ARGCHK(words != NULL);
34
LTC_ARGCHK(outlen != NULL);
36
/* header is at least 3 bytes */
38
return CRYPT_INVALID_PACKET;
41
/* 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;
70
/* decode word1 and word2 */
80
t = (t << 7) | (in[x] & 0x7F);
81
if (!(in[x++] & 0x80)) {
84
return CRYPT_BUFFER_OVERFLOW;
97
/* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/object_identifier/der_decode_object_identifier.c,v $ */
98
/* $Revision: 1.1 $ */
99
/* $Date: 2005/05/16 15:08:11 $ */