annotate src/pk/asn1/der/sequence/der_decode_sequence_multi.c @ 222:36160290a1b2 libtomcrypt LTC_DB_0.46

* change include path of options.h * don't use the constant ROL/ROR operations, since compilers seem to have problems
author Matt Johnston <matt@ucc.asn.au>
date Fri, 08 Jul 2005 19:13:24 +0000
parents 39d5d58461d6
children d5faf4814ddb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
209
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
2 *
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
3 * LibTomCrypt is a library that provides various cryptographic
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
4 * algorithms in a highly modular and flexible manner.
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
5 *
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
6 * The library is free for all purposes without any express
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
7 * guarantee it works.
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
8 *
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
9 * Tom St Denis, [email protected], http://libtomcrypt.org
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
10 */
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
11 #include "tomcrypt.h"
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
12 #include <stdarg.h>
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
13
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
14
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
15 /**
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
16 @file der_decode_sequence_multi.c
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
17 ASN.1 DER, decode a SEQUENCE, Tom St Denis
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
18 */
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
19
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
20 #ifdef LTC_DER
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
21
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
22 int der_decode_sequence_multi(const unsigned char *in, unsigned long inlen, ...)
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
23 {
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
24 int err, type;
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
25 unsigned long size, x;
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
26 void *data;
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
27 va_list args;
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
28 ltc_asn1_list *list;
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
29
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
30 LTC_ARGCHK(in != NULL);
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
31
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
32 /* get size of output that will be required */
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
33 va_start(args, inlen);
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
34 x = 0;
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
35 for (;;) {
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
36 type = va_arg(args, int);
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
37 size = va_arg(args, unsigned long);
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
38 data = va_arg(args, void*);
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
39
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
40 if (type == LTC_ASN1_EOL) {
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
41 break;
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
42 }
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
43
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
44 switch (type) {
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
45 case LTC_ASN1_INTEGER:
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
46 case LTC_ASN1_SHORT_INTEGER:
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
47 case LTC_ASN1_BIT_STRING:
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
48 case LTC_ASN1_OCTET_STRING:
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
49 case LTC_ASN1_NULL:
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
50 case LTC_ASN1_OBJECT_IDENTIFIER:
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
51 case LTC_ASN1_IA5_STRING:
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
52 case LTC_ASN1_PRINTABLE_STRING:
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
53 case LTC_ASN1_UTCTIME:
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
54 case LTC_ASN1_SEQUENCE:
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
55 case LTC_ASN1_CHOICE:
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
56 ++x;
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
57 break;
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
58
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
59 default:
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
60 va_end(args);
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
61 return CRYPT_INVALID_ARG;
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
62 }
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
63 }
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
64 va_end(args);
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
65
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
66 /* allocate structure for x elements */
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
67 if (x == 0) {
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
68 return CRYPT_NOP;
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
69 }
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
70
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
71 list = XCALLOC(sizeof(*list), x);
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
72 if (list == NULL) {
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
73 return CRYPT_MEM;
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
74 }
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
75
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
76 /* fill in the structure */
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
77 va_start(args, inlen);
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
78 x = 0;
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
79 for (;;) {
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
80 type = va_arg(args, int);
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
81 size = va_arg(args, unsigned long);
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
82 data = va_arg(args, void*);
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
83
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
84 if (type == LTC_ASN1_EOL) {
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
85 break;
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
86 }
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
87
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
88 switch (type) {
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
89 case LTC_ASN1_INTEGER:
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
90 case LTC_ASN1_SHORT_INTEGER:
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
91 case LTC_ASN1_BIT_STRING:
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
92 case LTC_ASN1_OCTET_STRING:
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
93 case LTC_ASN1_NULL:
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
94 case LTC_ASN1_OBJECT_IDENTIFIER:
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
95 case LTC_ASN1_IA5_STRING:
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
96 case LTC_ASN1_PRINTABLE_STRING:
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
97 case LTC_ASN1_UTCTIME:
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
98 case LTC_ASN1_SEQUENCE:
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
99 case LTC_ASN1_CHOICE:
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
100 list[x].type = type;
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
101 list[x].size = size;
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
102 list[x++].data = data;
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
103 break;
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
104
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
105 default:
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
106 va_end(args);
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
107 err = CRYPT_INVALID_ARG;
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
108 goto LBL_ERR;
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
109 }
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
110 }
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
111 va_end(args);
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
112
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
113 err = der_decode_sequence(in, inlen, list, x);
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
114 LBL_ERR:
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
115 XFREE(list);
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
116 return err;
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
117 }
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
118
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
119 #endif
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
120
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
121
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
122 /* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/sequence/der_decode_sequence_multi.c,v $ */
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
123 /* $Revision: 1.7 $ */
39d5d58461d6 Import of libtomcrypt 1.05
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
124 /* $Date: 2005/06/18 19:20:23 $ */