diff options
Diffstat (limited to 'src/lib/libcrypto/bio/bf_nbio.c')
| -rw-r--r-- | src/lib/libcrypto/bio/bf_nbio.c | 79 |
1 files changed, 33 insertions, 46 deletions
diff --git a/src/lib/libcrypto/bio/bf_nbio.c b/src/lib/libcrypto/bio/bf_nbio.c index 034b3024df..1ce2bfacc0 100644 --- a/src/lib/libcrypto/bio/bf_nbio.c +++ b/src/lib/libcrypto/bio/bf_nbio.c | |||
| @@ -59,31 +59,20 @@ | |||
| 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 "rand.h" | 62 | #include <openssl/rand.h> |
| 63 | #include "bio.h" | 63 | #include <openssl/bio.h> |
| 64 | #include "evp.h" | ||
| 65 | 64 | ||
| 66 | /* BIO_put and BIO_get both add to the digest, | 65 | /* BIO_put and BIO_get both add to the digest, |
| 67 | * BIO_gets returns the digest */ | 66 | * BIO_gets returns the digest */ |
| 68 | 67 | ||
| 69 | #ifndef NOPROTO | 68 | static int nbiof_write(BIO *h,const char *buf,int num); |
| 70 | static int nbiof_write(BIO *h,char *buf,int num); | ||
| 71 | static int nbiof_read(BIO *h,char *buf,int size); | 69 | static int nbiof_read(BIO *h,char *buf,int size); |
| 72 | static int nbiof_puts(BIO *h,char *str); | 70 | static int nbiof_puts(BIO *h,const char *str); |
| 73 | static int nbiof_gets(BIO *h,char *str,int size); | 71 | static int nbiof_gets(BIO *h,char *str,int size); |
| 74 | static long nbiof_ctrl(BIO *h,int cmd,long arg1,char *arg2); | 72 | static long nbiof_ctrl(BIO *h,int cmd,long arg1,void *arg2); |
| 75 | static int nbiof_new(BIO *h); | 73 | static int nbiof_new(BIO *h); |
| 76 | static int nbiof_free(BIO *data); | 74 | static int nbiof_free(BIO *data); |
| 77 | #else | 75 | static long nbiof_callback_ctrl(BIO *h,int cmd,bio_info_cb *fp); |
| 78 | static int nbiof_write(); | ||
| 79 | static int nbiof_read(); | ||
| 80 | static int nbiof_puts(); | ||
| 81 | static int nbiof_gets(); | ||
| 82 | static long nbiof_ctrl(); | ||
| 83 | static int nbiof_new(); | ||
| 84 | static int nbiof_free(); | ||
| 85 | #endif | ||
| 86 | |||
| 87 | typedef struct nbio_test_st | 76 | typedef struct nbio_test_st |
| 88 | { | 77 | { |
| 89 | /* only set if we sent a 'should retry' error */ | 78 | /* only set if we sent a 'should retry' error */ |
| @@ -102,19 +91,19 @@ static BIO_METHOD methods_nbiof= | |||
| 102 | nbiof_ctrl, | 91 | nbiof_ctrl, |
| 103 | nbiof_new, | 92 | nbiof_new, |
| 104 | nbiof_free, | 93 | nbiof_free, |
| 94 | nbiof_callback_ctrl, | ||
| 105 | }; | 95 | }; |
| 106 | 96 | ||
| 107 | BIO_METHOD *BIO_f_nbio_test() | 97 | BIO_METHOD *BIO_f_nbio_test(void) |
| 108 | { | 98 | { |
| 109 | return(&methods_nbiof); | 99 | return(&methods_nbiof); |
| 110 | } | 100 | } |
| 111 | 101 | ||
| 112 | static int nbiof_new(bi) | 102 | static int nbiof_new(BIO *bi) |
| 113 | BIO *bi; | ||
| 114 | { | 103 | { |
| 115 | NBIO_TEST *nt; | 104 | NBIO_TEST *nt; |
| 116 | 105 | ||
| 117 | nt=(NBIO_TEST *)Malloc(sizeof(NBIO_TEST)); | 106 | if (!(nt=(NBIO_TEST *)OPENSSL_malloc(sizeof(NBIO_TEST)))) return(0); |
| 118 | nt->lrn= -1; | 107 | nt->lrn= -1; |
| 119 | nt->lwn= -1; | 108 | nt->lwn= -1; |
| 120 | bi->ptr=(char *)nt; | 109 | bi->ptr=(char *)nt; |
| @@ -123,22 +112,18 @@ BIO *bi; | |||
| 123 | return(1); | 112 | return(1); |
| 124 | } | 113 | } |
| 125 | 114 | ||
| 126 | static int nbiof_free(a) | 115 | static int nbiof_free(BIO *a) |
| 127 | BIO *a; | ||
| 128 | { | 116 | { |
| 129 | if (a == NULL) return(0); | 117 | if (a == NULL) return(0); |
| 130 | if (a->ptr != NULL) | 118 | if (a->ptr != NULL) |
| 131 | Free(a->ptr); | 119 | OPENSSL_free(a->ptr); |
| 132 | a->ptr=NULL; | 120 | a->ptr=NULL; |
| 133 | a->init=0; | 121 | a->init=0; |
| 134 | a->flags=0; | 122 | a->flags=0; |
| 135 | return(1); | 123 | return(1); |
| 136 | } | 124 | } |
| 137 | 125 | ||
| 138 | static int nbiof_read(b,out,outl) | 126 | static int nbiof_read(BIO *b, char *out, int outl) |
| 139 | BIO *b; | ||
| 140 | char *out; | ||
| 141 | int outl; | ||
| 142 | { | 127 | { |
| 143 | NBIO_TEST *nt; | 128 | NBIO_TEST *nt; |
| 144 | int ret=0; | 129 | int ret=0; |
| @@ -153,7 +138,7 @@ int outl; | |||
| 153 | 138 | ||
| 154 | BIO_clear_retry_flags(b); | 139 | BIO_clear_retry_flags(b); |
| 155 | #if 0 | 140 | #if 0 |
| 156 | RAND_bytes(&n,1); | 141 | RAND_pseudo_bytes(&n,1); |
| 157 | num=(n&0x07); | 142 | num=(n&0x07); |
| 158 | 143 | ||
| 159 | if (outl > num) outl=num; | 144 | if (outl > num) outl=num; |
| @@ -173,10 +158,7 @@ int outl; | |||
| 173 | return(ret); | 158 | return(ret); |
| 174 | } | 159 | } |
| 175 | 160 | ||
| 176 | static int nbiof_write(b,in,inl) | 161 | static int nbiof_write(BIO *b, const char *in, int inl) |
| 177 | BIO *b; | ||
| 178 | char *in; | ||
| 179 | int inl; | ||
| 180 | { | 162 | { |
| 181 | NBIO_TEST *nt; | 163 | NBIO_TEST *nt; |
| 182 | int ret=0; | 164 | int ret=0; |
| @@ -197,7 +179,7 @@ int inl; | |||
| 197 | } | 179 | } |
| 198 | else | 180 | else |
| 199 | { | 181 | { |
| 200 | RAND_bytes(&n,1); | 182 | RAND_pseudo_bytes(&n,1); |
| 201 | num=(n&7); | 183 | num=(n&7); |
| 202 | } | 184 | } |
| 203 | 185 | ||
| @@ -221,11 +203,7 @@ int inl; | |||
| 221 | return(ret); | 203 | return(ret); |
| 222 | } | 204 | } |
| 223 | 205 | ||
| 224 | static long nbiof_ctrl(b,cmd,num,ptr) | 206 | static long nbiof_ctrl(BIO *b, int cmd, long num, void *ptr) |
| 225 | BIO *b; | ||
| 226 | int cmd; | ||
| 227 | long num; | ||
| 228 | char *ptr; | ||
| 229 | { | 207 | { |
| 230 | long ret; | 208 | long ret; |
| 231 | 209 | ||
| @@ -247,19 +225,28 @@ char *ptr; | |||
| 247 | return(ret); | 225 | return(ret); |
| 248 | } | 226 | } |
| 249 | 227 | ||
| 250 | static int nbiof_gets(bp,buf,size) | 228 | static long nbiof_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) |
| 251 | BIO *bp; | 229 | { |
| 252 | char *buf; | 230 | long ret=1; |
| 253 | int size; | 231 | |
| 232 | if (b->next_bio == NULL) return(0); | ||
| 233 | switch (cmd) | ||
| 234 | { | ||
| 235 | default: | ||
| 236 | ret=BIO_callback_ctrl(b->next_bio,cmd,fp); | ||
| 237 | break; | ||
| 238 | } | ||
| 239 | return(ret); | ||
| 240 | } | ||
| 241 | |||
| 242 | static int nbiof_gets(BIO *bp, char *buf, int size) | ||
| 254 | { | 243 | { |
| 255 | if (bp->next_bio == NULL) return(0); | 244 | if (bp->next_bio == NULL) return(0); |
| 256 | return(BIO_gets(bp->next_bio,buf,size)); | 245 | return(BIO_gets(bp->next_bio,buf,size)); |
| 257 | } | 246 | } |
| 258 | 247 | ||
| 259 | 248 | ||
| 260 | static int nbiof_puts(bp,str) | 249 | static int nbiof_puts(BIO *bp, const char *str) |
| 261 | BIO *bp; | ||
| 262 | char *str; | ||
| 263 | { | 250 | { |
| 264 | if (bp->next_bio == NULL) return(0); | 251 | if (bp->next_bio == NULL) return(0); |
| 265 | return(BIO_puts(bp->next_bio,str)); | 252 | return(BIO_puts(bp->next_bio,str)); |
