diff options
Diffstat (limited to 'src/lib/libcrypto/bio/bf_buff.c')
-rw-r--r-- | src/lib/libcrypto/bio/bf_buff.c | 120 |
1 files changed, 59 insertions, 61 deletions
diff --git a/src/lib/libcrypto/bio/bf_buff.c b/src/lib/libcrypto/bio/bf_buff.c index 7912b88473..6ccda06596 100644 --- a/src/lib/libcrypto/bio/bf_buff.c +++ b/src/lib/libcrypto/bio/bf_buff.c | |||
@@ -59,28 +59,17 @@ | |||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include <errno.h> | 60 | #include <errno.h> |
61 | #include "cryptlib.h" | 61 | #include "cryptlib.h" |
62 | #include "bio.h" | 62 | #include <openssl/bio.h> |
63 | #include "evp.h" | 63 | |
64 | 64 | static int buffer_write(BIO *h, const char *buf,int num); | |
65 | #ifndef NOPROTO | 65 | static int buffer_read(BIO *h, char *buf, int size); |
66 | static int buffer_write(BIO *h,char *buf,int num); | 66 | static int buffer_puts(BIO *h, const char *str); |
67 | static int buffer_read(BIO *h,char *buf,int size); | 67 | static int buffer_gets(BIO *h, char *str, int size); |
68 | static int buffer_puts(BIO *h,char *str); | 68 | static long buffer_ctrl(BIO *h, int cmd, long arg1, void *arg2); |
69 | static int buffer_gets(BIO *h,char *str,int size); | ||
70 | static long buffer_ctrl(BIO *h,int cmd,long arg1,char *arg2); | ||
71 | static int buffer_new(BIO *h); | 69 | static int buffer_new(BIO *h); |
72 | static int buffer_free(BIO *data); | 70 | static int buffer_free(BIO *data); |
73 | #else | 71 | static long buffer_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp); |
74 | static int buffer_write(); | 72 | #define DEFAULT_BUFFER_SIZE 4096 |
75 | static int buffer_read(); | ||
76 | static int buffer_puts(); | ||
77 | static int buffer_gets(); | ||
78 | static long buffer_ctrl(); | ||
79 | static int buffer_new(); | ||
80 | static int buffer_free(); | ||
81 | #endif | ||
82 | |||
83 | #define DEFAULT_BUFFER_SIZE 1024 | ||
84 | 73 | ||
85 | static BIO_METHOD methods_buffer= | 74 | static BIO_METHOD methods_buffer= |
86 | { | 75 | { |
@@ -93,24 +82,24 @@ static BIO_METHOD methods_buffer= | |||
93 | buffer_ctrl, | 82 | buffer_ctrl, |
94 | buffer_new, | 83 | buffer_new, |
95 | buffer_free, | 84 | buffer_free, |
85 | buffer_callback_ctrl, | ||
96 | }; | 86 | }; |
97 | 87 | ||
98 | BIO_METHOD *BIO_f_buffer() | 88 | BIO_METHOD *BIO_f_buffer(void) |
99 | { | 89 | { |
100 | return(&methods_buffer); | 90 | return(&methods_buffer); |
101 | } | 91 | } |
102 | 92 | ||
103 | static int buffer_new(bi) | 93 | static int buffer_new(BIO *bi) |
104 | BIO *bi; | ||
105 | { | 94 | { |
106 | BIO_F_BUFFER_CTX *ctx; | 95 | BIO_F_BUFFER_CTX *ctx; |
107 | 96 | ||
108 | ctx=(BIO_F_BUFFER_CTX *)Malloc(sizeof(BIO_F_BUFFER_CTX)); | 97 | ctx=(BIO_F_BUFFER_CTX *)OPENSSL_malloc(sizeof(BIO_F_BUFFER_CTX)); |
109 | if (ctx == NULL) return(0); | 98 | if (ctx == NULL) return(0); |
110 | ctx->ibuf=(char *)Malloc(DEFAULT_BUFFER_SIZE); | 99 | ctx->ibuf=(char *)OPENSSL_malloc(DEFAULT_BUFFER_SIZE); |
111 | if (ctx->ibuf == NULL) { Free(ctx); return(0); } | 100 | if (ctx->ibuf == NULL) { OPENSSL_free(ctx); return(0); } |
112 | ctx->obuf=(char *)Malloc(DEFAULT_BUFFER_SIZE); | 101 | ctx->obuf=(char *)OPENSSL_malloc(DEFAULT_BUFFER_SIZE); |
113 | if (ctx->obuf == NULL) { Free(ctx->ibuf); Free(ctx); return(0); } | 102 | if (ctx->obuf == NULL) { OPENSSL_free(ctx->ibuf); OPENSSL_free(ctx); return(0); } |
114 | ctx->ibuf_size=DEFAULT_BUFFER_SIZE; | 103 | ctx->ibuf_size=DEFAULT_BUFFER_SIZE; |
115 | ctx->obuf_size=DEFAULT_BUFFER_SIZE; | 104 | ctx->obuf_size=DEFAULT_BUFFER_SIZE; |
116 | ctx->ibuf_len=0; | 105 | ctx->ibuf_len=0; |
@@ -124,26 +113,22 @@ BIO *bi; | |||
124 | return(1); | 113 | return(1); |
125 | } | 114 | } |
126 | 115 | ||
127 | static int buffer_free(a) | 116 | static int buffer_free(BIO *a) |
128 | BIO *a; | ||
129 | { | 117 | { |
130 | BIO_F_BUFFER_CTX *b; | 118 | BIO_F_BUFFER_CTX *b; |
131 | 119 | ||
132 | if (a == NULL) return(0); | 120 | if (a == NULL) return(0); |
133 | b=(BIO_F_BUFFER_CTX *)a->ptr; | 121 | b=(BIO_F_BUFFER_CTX *)a->ptr; |
134 | if (b->ibuf != NULL) Free(b->ibuf); | 122 | if (b->ibuf != NULL) OPENSSL_free(b->ibuf); |
135 | if (b->obuf != NULL) Free(b->obuf); | 123 | if (b->obuf != NULL) OPENSSL_free(b->obuf); |
136 | Free(a->ptr); | 124 | OPENSSL_free(a->ptr); |
137 | a->ptr=NULL; | 125 | a->ptr=NULL; |
138 | a->init=0; | 126 | a->init=0; |
139 | a->flags=0; | 127 | a->flags=0; |
140 | return(1); | 128 | return(1); |
141 | } | 129 | } |
142 | 130 | ||
143 | static int buffer_read(b,out,outl) | 131 | static int buffer_read(BIO *b, char *out, int outl) |
144 | BIO *b; | ||
145 | char *out; | ||
146 | int outl; | ||
147 | { | 132 | { |
148 | int i,num=0; | 133 | int i,num=0; |
149 | BIO_F_BUFFER_CTX *ctx; | 134 | BIO_F_BUFFER_CTX *ctx; |
@@ -209,10 +194,7 @@ start: | |||
209 | goto start; | 194 | goto start; |
210 | } | 195 | } |
211 | 196 | ||
212 | static int buffer_write(b,in,inl) | 197 | static int buffer_write(BIO *b, const char *in, int inl) |
213 | BIO *b; | ||
214 | char *in; | ||
215 | int inl; | ||
216 | { | 198 | { |
217 | int i,num=0; | 199 | int i,num=0; |
218 | BIO_F_BUFFER_CTX *ctx; | 200 | BIO_F_BUFFER_CTX *ctx; |
@@ -285,11 +267,7 @@ start: | |||
285 | goto start; | 267 | goto start; |
286 | } | 268 | } |
287 | 269 | ||
288 | static long buffer_ctrl(b,cmd,num,ptr) | 270 | static long buffer_ctrl(BIO *b, int cmd, long num, void *ptr) |
289 | BIO *b; | ||
290 | int cmd; | ||
291 | long num; | ||
292 | char *ptr; | ||
293 | { | 271 | { |
294 | BIO *dbio; | 272 | BIO *dbio; |
295 | BIO_F_BUFFER_CTX *ctx; | 273 | BIO_F_BUFFER_CTX *ctx; |
@@ -307,6 +285,7 @@ char *ptr; | |||
307 | ctx->ibuf_len=0; | 285 | ctx->ibuf_len=0; |
308 | ctx->obuf_off=0; | 286 | ctx->obuf_off=0; |
309 | ctx->obuf_len=0; | 287 | ctx->obuf_len=0; |
288 | if (b->next_bio == NULL) return(0); | ||
310 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | 289 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); |
311 | break; | 290 | break; |
312 | case BIO_CTRL_INFO: | 291 | case BIO_CTRL_INFO: |
@@ -323,19 +302,25 @@ char *ptr; | |||
323 | case BIO_CTRL_WPENDING: | 302 | case BIO_CTRL_WPENDING: |
324 | ret=(long)ctx->obuf_len; | 303 | ret=(long)ctx->obuf_len; |
325 | if (ret == 0) | 304 | if (ret == 0) |
305 | { | ||
306 | if (b->next_bio == NULL) return(0); | ||
326 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | 307 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); |
308 | } | ||
327 | break; | 309 | break; |
328 | case BIO_CTRL_PENDING: | 310 | case BIO_CTRL_PENDING: |
329 | ret=(long)ctx->ibuf_len; | 311 | ret=(long)ctx->ibuf_len; |
330 | if (ret == 0) | 312 | if (ret == 0) |
313 | { | ||
314 | if (b->next_bio == NULL) return(0); | ||
331 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | 315 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); |
316 | } | ||
332 | break; | 317 | break; |
333 | case BIO_C_SET_BUFF_READ_DATA: | 318 | case BIO_C_SET_BUFF_READ_DATA: |
334 | if (num > ctx->ibuf_size) | 319 | if (num > ctx->ibuf_size) |
335 | { | 320 | { |
336 | p1=Malloc((int)num); | 321 | p1=OPENSSL_malloc((int)num); |
337 | if (p1 == NULL) goto malloc_error; | 322 | if (p1 == NULL) goto malloc_error; |
338 | if (ctx->ibuf != NULL) Free(ctx->ibuf); | 323 | if (ctx->ibuf != NULL) OPENSSL_free(ctx->ibuf); |
339 | ctx->ibuf=p1; | 324 | ctx->ibuf=p1; |
340 | } | 325 | } |
341 | ctx->ibuf_off=0; | 326 | ctx->ibuf_off=0; |
@@ -367,21 +352,21 @@ char *ptr; | |||
367 | p2=ctx->obuf; | 352 | p2=ctx->obuf; |
368 | if ((ibs > DEFAULT_BUFFER_SIZE) && (ibs != ctx->ibuf_size)) | 353 | if ((ibs > DEFAULT_BUFFER_SIZE) && (ibs != ctx->ibuf_size)) |
369 | { | 354 | { |
370 | p1=(char *)Malloc((int)num); | 355 | p1=(char *)OPENSSL_malloc((int)num); |
371 | if (p1 == NULL) goto malloc_error; | 356 | if (p1 == NULL) goto malloc_error; |
372 | } | 357 | } |
373 | if ((obs > DEFAULT_BUFFER_SIZE) && (obs != ctx->obuf_size)) | 358 | if ((obs > DEFAULT_BUFFER_SIZE) && (obs != ctx->obuf_size)) |
374 | { | 359 | { |
375 | p2=(char *)Malloc((int)num); | 360 | p2=(char *)OPENSSL_malloc((int)num); |
376 | if (p2 == NULL) | 361 | if (p2 == NULL) |
377 | { | 362 | { |
378 | if (p1 != ctx->ibuf) Free(p1); | 363 | if (p1 != ctx->ibuf) OPENSSL_free(p1); |
379 | goto malloc_error; | 364 | goto malloc_error; |
380 | } | 365 | } |
381 | } | 366 | } |
382 | if (ctx->ibuf != p1) | 367 | if (ctx->ibuf != p1) |
383 | { | 368 | { |
384 | Free(ctx->ibuf); | 369 | OPENSSL_free(ctx->ibuf); |
385 | ctx->ibuf=p1; | 370 | ctx->ibuf=p1; |
386 | ctx->ibuf_off=0; | 371 | ctx->ibuf_off=0; |
387 | ctx->ibuf_len=0; | 372 | ctx->ibuf_len=0; |
@@ -389,7 +374,7 @@ char *ptr; | |||
389 | } | 374 | } |
390 | if (ctx->obuf != p2) | 375 | if (ctx->obuf != p2) |
391 | { | 376 | { |
392 | Free(ctx->obuf); | 377 | OPENSSL_free(ctx->obuf); |
393 | ctx->obuf=p2; | 378 | ctx->obuf=p2; |
394 | ctx->obuf_off=0; | 379 | ctx->obuf_off=0; |
395 | ctx->obuf_len=0; | 380 | ctx->obuf_len=0; |
@@ -397,12 +382,14 @@ char *ptr; | |||
397 | } | 382 | } |
398 | break; | 383 | break; |
399 | case BIO_C_DO_STATE_MACHINE: | 384 | case BIO_C_DO_STATE_MACHINE: |
385 | if (b->next_bio == NULL) return(0); | ||
400 | BIO_clear_retry_flags(b); | 386 | BIO_clear_retry_flags(b); |
401 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | 387 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); |
402 | BIO_copy_next_retry(b); | 388 | BIO_copy_next_retry(b); |
403 | break; | 389 | break; |
404 | 390 | ||
405 | case BIO_CTRL_FLUSH: | 391 | case BIO_CTRL_FLUSH: |
392 | if (b->next_bio == NULL) return(0); | ||
406 | if (ctx->obuf_len <= 0) | 393 | if (ctx->obuf_len <= 0) |
407 | { | 394 | { |
408 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | 395 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); |
@@ -432,6 +419,7 @@ fprintf(stderr,"FLUSH [%3d] %3d -> %3d\n",ctx->obuf_off,ctx->obuf_len-ctx->obuf_ | |||
432 | break; | 419 | break; |
433 | } | 420 | } |
434 | } | 421 | } |
422 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
435 | break; | 423 | break; |
436 | case BIO_CTRL_DUP: | 424 | case BIO_CTRL_DUP: |
437 | dbio=(BIO *)ptr; | 425 | dbio=(BIO *)ptr; |
@@ -440,6 +428,7 @@ fprintf(stderr,"FLUSH [%3d] %3d -> %3d\n",ctx->obuf_off,ctx->obuf_len-ctx->obuf_ | |||
440 | ret=0; | 428 | ret=0; |
441 | break; | 429 | break; |
442 | default: | 430 | default: |
431 | if (b->next_bio == NULL) return(0); | ||
443 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | 432 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); |
444 | break; | 433 | break; |
445 | } | 434 | } |
@@ -449,10 +438,21 @@ malloc_error: | |||
449 | return(0); | 438 | return(0); |
450 | } | 439 | } |
451 | 440 | ||
452 | static int buffer_gets(b,buf,size) | 441 | static long buffer_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) |
453 | BIO *b; | 442 | { |
454 | char *buf; | 443 | long ret=1; |
455 | int size; | 444 | |
445 | if (b->next_bio == NULL) return(0); | ||
446 | switch (cmd) | ||
447 | { | ||
448 | default: | ||
449 | ret=BIO_callback_ctrl(b->next_bio,cmd,fp); | ||
450 | break; | ||
451 | } | ||
452 | return(ret); | ||
453 | } | ||
454 | |||
455 | static int buffer_gets(BIO *b, char *buf, int size) | ||
456 | { | 456 | { |
457 | BIO_F_BUFFER_CTX *ctx; | 457 | BIO_F_BUFFER_CTX *ctx; |
458 | int num=0,i,flag; | 458 | int num=0,i,flag; |
@@ -503,10 +503,8 @@ int size; | |||
503 | } | 503 | } |
504 | } | 504 | } |
505 | 505 | ||
506 | static int buffer_puts(b,str) | 506 | static int buffer_puts(BIO *b, const char *str) |
507 | BIO *b; | ||
508 | char *str; | ||
509 | { | 507 | { |
510 | return(BIO_write(b,str,strlen(str))); | 508 | return(buffer_write(b,str,strlen(str))); |
511 | } | 509 | } |
512 | 510 | ||