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