diff options
Diffstat (limited to 'src/lib/libcrypto/evp/bio_ok.c')
| -rw-r--r-- | src/lib/libcrypto/evp/bio_ok.c | 60 |
1 files changed, 30 insertions, 30 deletions
diff --git a/src/lib/libcrypto/evp/bio_ok.c b/src/lib/libcrypto/evp/bio_ok.c index 4e3f10141b..98bc1ab409 100644 --- a/src/lib/libcrypto/evp/bio_ok.c +++ b/src/lib/libcrypto/evp/bio_ok.c | |||
| @@ -119,6 +119,7 @@ | |||
| 119 | 119 | ||
| 120 | #include <stdio.h> | 120 | #include <stdio.h> |
| 121 | #include <errno.h> | 121 | #include <errno.h> |
| 122 | #include <assert.h> | ||
| 122 | #include "cryptlib.h" | 123 | #include "cryptlib.h" |
| 123 | #include <openssl/buffer.h> | 124 | #include <openssl/buffer.h> |
| 124 | #include <openssl/bio.h> | 125 | #include <openssl/bio.h> |
| @@ -141,22 +142,12 @@ static void block_in(BIO* b); | |||
| 141 | #define IOBS (OK_BLOCK_SIZE+ OK_BLOCK_BLOCK+ 3*EVP_MAX_MD_SIZE) | 142 | #define IOBS (OK_BLOCK_SIZE+ OK_BLOCK_BLOCK+ 3*EVP_MAX_MD_SIZE) |
| 142 | #define WELLKNOWN "The quick brown fox jumped over the lazy dog's back." | 143 | #define WELLKNOWN "The quick brown fox jumped over the lazy dog's back." |
| 143 | 144 | ||
| 144 | #ifndef L_ENDIAN | ||
| 145 | #define swapem(x) \ | ||
| 146 | ((unsigned long int)((((unsigned long int)(x) & 0x000000ffU) << 24) | \ | ||
| 147 | (((unsigned long int)(x) & 0x0000ff00U) << 8) | \ | ||
| 148 | (((unsigned long int)(x) & 0x00ff0000U) >> 8) | \ | ||
| 149 | (((unsigned long int)(x) & 0xff000000U) >> 24))) | ||
| 150 | #else | ||
| 151 | #define swapem(x) (x) | ||
| 152 | #endif | ||
| 153 | |||
| 154 | typedef struct ok_struct | 145 | typedef struct ok_struct |
| 155 | { | 146 | { |
| 156 | int buf_len; | 147 | size_t buf_len; |
| 157 | int buf_off; | 148 | size_t buf_off; |
| 158 | int buf_len_save; | 149 | size_t buf_len_save; |
| 159 | int buf_off_save; | 150 | size_t buf_off_save; |
| 160 | int cont; /* <= 0 when finished */ | 151 | int cont; /* <= 0 when finished */ |
| 161 | int finished; | 152 | int finished; |
| 162 | EVP_MD_CTX md; | 153 | EVP_MD_CTX md; |
| @@ -295,6 +286,8 @@ static int ok_write(BIO *b, const char *in, int inl) | |||
| 295 | int ret=0,n,i; | 286 | int ret=0,n,i; |
| 296 | BIO_OK_CTX *ctx; | 287 | BIO_OK_CTX *ctx; |
| 297 | 288 | ||
| 289 | if (inl <= 0) return inl; | ||
| 290 | |||
| 298 | ctx=(BIO_OK_CTX *)b->ptr; | 291 | ctx=(BIO_OK_CTX *)b->ptr; |
| 299 | ret=inl; | 292 | ret=inl; |
| 300 | 293 | ||
| @@ -330,7 +323,7 @@ static int ok_write(BIO *b, const char *in, int inl) | |||
| 330 | if ((in == NULL) || (inl <= 0)) return(0); | 323 | if ((in == NULL) || (inl <= 0)) return(0); |
| 331 | 324 | ||
| 332 | n= (inl+ ctx->buf_len > OK_BLOCK_SIZE+ OK_BLOCK_BLOCK) ? | 325 | n= (inl+ ctx->buf_len > OK_BLOCK_SIZE+ OK_BLOCK_BLOCK) ? |
| 333 | OK_BLOCK_SIZE+ OK_BLOCK_BLOCK- ctx->buf_len : inl; | 326 | (int)(OK_BLOCK_SIZE+OK_BLOCK_BLOCK-ctx->buf_len) : inl; |
| 334 | 327 | ||
| 335 | memcpy((unsigned char *)(&(ctx->buf[ctx->buf_len])),(unsigned char *)in,n); | 328 | memcpy((unsigned char *)(&(ctx->buf[ctx->buf_len])),(unsigned char *)in,n); |
| 336 | ctx->buf_len+= n; | 329 | ctx->buf_len+= n; |
| @@ -448,16 +441,18 @@ static long ok_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) | |||
| 448 | return(ret); | 441 | return(ret); |
| 449 | } | 442 | } |
| 450 | 443 | ||
| 451 | static void longswap(void *_ptr, int len) | 444 | static void longswap(void *_ptr, size_t len) |
| 452 | { | 445 | { const union { long one; char little; } is_endian = {1}; |
| 453 | #ifndef L_ENDIAN | ||
| 454 | int i; | ||
| 455 | char *ptr=_ptr; | ||
| 456 | 446 | ||
| 457 | for(i= 0;i < len;i+= 4){ | 447 | if (is_endian.little) { |
| 458 | *((unsigned long *)&(ptr[i]))= swapem(*((unsigned long *)&(ptr[i]))); | 448 | size_t i; |
| 449 | unsigned char *p=_ptr,c; | ||
| 450 | |||
| 451 | for(i= 0;i < len;i+= 4) { | ||
| 452 | c=p[0],p[0]=p[3],p[3]=c; | ||
| 453 | c=p[1],p[1]=p[2],p[2]=c; | ||
| 454 | } | ||
| 459 | } | 455 | } |
| 460 | #endif | ||
| 461 | } | 456 | } |
| 462 | 457 | ||
| 463 | static void sig_out(BIO* b) | 458 | static void sig_out(BIO* b) |
| @@ -496,7 +491,7 @@ static void sig_in(BIO* b) | |||
| 496 | ctx=b->ptr; | 491 | ctx=b->ptr; |
| 497 | md=&ctx->md; | 492 | md=&ctx->md; |
| 498 | 493 | ||
| 499 | if(ctx->buf_len- ctx->buf_off < 2* md->digest->md_size) return; | 494 | if((int)(ctx->buf_len-ctx->buf_off) < 2*md->digest->md_size) return; |
| 500 | 495 | ||
| 501 | EVP_DigestInit_ex(md, md->digest, NULL); | 496 | EVP_DigestInit_ex(md, md->digest, NULL); |
| 502 | memcpy(md->md_data, &(ctx->buf[ctx->buf_off]), md->digest->md_size); | 497 | memcpy(md->md_data, &(ctx->buf[ctx->buf_off]), md->digest->md_size); |
| @@ -533,9 +528,10 @@ static void block_out(BIO* b) | |||
| 533 | md=&ctx->md; | 528 | md=&ctx->md; |
| 534 | 529 | ||
| 535 | tl= ctx->buf_len- OK_BLOCK_BLOCK; | 530 | tl= ctx->buf_len- OK_BLOCK_BLOCK; |
| 536 | tl= swapem(tl); | 531 | ctx->buf[0]=(unsigned char)(tl>>24); |
| 537 | memcpy(ctx->buf, &tl, OK_BLOCK_BLOCK); | 532 | ctx->buf[1]=(unsigned char)(tl>>16); |
| 538 | tl= swapem(tl); | 533 | ctx->buf[2]=(unsigned char)(tl>>8); |
| 534 | ctx->buf[3]=(unsigned char)(tl); | ||
| 539 | EVP_DigestUpdate(md, (unsigned char*) &(ctx->buf[OK_BLOCK_BLOCK]), tl); | 535 | EVP_DigestUpdate(md, (unsigned char*) &(ctx->buf[OK_BLOCK_BLOCK]), tl); |
| 540 | EVP_DigestFinal_ex(md, &(ctx->buf[ctx->buf_len]), NULL); | 536 | EVP_DigestFinal_ex(md, &(ctx->buf[ctx->buf_len]), NULL); |
| 541 | ctx->buf_len+= md->digest->md_size; | 537 | ctx->buf_len+= md->digest->md_size; |
| @@ -546,14 +542,18 @@ static void block_in(BIO* b) | |||
| 546 | { | 542 | { |
| 547 | BIO_OK_CTX *ctx; | 543 | BIO_OK_CTX *ctx; |
| 548 | EVP_MD_CTX *md; | 544 | EVP_MD_CTX *md; |
| 549 | long tl= 0; | 545 | unsigned long tl= 0; |
| 550 | unsigned char tmp[EVP_MAX_MD_SIZE]; | 546 | unsigned char tmp[EVP_MAX_MD_SIZE]; |
| 551 | 547 | ||
| 552 | ctx=b->ptr; | 548 | ctx=b->ptr; |
| 553 | md=&ctx->md; | 549 | md=&ctx->md; |
| 554 | 550 | ||
| 555 | memcpy(&tl, ctx->buf, OK_BLOCK_BLOCK); | 551 | assert(sizeof(tl)>=OK_BLOCK_BLOCK); /* always true */ |
| 556 | tl= swapem(tl); | 552 | tl =ctx->buf[0]; tl<<=8; |
| 553 | tl|=ctx->buf[1]; tl<<=8; | ||
| 554 | tl|=ctx->buf[2]; tl<<=8; | ||
| 555 | tl|=ctx->buf[3]; | ||
| 556 | |||
| 557 | if (ctx->buf_len < tl+ OK_BLOCK_BLOCK+ md->digest->md_size) return; | 557 | if (ctx->buf_len < tl+ OK_BLOCK_BLOCK+ md->digest->md_size) return; |
| 558 | 558 | ||
| 559 | EVP_DigestUpdate(md, (unsigned char*) &(ctx->buf[OK_BLOCK_BLOCK]), tl); | 559 | EVP_DigestUpdate(md, (unsigned char*) &(ctx->buf[OK_BLOCK_BLOCK]), tl); |
