summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/bio/bf_nbio.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/bio/bf_nbio.c')
-rw-r--r--src/lib/libcrypto/bio/bf_nbio.c79
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 68static int nbiof_write(BIO *h,const char *buf,int num);
70static int nbiof_write(BIO *h,char *buf,int num);
71static int nbiof_read(BIO *h,char *buf,int size); 69static int nbiof_read(BIO *h,char *buf,int size);
72static int nbiof_puts(BIO *h,char *str); 70static int nbiof_puts(BIO *h,const char *str);
73static int nbiof_gets(BIO *h,char *str,int size); 71static int nbiof_gets(BIO *h,char *str,int size);
74static long nbiof_ctrl(BIO *h,int cmd,long arg1,char *arg2); 72static long nbiof_ctrl(BIO *h,int cmd,long arg1,void *arg2);
75static int nbiof_new(BIO *h); 73static int nbiof_new(BIO *h);
76static int nbiof_free(BIO *data); 74static int nbiof_free(BIO *data);
77#else 75static long nbiof_callback_ctrl(BIO *h,int cmd,bio_info_cb *fp);
78static int nbiof_write();
79static int nbiof_read();
80static int nbiof_puts();
81static int nbiof_gets();
82static long nbiof_ctrl();
83static int nbiof_new();
84static int nbiof_free();
85#endif
86
87typedef struct nbio_test_st 76typedef 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
107BIO_METHOD *BIO_f_nbio_test() 97BIO_METHOD *BIO_f_nbio_test(void)
108 { 98 {
109 return(&methods_nbiof); 99 return(&methods_nbiof);
110 } 100 }
111 101
112static int nbiof_new(bi) 102static int nbiof_new(BIO *bi)
113BIO *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
126static int nbiof_free(a) 115static int nbiof_free(BIO *a)
127BIO *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
138static int nbiof_read(b,out,outl) 126static int nbiof_read(BIO *b, char *out, int outl)
139BIO *b;
140char *out;
141int 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
176static int nbiof_write(b,in,inl) 161static int nbiof_write(BIO *b, const char *in, int inl)
177BIO *b;
178char *in;
179int 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
224static long nbiof_ctrl(b,cmd,num,ptr) 206static long nbiof_ctrl(BIO *b, int cmd, long num, void *ptr)
225BIO *b;
226int cmd;
227long num;
228char *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
250static int nbiof_gets(bp,buf,size) 228static long nbiof_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
251BIO *bp; 229 {
252char *buf; 230 long ret=1;
253int 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
242static 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
260static int nbiof_puts(bp,str) 249static int nbiof_puts(BIO *bp, const char *str)
261BIO *bp;
262char *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));