diff options
author | djm <> | 2008-09-06 12:17:54 +0000 |
---|---|---|
committer | djm <> | 2008-09-06 12:17:54 +0000 |
commit | 38ce604e3cc97706b876b0525ddff0121115456d (patch) | |
tree | 7ccc28afe1789ea3dbedf72365f955d5b8e105b5 /src/lib/libcrypto/asn1/a_object.c | |
parent | 12867252827c8efaa8ddd1fa3b3d6e321e2bcdef (diff) | |
download | openbsd-38ce604e3cc97706b876b0525ddff0121115456d.tar.gz openbsd-38ce604e3cc97706b876b0525ddff0121115456d.tar.bz2 openbsd-38ce604e3cc97706b876b0525ddff0121115456d.zip |
resolve conflicts
Diffstat (limited to 'src/lib/libcrypto/asn1/a_object.c')
-rw-r--r-- | src/lib/libcrypto/asn1/a_object.c | 100 |
1 files changed, 83 insertions, 17 deletions
diff --git a/src/lib/libcrypto/asn1/a_object.c b/src/lib/libcrypto/asn1/a_object.c index 0a8e6c287c..dc980421d0 100644 --- a/src/lib/libcrypto/asn1/a_object.c +++ b/src/lib/libcrypto/asn1/a_object.c | |||
@@ -57,10 +57,12 @@ | |||
57 | */ | 57 | */ |
58 | 58 | ||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include <limits.h> | ||
60 | #include "cryptlib.h" | 61 | #include "cryptlib.h" |
61 | #include <openssl/buffer.h> | 62 | #include <openssl/buffer.h> |
62 | #include <openssl/asn1.h> | 63 | #include <openssl/asn1.h> |
63 | #include <openssl/objects.h> | 64 | #include <openssl/objects.h> |
65 | #include <openssl/bn.h> | ||
64 | 66 | ||
65 | int i2d_ASN1_OBJECT(ASN1_OBJECT *a, unsigned char **pp) | 67 | int i2d_ASN1_OBJECT(ASN1_OBJECT *a, unsigned char **pp) |
66 | { | 68 | { |
@@ -83,10 +85,12 @@ int i2d_ASN1_OBJECT(ASN1_OBJECT *a, unsigned char **pp) | |||
83 | 85 | ||
84 | int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num) | 86 | int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num) |
85 | { | 87 | { |
86 | int i,first,len=0,c; | 88 | int i,first,len=0,c, use_bn; |
87 | char tmp[24]; | 89 | char ftmp[24], *tmp = ftmp; |
90 | int tmpsize = sizeof ftmp; | ||
88 | const char *p; | 91 | const char *p; |
89 | unsigned long l; | 92 | unsigned long l; |
93 | BIGNUM *bl = NULL; | ||
90 | 94 | ||
91 | if (num == 0) | 95 | if (num == 0) |
92 | return(0); | 96 | return(0); |
@@ -98,7 +102,7 @@ int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num) | |||
98 | num--; | 102 | num--; |
99 | if ((c >= '0') && (c <= '2')) | 103 | if ((c >= '0') && (c <= '2')) |
100 | { | 104 | { |
101 | first=(c-'0')*40; | 105 | first= c-'0'; |
102 | } | 106 | } |
103 | else | 107 | else |
104 | { | 108 | { |
@@ -122,6 +126,7 @@ int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num) | |||
122 | goto err; | 126 | goto err; |
123 | } | 127 | } |
124 | l=0; | 128 | l=0; |
129 | use_bn = 0; | ||
125 | for (;;) | 130 | for (;;) |
126 | { | 131 | { |
127 | if (num <= 0) break; | 132 | if (num <= 0) break; |
@@ -134,7 +139,22 @@ int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num) | |||
134 | ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_INVALID_DIGIT); | 139 | ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_INVALID_DIGIT); |
135 | goto err; | 140 | goto err; |
136 | } | 141 | } |
137 | l=l*10L+(long)(c-'0'); | 142 | if (!use_bn && l > (ULONG_MAX / 10L)) |
143 | { | ||
144 | use_bn = 1; | ||
145 | if (!bl) | ||
146 | bl = BN_new(); | ||
147 | if (!bl || !BN_set_word(bl, l)) | ||
148 | goto err; | ||
149 | } | ||
150 | if (use_bn) | ||
151 | { | ||
152 | if (!BN_mul_word(bl, 10L) | ||
153 | || !BN_add_word(bl, c-'0')) | ||
154 | goto err; | ||
155 | } | ||
156 | else | ||
157 | l=l*10L+(long)(c-'0'); | ||
138 | } | 158 | } |
139 | if (len == 0) | 159 | if (len == 0) |
140 | { | 160 | { |
@@ -143,14 +163,42 @@ int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num) | |||
143 | ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_SECOND_NUMBER_TOO_LARGE); | 163 | ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_SECOND_NUMBER_TOO_LARGE); |
144 | goto err; | 164 | goto err; |
145 | } | 165 | } |
146 | l+=(long)first; | 166 | if (use_bn) |
167 | { | ||
168 | if (!BN_add_word(bl, first * 40)) | ||
169 | goto err; | ||
170 | } | ||
171 | else | ||
172 | l+=(long)first*40; | ||
147 | } | 173 | } |
148 | i=0; | 174 | i=0; |
149 | for (;;) | 175 | if (use_bn) |
176 | { | ||
177 | int blsize; | ||
178 | blsize = BN_num_bits(bl); | ||
179 | blsize = (blsize + 6)/7; | ||
180 | if (blsize > tmpsize) | ||
181 | { | ||
182 | if (tmp != ftmp) | ||
183 | OPENSSL_free(tmp); | ||
184 | tmpsize = blsize + 32; | ||
185 | tmp = OPENSSL_malloc(tmpsize); | ||
186 | if (!tmp) | ||
187 | goto err; | ||
188 | } | ||
189 | while(blsize--) | ||
190 | tmp[i++] = (unsigned char)BN_div_word(bl, 0x80L); | ||
191 | } | ||
192 | else | ||
150 | { | 193 | { |
151 | tmp[i++]=(unsigned char)l&0x7f; | 194 | |
152 | l>>=7L; | 195 | for (;;) |
153 | if (l == 0L) break; | 196 | { |
197 | tmp[i++]=(unsigned char)l&0x7f; | ||
198 | l>>=7L; | ||
199 | if (l == 0L) break; | ||
200 | } | ||
201 | |||
154 | } | 202 | } |
155 | if (out != NULL) | 203 | if (out != NULL) |
156 | { | 204 | { |
@@ -166,8 +214,16 @@ int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num) | |||
166 | else | 214 | else |
167 | len+=i; | 215 | len+=i; |
168 | } | 216 | } |
217 | if (tmp != ftmp) | ||
218 | OPENSSL_free(tmp); | ||
219 | if (bl) | ||
220 | BN_free(bl); | ||
169 | return(len); | 221 | return(len); |
170 | err: | 222 | err: |
223 | if (tmp != ftmp) | ||
224 | OPENSSL_free(tmp); | ||
225 | if (bl) | ||
226 | BN_free(bl); | ||
171 | return(0); | 227 | return(0); |
172 | } | 228 | } |
173 | 229 | ||
@@ -178,21 +234,31 @@ int i2t_ASN1_OBJECT(char *buf, int buf_len, ASN1_OBJECT *a) | |||
178 | 234 | ||
179 | int i2a_ASN1_OBJECT(BIO *bp, ASN1_OBJECT *a) | 235 | int i2a_ASN1_OBJECT(BIO *bp, ASN1_OBJECT *a) |
180 | { | 236 | { |
181 | char buf[80]; | 237 | char buf[80], *p = buf; |
182 | int i; | 238 | int i; |
183 | 239 | ||
184 | if ((a == NULL) || (a->data == NULL)) | 240 | if ((a == NULL) || (a->data == NULL)) |
185 | return(BIO_write(bp,"NULL",4)); | 241 | return(BIO_write(bp,"NULL",4)); |
186 | i=i2t_ASN1_OBJECT(buf,sizeof buf,a); | 242 | i=i2t_ASN1_OBJECT(buf,sizeof buf,a); |
187 | if (i > sizeof buf) i=sizeof buf; | 243 | if (i > (int)(sizeof(buf) - 1)) |
188 | BIO_write(bp,buf,i); | 244 | { |
245 | p = OPENSSL_malloc(i + 1); | ||
246 | if (!p) | ||
247 | return -1; | ||
248 | i2t_ASN1_OBJECT(p,i + 1,a); | ||
249 | } | ||
250 | if (i <= 0) | ||
251 | return BIO_write(bp, "<INVALID>", 9); | ||
252 | BIO_write(bp,p,i); | ||
253 | if (p != buf) | ||
254 | OPENSSL_free(p); | ||
189 | return(i); | 255 | return(i); |
190 | } | 256 | } |
191 | 257 | ||
192 | ASN1_OBJECT *d2i_ASN1_OBJECT(ASN1_OBJECT **a, unsigned char **pp, | 258 | ASN1_OBJECT *d2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, |
193 | long length) | 259 | long length) |
194 | { | 260 | { |
195 | unsigned char *p; | 261 | const unsigned char *p; |
196 | long len; | 262 | long len; |
197 | int tag,xclass; | 263 | int tag,xclass; |
198 | int inf,i; | 264 | int inf,i; |
@@ -219,11 +285,11 @@ err: | |||
219 | ASN1_OBJECT_free(ret); | 285 | ASN1_OBJECT_free(ret); |
220 | return(NULL); | 286 | return(NULL); |
221 | } | 287 | } |
222 | ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, unsigned char **pp, | 288 | ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, |
223 | long len) | 289 | long len) |
224 | { | 290 | { |
225 | ASN1_OBJECT *ret=NULL; | 291 | ASN1_OBJECT *ret=NULL; |
226 | unsigned char *p; | 292 | const unsigned char *p; |
227 | int i; | 293 | int i; |
228 | 294 | ||
229 | /* only the ASN1_OBJECTs from the 'table' will have values | 295 | /* only the ASN1_OBJECTs from the 'table' will have values |
@@ -255,7 +321,7 @@ ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, unsigned char **pp, | |||
255 | *pp=p; | 321 | *pp=p; |
256 | return(ret); | 322 | return(ret); |
257 | err: | 323 | err: |
258 | ASN1err(ASN1_F_D2I_ASN1_OBJECT,i); | 324 | ASN1err(ASN1_F_C2I_ASN1_OBJECT,i); |
259 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) | 325 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) |
260 | ASN1_OBJECT_free(ret); | 326 | ASN1_OBJECT_free(ret); |
261 | return(NULL); | 327 | return(NULL); |