comparison libtomcrypt/src/pk/asn1/der/choice/der_decode_choice.c @ 1511:5916af64acd4 fuzz

merge from main
author Matt Johnston <matt@ucc.asn.au>
date Sat, 17 Feb 2018 19:29:51 +0800
parents 6dba84798cd5
children
comparison
equal deleted inserted replaced
1457:32f990cc96b1 1511:5916af64acd4
3 * LibTomCrypt is a library that provides various cryptographic 3 * LibTomCrypt is a library that provides various cryptographic
4 * algorithms in a highly modular and flexible manner. 4 * algorithms in a highly modular and flexible manner.
5 * 5 *
6 * The library is free for all purposes without any express 6 * The library is free for all purposes without any express
7 * guarantee it works. 7 * guarantee it works.
8 *
9 * Tom St Denis, [email protected], http://libtom.org
10 */ 8 */
11 #include "tomcrypt.h" 9 #include "tomcrypt.h"
12 10
13 /** 11 /**
14 @file der_decode_choice.c 12 @file der_decode_choice.c
49 for (x = 0; x < outlen; x++) { 47 for (x = 0; x < outlen; x++) {
50 size = list[x].size; 48 size = list[x].size;
51 data = list[x].data; 49 data = list[x].data;
52 50
53 switch (list[x].type) { 51 switch (list[x].type) {
52 case LTC_ASN1_BOOLEAN:
53 if (der_decode_boolean(in, *inlen, data) == CRYPT_OK) {
54 if (der_length_boolean(&z) == CRYPT_OK) {
55 list[x].used = 1;
56 *inlen = z;
57 return CRYPT_OK;
58 }
59 }
60 break;
61
54 case LTC_ASN1_INTEGER: 62 case LTC_ASN1_INTEGER:
55 if (der_decode_integer(in, *inlen, data) == CRYPT_OK) { 63 if (der_decode_integer(in, *inlen, data) == CRYPT_OK) {
56 if (der_length_integer(data, &z) == CRYPT_OK) { 64 if (der_length_integer(data, &z) == CRYPT_OK) {
57 list[x].used = 1; 65 list[x].used = 1;
58 *inlen = z; 66 *inlen = z;
80 return CRYPT_OK; 88 return CRYPT_OK;
81 } 89 }
82 } 90 }
83 break; 91 break;
84 92
93 case LTC_ASN1_RAW_BIT_STRING:
94 if (der_decode_raw_bit_string(in, *inlen, data, &size) == CRYPT_OK) {
95 if (der_length_bit_string(size, &z) == CRYPT_OK) {
96 list[x].used = 1;
97 list[x].size = size;
98 *inlen = z;
99 return CRYPT_OK;
100 }
101 }
102 break;
103
85 case LTC_ASN1_OCTET_STRING: 104 case LTC_ASN1_OCTET_STRING:
86 if (der_decode_octet_string(in, *inlen, data, &size) == CRYPT_OK) { 105 if (der_decode_octet_string(in, *inlen, data, &size) == CRYPT_OK) {
87 if (der_length_octet_string(size, &z) == CRYPT_OK) { 106 if (der_length_octet_string(size, &z) == CRYPT_OK) {
88 list[x].used = 1; 107 list[x].used = 1;
89 list[x].size = size; 108 list[x].size = size;
98 *inlen = 2; 117 *inlen = 2;
99 list[x].used = 1; 118 list[x].used = 1;
100 return CRYPT_OK; 119 return CRYPT_OK;
101 } 120 }
102 break; 121 break;
103 122
104 case LTC_ASN1_OBJECT_IDENTIFIER: 123 case LTC_ASN1_OBJECT_IDENTIFIER:
105 if (der_decode_object_identifier(in, *inlen, data, &size) == CRYPT_OK) { 124 if (der_decode_object_identifier(in, *inlen, data, &size) == CRYPT_OK) {
106 if (der_length_object_identifier(data, size, &z) == CRYPT_OK) { 125 if (der_length_object_identifier(data, size, &z) == CRYPT_OK) {
107 list[x].used = 1; 126 list[x].used = 1;
108 list[x].size = size; 127 list[x].size = size;
110 return CRYPT_OK; 129 return CRYPT_OK;
111 } 130 }
112 } 131 }
113 break; 132 break;
114 133
134 case LTC_ASN1_TELETEX_STRING:
135 if (der_decode_teletex_string(in, *inlen, data, &size) == CRYPT_OK) {
136 if (der_length_teletex_string(data, size, &z) == CRYPT_OK) {
137 list[x].used = 1;
138 list[x].size = size;
139 *inlen = z;
140 return CRYPT_OK;
141 }
142 }
143 break;
144
115 case LTC_ASN1_IA5_STRING: 145 case LTC_ASN1_IA5_STRING:
116 if (der_decode_ia5_string(in, *inlen, data, &size) == CRYPT_OK) { 146 if (der_decode_ia5_string(in, *inlen, data, &size) == CRYPT_OK) {
117 if (der_length_ia5_string(data, size, &z) == CRYPT_OK) { 147 if (der_length_ia5_string(data, size, &z) == CRYPT_OK) {
118 list[x].used = 1; 148 list[x].used = 1;
119 list[x].size = size; 149 list[x].size = size;
120 *inlen = z; 150 *inlen = z;
121 return CRYPT_OK; 151 return CRYPT_OK;
122 } 152 }
123 } 153 }
124 break; 154 break;
125
126 155
127 case LTC_ASN1_PRINTABLE_STRING: 156 case LTC_ASN1_PRINTABLE_STRING:
128 if (der_decode_printable_string(in, *inlen, data, &size) == CRYPT_OK) { 157 if (der_decode_printable_string(in, *inlen, data, &size) == CRYPT_OK) {
129 if (der_length_printable_string(data, size, &z) == CRYPT_OK) { 158 if (der_length_printable_string(data, size, &z) == CRYPT_OK) {
130 list[x].used = 1; 159 list[x].used = 1;
153 *inlen = z; 182 *inlen = z;
154 return CRYPT_OK; 183 return CRYPT_OK;
155 } 184 }
156 break; 185 break;
157 186
187 case LTC_ASN1_GENERALIZEDTIME:
188 z = *inlen;
189 if (der_decode_generalizedtime(in, &z, data) == CRYPT_OK) {
190 list[x].used = 1;
191 *inlen = z;
192 return CRYPT_OK;
193 }
194 break;
195
158 case LTC_ASN1_SET: 196 case LTC_ASN1_SET:
159 case LTC_ASN1_SETOF: 197 case LTC_ASN1_SETOF:
160 case LTC_ASN1_SEQUENCE: 198 case LTC_ASN1_SEQUENCE:
161 if (der_decode_sequence(in, *inlen, data, size) == CRYPT_OK) { 199 if (der_decode_sequence(in, *inlen, data, size) == CRYPT_OK) {
162 if (der_length_sequence(data, size, &z) == CRYPT_OK) { 200 if (der_length_sequence(data, size, &z) == CRYPT_OK) {
165 return CRYPT_OK; 203 return CRYPT_OK;
166 } 204 }
167 } 205 }
168 break; 206 break;
169 207
170 default: 208 case LTC_ASN1_CHOICE:
209 case LTC_ASN1_CONSTRUCTED:
210 case LTC_ASN1_CONTEXT_SPECIFIC:
211 case LTC_ASN1_EOL:
171 return CRYPT_INVALID_ARG; 212 return CRYPT_INVALID_ARG;
172 } 213 }
173 } 214 }
174 215
175 return CRYPT_INVALID_PACKET; 216 return CRYPT_INVALID_PACKET;
176 } 217 }
177 218
178 #endif 219 #endif
179 220
180 /* $Source$ */ 221 /* ref: $Format:%D$ */
181 /* $Revision$ */ 222 /* git commit: $Format:%H$ */
182 /* $Date$ */ 223 /* commit time: $Format:%ai$ */