comparison libtomcrypt/src/pk/asn1/der/sequence/der_encode_sequence_multi.c @ 1471:6dba84798cd5

Update to libtomcrypt 1.18.1, merged with Dropbear changes
author Matt Johnston <matt@ucc.asn.au>
date Fri, 09 Feb 2018 21:44:05 +0800
parents f849a5ca2efc
children
comparison
equal deleted inserted replaced
1470:8bba51a55704 1471:6dba84798cd5
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 #include <stdarg.h> 10 #include <stdarg.h>
13 11
14 12
23 Encode a SEQUENCE type using a VA list 21 Encode a SEQUENCE type using a VA list
24 @param out [out] Destination for data 22 @param out [out] Destination for data
25 @param outlen [in/out] Length of buffer and resulting length of output 23 @param outlen [in/out] Length of buffer and resulting length of output
26 @remark <...> is of the form <type, size, data> (int, unsigned long, void*) 24 @remark <...> is of the form <type, size, data> (int, unsigned long, void*)
27 @return CRYPT_OK on success 25 @return CRYPT_OK on success
28 */ 26 */
29 int der_encode_sequence_multi(unsigned char *out, unsigned long *outlen, ...) 27 int der_encode_sequence_multi(unsigned char *out, unsigned long *outlen, ...)
30 { 28 {
31 int err, type; 29 int err;
30 ltc_asn1_type type;
32 unsigned long size, x; 31 unsigned long size, x;
33 void *data; 32 void *data;
34 va_list args; 33 va_list args;
35 ltc_asn1_list *list; 34 ltc_asn1_list *list;
36 35
39 38
40 /* get size of output that will be required */ 39 /* get size of output that will be required */
41 va_start(args, outlen); 40 va_start(args, outlen);
42 x = 0; 41 x = 0;
43 for (;;) { 42 for (;;) {
44 type = va_arg(args, int); 43 type = (ltc_asn1_type)va_arg(args, int);
45 size = va_arg(args, unsigned long); 44 size = va_arg(args, unsigned long);
46 data = va_arg(args, void*); 45 data = va_arg(args, void*);
46 LTC_UNUSED_PARAM(size);
47 LTC_UNUSED_PARAM(data);
47 48
48 if (type == LTC_ASN1_EOL) { 49 if (type == LTC_ASN1_EOL) {
49 break; 50 break;
50 } 51 }
51 52
52 switch (type) { 53 switch (type) {
53 case LTC_ASN1_BOOLEAN: 54 case LTC_ASN1_BOOLEAN:
62 case LTC_ASN1_UTF8_STRING: 63 case LTC_ASN1_UTF8_STRING:
63 case LTC_ASN1_UTCTIME: 64 case LTC_ASN1_UTCTIME:
64 case LTC_ASN1_SEQUENCE: 65 case LTC_ASN1_SEQUENCE:
65 case LTC_ASN1_SET: 66 case LTC_ASN1_SET:
66 case LTC_ASN1_SETOF: 67 case LTC_ASN1_SETOF:
67 ++x; 68 case LTC_ASN1_RAW_BIT_STRING:
69 case LTC_ASN1_GENERALIZEDTIME:
70 ++x;
68 break; 71 break;
69 72
70 default: 73 case LTC_ASN1_CHOICE:
74 case LTC_ASN1_CONSTRUCTED:
75 case LTC_ASN1_CONTEXT_SPECIFIC:
76 case LTC_ASN1_EOL:
77 case LTC_ASN1_TELETEX_STRING:
71 va_end(args); 78 va_end(args);
72 return CRYPT_INVALID_ARG; 79 return CRYPT_INVALID_ARG;
73 } 80 }
74 } 81 }
75 va_end(args); 82 va_end(args);
86 93
87 /* fill in the structure */ 94 /* fill in the structure */
88 va_start(args, outlen); 95 va_start(args, outlen);
89 x = 0; 96 x = 0;
90 for (;;) { 97 for (;;) {
91 type = va_arg(args, int); 98 type = (ltc_asn1_type)va_arg(args, int);
92 size = va_arg(args, unsigned long); 99 size = va_arg(args, unsigned long);
93 data = va_arg(args, void*); 100 data = va_arg(args, void*);
94 101
95 if (type == LTC_ASN1_EOL) { 102 if (type == LTC_ASN1_EOL) {
96 break; 103 break;
97 } 104 }
98 105
99 switch (type) { 106 switch (type) {
100 case LTC_ASN1_BOOLEAN: 107 case LTC_ASN1_BOOLEAN:
109 case LTC_ASN1_UTF8_STRING: 116 case LTC_ASN1_UTF8_STRING:
110 case LTC_ASN1_UTCTIME: 117 case LTC_ASN1_UTCTIME:
111 case LTC_ASN1_SEQUENCE: 118 case LTC_ASN1_SEQUENCE:
112 case LTC_ASN1_SET: 119 case LTC_ASN1_SET:
113 case LTC_ASN1_SETOF: 120 case LTC_ASN1_SETOF:
114 list[x].type = type; 121 case LTC_ASN1_RAW_BIT_STRING:
115 list[x].size = size; 122 case LTC_ASN1_GENERALIZEDTIME:
116 list[x++].data = data; 123 LTC_SET_ASN1(list, x++, type, data, size);
117 break; 124 break;
118 125
119 default: 126 case LTC_ASN1_CHOICE:
127 case LTC_ASN1_CONSTRUCTED:
128 case LTC_ASN1_CONTEXT_SPECIFIC:
129 case LTC_ASN1_EOL:
130 case LTC_ASN1_TELETEX_STRING:
120 va_end(args); 131 va_end(args);
121 err = CRYPT_INVALID_ARG; 132 err = CRYPT_INVALID_ARG;
122 goto LBL_ERR; 133 goto LBL_ERR;
123 } 134 }
124 } 135 }
125 va_end(args); 136 va_end(args);
126 137
127 err = der_encode_sequence(list, x, out, outlen); 138 err = der_encode_sequence(list, x, out, outlen);
128 LBL_ERR: 139 LBL_ERR:
129 XFREE(list); 140 XFREE(list);
130 return err; 141 return err;
131 } 142 }
132 143
133 #endif 144 #endif
134 145
135 146
136 /* $Source$ */ 147 /* ref: $Format:%D$ */
137 /* $Revision$ */ 148 /* git commit: $Format:%H$ */
138 /* $Date$ */ 149 /* commit time: $Format:%ai$ */