diff options
author | djm <> | 2010-10-01 22:59:01 +0000 |
---|---|---|
committer | djm <> | 2010-10-01 22:59:01 +0000 |
commit | fe047d8b632246cb2db3234a0a4f32e5c318857b (patch) | |
tree | 939b752540947d33507b3acc48d76a8bfb7c3dc3 /src/lib/libcrypto/evp/bio_b64.c | |
parent | 2ea67f4aa254b09ded62e6e14fc893bbe6381579 (diff) | |
download | openbsd-fe047d8b632246cb2db3234a0a4f32e5c318857b.tar.gz openbsd-fe047d8b632246cb2db3234a0a4f32e5c318857b.tar.bz2 openbsd-fe047d8b632246cb2db3234a0a4f32e5c318857b.zip |
resolve conflicts, fix local changes
Diffstat (limited to 'src/lib/libcrypto/evp/bio_b64.c')
-rw-r--r-- | src/lib/libcrypto/evp/bio_b64.c | 77 |
1 files changed, 54 insertions, 23 deletions
diff --git a/src/lib/libcrypto/evp/bio_b64.c b/src/lib/libcrypto/evp/bio_b64.c index fa5cbc7eb1..72a2a67277 100644 --- a/src/lib/libcrypto/evp/bio_b64.c +++ b/src/lib/libcrypto/evp/bio_b64.c | |||
@@ -64,7 +64,7 @@ | |||
64 | 64 | ||
65 | static int b64_write(BIO *h, const char *buf, int num); | 65 | static int b64_write(BIO *h, const char *buf, int num); |
66 | static int b64_read(BIO *h, char *buf, int size); | 66 | static int b64_read(BIO *h, char *buf, int size); |
67 | /*static int b64_puts(BIO *h, const char *str); */ | 67 | static int b64_puts(BIO *h, const char *str); |
68 | /*static int b64_gets(BIO *h, char *str, int size); */ | 68 | /*static int b64_gets(BIO *h, char *str, int size); */ |
69 | static long b64_ctrl(BIO *h, int cmd, long arg1, void *arg2); | 69 | static long b64_ctrl(BIO *h, int cmd, long arg1, void *arg2); |
70 | static int b64_new(BIO *h); | 70 | static int b64_new(BIO *h); |
@@ -96,7 +96,7 @@ static BIO_METHOD methods_b64= | |||
96 | BIO_TYPE_BASE64,"base64 encoding", | 96 | BIO_TYPE_BASE64,"base64 encoding", |
97 | b64_write, | 97 | b64_write, |
98 | b64_read, | 98 | b64_read, |
99 | NULL, /* b64_puts, */ | 99 | b64_puts, |
100 | NULL, /* b64_gets, */ | 100 | NULL, /* b64_gets, */ |
101 | b64_ctrl, | 101 | b64_ctrl, |
102 | b64_new, | 102 | b64_new, |
@@ -127,6 +127,7 @@ static int b64_new(BIO *bi) | |||
127 | bi->init=1; | 127 | bi->init=1; |
128 | bi->ptr=(char *)ctx; | 128 | bi->ptr=(char *)ctx; |
129 | bi->flags=0; | 129 | bi->flags=0; |
130 | bi->num = 0; | ||
130 | return(1); | 131 | return(1); |
131 | } | 132 | } |
132 | 133 | ||
@@ -151,6 +152,8 @@ static int b64_read(BIO *b, char *out, int outl) | |||
151 | 152 | ||
152 | if ((ctx == NULL) || (b->next_bio == NULL)) return(0); | 153 | if ((ctx == NULL) || (b->next_bio == NULL)) return(0); |
153 | 154 | ||
155 | BIO_clear_retry_flags(b); | ||
156 | |||
154 | if (ctx->encode != B64_DECODE) | 157 | if (ctx->encode != B64_DECODE) |
155 | { | 158 | { |
156 | ctx->encode=B64_DECODE; | 159 | ctx->encode=B64_DECODE; |
@@ -163,6 +166,7 @@ static int b64_read(BIO *b, char *out, int outl) | |||
163 | /* First check if there are bytes decoded/encoded */ | 166 | /* First check if there are bytes decoded/encoded */ |
164 | if (ctx->buf_len > 0) | 167 | if (ctx->buf_len > 0) |
165 | { | 168 | { |
169 | OPENSSL_assert(ctx->buf_len >= ctx->buf_off); | ||
166 | i=ctx->buf_len-ctx->buf_off; | 170 | i=ctx->buf_len-ctx->buf_off; |
167 | if (i > outl) i=outl; | 171 | if (i > outl) i=outl; |
168 | OPENSSL_assert(ctx->buf_off+i < (int)sizeof(ctx->buf)); | 172 | OPENSSL_assert(ctx->buf_off+i < (int)sizeof(ctx->buf)); |
@@ -184,7 +188,6 @@ static int b64_read(BIO *b, char *out, int outl) | |||
184 | ret_code=0; | 188 | ret_code=0; |
185 | while (outl > 0) | 189 | while (outl > 0) |
186 | { | 190 | { |
187 | |||
188 | if (ctx->cont <= 0) | 191 | if (ctx->cont <= 0) |
189 | break; | 192 | break; |
190 | 193 | ||
@@ -195,7 +198,7 @@ static int b64_read(BIO *b, char *out, int outl) | |||
195 | { | 198 | { |
196 | ret_code=i; | 199 | ret_code=i; |
197 | 200 | ||
198 | /* Should be continue next time we are called? */ | 201 | /* Should we continue next time we are called? */ |
199 | if (!BIO_should_retry(b->next_bio)) | 202 | if (!BIO_should_retry(b->next_bio)) |
200 | { | 203 | { |
201 | ctx->cont=i; | 204 | ctx->cont=i; |
@@ -285,19 +288,27 @@ static int b64_read(BIO *b, char *out, int outl) | |||
285 | continue; | 288 | continue; |
286 | } | 289 | } |
287 | else | 290 | else |
291 | { | ||
288 | ctx->tmp_len=0; | 292 | ctx->tmp_len=0; |
289 | } | 293 | } |
290 | /* If buffer isn't full and we can retry then | 294 | } |
291 | * restart to read in more data. | ||
292 | */ | ||
293 | else if ((i < B64_BLOCK_SIZE) && (ctx->cont > 0)) | 295 | else if ((i < B64_BLOCK_SIZE) && (ctx->cont > 0)) |
296 | { | ||
297 | /* If buffer isn't full and we can retry then | ||
298 | * restart to read in more data. | ||
299 | */ | ||
294 | continue; | 300 | continue; |
301 | } | ||
295 | 302 | ||
296 | if (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL) | 303 | if (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL) |
297 | { | 304 | { |
298 | int z,jj; | 305 | int z,jj; |
299 | 306 | ||
307 | #if 0 | ||
300 | jj=(i>>2)<<2; | 308 | jj=(i>>2)<<2; |
309 | #else | ||
310 | jj = i & ~3; /* process per 4 */ | ||
311 | #endif | ||
301 | z=EVP_DecodeBlock((unsigned char *)ctx->buf, | 312 | z=EVP_DecodeBlock((unsigned char *)ctx->buf, |
302 | (unsigned char *)ctx->tmp,jj); | 313 | (unsigned char *)ctx->tmp,jj); |
303 | if (jj > 2) | 314 | if (jj > 2) |
@@ -313,18 +324,15 @@ static int b64_read(BIO *b, char *out, int outl) | |||
313 | * number consumed */ | 324 | * number consumed */ |
314 | if (jj != i) | 325 | if (jj != i) |
315 | { | 326 | { |
316 | memcpy((unsigned char *)ctx->tmp, | 327 | memmove(ctx->tmp, &ctx->tmp[jj], i-jj); |
317 | (unsigned char *)&(ctx->tmp[jj]),i-jj); | ||
318 | ctx->tmp_len=i-jj; | 328 | ctx->tmp_len=i-jj; |
319 | } | 329 | } |
320 | ctx->buf_len=0; | 330 | ctx->buf_len=0; |
321 | if (z > 0) | 331 | if (z > 0) |
322 | { | 332 | { |
323 | ctx->buf_len=z; | 333 | ctx->buf_len=z; |
324 | i=1; | ||
325 | } | 334 | } |
326 | else | 335 | i=z; |
327 | i=z; | ||
328 | } | 336 | } |
329 | else | 337 | else |
330 | { | 338 | { |
@@ -357,14 +365,16 @@ static int b64_read(BIO *b, char *out, int outl) | |||
357 | outl-=i; | 365 | outl-=i; |
358 | out+=i; | 366 | out+=i; |
359 | } | 367 | } |
360 | BIO_clear_retry_flags(b); | 368 | /* BIO_clear_retry_flags(b); */ |
361 | BIO_copy_next_retry(b); | 369 | BIO_copy_next_retry(b); |
362 | return((ret == 0)?ret_code:ret); | 370 | return((ret == 0)?ret_code:ret); |
363 | } | 371 | } |
364 | 372 | ||
365 | static int b64_write(BIO *b, const char *in, int inl) | 373 | static int b64_write(BIO *b, const char *in, int inl) |
366 | { | 374 | { |
367 | int ret=inl,n,i; | 375 | int ret=0; |
376 | int n; | ||
377 | int i; | ||
368 | BIO_B64_CTX *ctx; | 378 | BIO_B64_CTX *ctx; |
369 | 379 | ||
370 | ctx=(BIO_B64_CTX *)b->ptr; | 380 | ctx=(BIO_B64_CTX *)b->ptr; |
@@ -379,6 +389,9 @@ static int b64_write(BIO *b, const char *in, int inl) | |||
379 | EVP_EncodeInit(&(ctx->base64)); | 389 | EVP_EncodeInit(&(ctx->base64)); |
380 | } | 390 | } |
381 | 391 | ||
392 | OPENSSL_assert(ctx->buf_off < (int)sizeof(ctx->buf)); | ||
393 | OPENSSL_assert(ctx->buf_len <= (int)sizeof(ctx->buf)); | ||
394 | OPENSSL_assert(ctx->buf_len >= ctx->buf_off); | ||
382 | n=ctx->buf_len-ctx->buf_off; | 395 | n=ctx->buf_len-ctx->buf_off; |
383 | while (n > 0) | 396 | while (n > 0) |
384 | { | 397 | { |
@@ -388,7 +401,10 @@ static int b64_write(BIO *b, const char *in, int inl) | |||
388 | BIO_copy_next_retry(b); | 401 | BIO_copy_next_retry(b); |
389 | return(i); | 402 | return(i); |
390 | } | 403 | } |
404 | OPENSSL_assert(i <= n); | ||
391 | ctx->buf_off+=i; | 405 | ctx->buf_off+=i; |
406 | OPENSSL_assert(ctx->buf_off <= (int)sizeof(ctx->buf)); | ||
407 | OPENSSL_assert(ctx->buf_len >= ctx->buf_off); | ||
392 | n-=i; | 408 | n-=i; |
393 | } | 409 | } |
394 | /* at this point all pending data has been written */ | 410 | /* at this point all pending data has been written */ |
@@ -405,18 +421,19 @@ static int b64_write(BIO *b, const char *in, int inl) | |||
405 | { | 421 | { |
406 | if (ctx->tmp_len > 0) | 422 | if (ctx->tmp_len > 0) |
407 | { | 423 | { |
424 | OPENSSL_assert(ctx->tmp_len <= 3); | ||
408 | n=3-ctx->tmp_len; | 425 | n=3-ctx->tmp_len; |
409 | /* There's a teoretical possibility for this */ | 426 | /* There's a theoretical possibility for this */ |
410 | if (n > inl) | 427 | if (n > inl) |
411 | n=inl; | 428 | n=inl; |
412 | memcpy(&(ctx->tmp[ctx->tmp_len]),in,n); | 429 | memcpy(&(ctx->tmp[ctx->tmp_len]),in,n); |
413 | ctx->tmp_len+=n; | 430 | ctx->tmp_len+=n; |
431 | ret += n; | ||
414 | if (ctx->tmp_len < 3) | 432 | if (ctx->tmp_len < 3) |
415 | break; | 433 | break; |
416 | ctx->buf_len=EVP_EncodeBlock( | 434 | ctx->buf_len=EVP_EncodeBlock((unsigned char *)ctx->buf,(unsigned char *)ctx->tmp,ctx->tmp_len); |
417 | (unsigned char *)ctx->buf, | 435 | OPENSSL_assert(ctx->buf_len <= (int)sizeof(ctx->buf)); |
418 | (unsigned char *)ctx->tmp, | 436 | OPENSSL_assert(ctx->buf_len >= ctx->buf_off); |
419 | ctx->tmp_len); | ||
420 | /* Since we're now done using the temporary | 437 | /* Since we're now done using the temporary |
421 | buffer, the length should be 0'd */ | 438 | buffer, the length should be 0'd */ |
422 | ctx->tmp_len=0; | 439 | ctx->tmp_len=0; |
@@ -425,14 +442,16 @@ static int b64_write(BIO *b, const char *in, int inl) | |||
425 | { | 442 | { |
426 | if (n < 3) | 443 | if (n < 3) |
427 | { | 444 | { |
428 | memcpy(&(ctx->tmp[0]),in,n); | 445 | memcpy(ctx->tmp,in,n); |
429 | ctx->tmp_len=n; | 446 | ctx->tmp_len=n; |
447 | ret += n; | ||
430 | break; | 448 | break; |
431 | } | 449 | } |
432 | n-=n%3; | 450 | n-=n%3; |
433 | ctx->buf_len=EVP_EncodeBlock( | 451 | ctx->buf_len=EVP_EncodeBlock((unsigned char *)ctx->buf,(const unsigned char *)in,n); |
434 | (unsigned char *)ctx->buf, | 452 | OPENSSL_assert(ctx->buf_len <= (int)sizeof(ctx->buf)); |
435 | (unsigned char *)in,n); | 453 | OPENSSL_assert(ctx->buf_len >= ctx->buf_off); |
454 | ret += n; | ||
436 | } | 455 | } |
437 | } | 456 | } |
438 | else | 457 | else |
@@ -440,6 +459,9 @@ static int b64_write(BIO *b, const char *in, int inl) | |||
440 | EVP_EncodeUpdate(&(ctx->base64), | 459 | EVP_EncodeUpdate(&(ctx->base64), |
441 | (unsigned char *)ctx->buf,&ctx->buf_len, | 460 | (unsigned char *)ctx->buf,&ctx->buf_len, |
442 | (unsigned char *)in,n); | 461 | (unsigned char *)in,n); |
462 | OPENSSL_assert(ctx->buf_len <= (int)sizeof(ctx->buf)); | ||
463 | OPENSSL_assert(ctx->buf_len >= ctx->buf_off); | ||
464 | ret += n; | ||
443 | } | 465 | } |
444 | inl-=n; | 466 | inl-=n; |
445 | in+=n; | 467 | in+=n; |
@@ -454,8 +476,11 @@ static int b64_write(BIO *b, const char *in, int inl) | |||
454 | BIO_copy_next_retry(b); | 476 | BIO_copy_next_retry(b); |
455 | return((ret == 0)?i:ret); | 477 | return((ret == 0)?i:ret); |
456 | } | 478 | } |
479 | OPENSSL_assert(i <= n); | ||
457 | n-=i; | 480 | n-=i; |
458 | ctx->buf_off+=i; | 481 | ctx->buf_off+=i; |
482 | OPENSSL_assert(ctx->buf_off <= (int)sizeof(ctx->buf)); | ||
483 | OPENSSL_assert(ctx->buf_len >= ctx->buf_off); | ||
459 | } | 484 | } |
460 | ctx->buf_len=0; | 485 | ctx->buf_len=0; |
461 | ctx->buf_off=0; | 486 | ctx->buf_off=0; |
@@ -486,6 +511,7 @@ static long b64_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
486 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | 511 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); |
487 | break; | 512 | break; |
488 | case BIO_CTRL_WPENDING: /* More to write in buffer */ | 513 | case BIO_CTRL_WPENDING: /* More to write in buffer */ |
514 | OPENSSL_assert(ctx->buf_len >= ctx->buf_off); | ||
489 | ret=ctx->buf_len-ctx->buf_off; | 515 | ret=ctx->buf_len-ctx->buf_off; |
490 | if ((ret == 0) && (ctx->encode != B64_NONE) | 516 | if ((ret == 0) && (ctx->encode != B64_NONE) |
491 | && (ctx->base64.num != 0)) | 517 | && (ctx->base64.num != 0)) |
@@ -494,6 +520,7 @@ static long b64_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
494 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | 520 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); |
495 | break; | 521 | break; |
496 | case BIO_CTRL_PENDING: /* More to read in buffer */ | 522 | case BIO_CTRL_PENDING: /* More to read in buffer */ |
523 | OPENSSL_assert(ctx->buf_len >= ctx->buf_off); | ||
497 | ret=ctx->buf_len-ctx->buf_off; | 524 | ret=ctx->buf_len-ctx->buf_off; |
498 | if (ret <= 0) | 525 | if (ret <= 0) |
499 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | 526 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); |
@@ -565,3 +592,7 @@ static long b64_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) | |||
565 | return(ret); | 592 | return(ret); |
566 | } | 593 | } |
567 | 594 | ||
595 | static int b64_puts(BIO *b, const char *str) | ||
596 | { | ||
597 | return b64_write(b,str,strlen(str)); | ||
598 | } | ||