OLD | NEW |
1 /* crypto/evp/bio_md.c */ | 1 /* crypto/evp/bio_md.c */ |
2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 * All rights reserved. | 3 * All rights reserved. |
4 * | 4 * |
5 * This package is an SSL implementation written | 5 * This package is an SSL implementation written |
6 * by Eric Young (eay@cryptsoft.com). | 6 * by Eric Young (eay@cryptsoft.com). |
7 * The implementation was written so as to conform with Netscapes SSL. | 7 * The implementation was written so as to conform with Netscapes SSL. |
8 * | 8 * |
9 * This library is free for commercial and non-commercial use as long as | 9 * This library is free for commercial and non-commercial use as long as |
10 * the following conditions are aheared to. The following conditions | 10 * the following conditions are aheared to. The following conditions |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 if (out == NULL) return(0); | 123 if (out == NULL) return(0); |
124 ctx=b->ptr; | 124 ctx=b->ptr; |
125 | 125 |
126 if ((ctx == NULL) || (b->next_bio == NULL)) return(0); | 126 if ((ctx == NULL) || (b->next_bio == NULL)) return(0); |
127 | 127 |
128 ret=BIO_read(b->next_bio,out,outl); | 128 ret=BIO_read(b->next_bio,out,outl); |
129 if (b->init) | 129 if (b->init) |
130 { | 130 { |
131 if (ret > 0) | 131 if (ret > 0) |
132 { | 132 { |
133 » » » EVP_DigestUpdate(ctx,(unsigned char *)out, | 133 » » » if (EVP_DigestUpdate(ctx,(unsigned char *)out, |
134 » » » » (unsigned int)ret); | 134 » » » » (unsigned int)ret)<=0) return (-1); |
135 } | 135 } |
136 } | 136 } |
137 BIO_clear_retry_flags(b); | 137 BIO_clear_retry_flags(b); |
138 BIO_copy_next_retry(b); | 138 BIO_copy_next_retry(b); |
139 return(ret); | 139 return(ret); |
140 } | 140 } |
141 | 141 |
142 static int md_write(BIO *b, const char *in, int inl) | 142 static int md_write(BIO *b, const char *in, int inl) |
143 { | 143 { |
144 int ret=0; | 144 int ret=0; |
145 EVP_MD_CTX *ctx; | 145 EVP_MD_CTX *ctx; |
146 | 146 |
147 if ((in == NULL) || (inl <= 0)) return(0); | 147 if ((in == NULL) || (inl <= 0)) return(0); |
148 ctx=b->ptr; | 148 ctx=b->ptr; |
149 | 149 |
150 if ((ctx != NULL) && (b->next_bio != NULL)) | 150 if ((ctx != NULL) && (b->next_bio != NULL)) |
151 ret=BIO_write(b->next_bio,in,inl); | 151 ret=BIO_write(b->next_bio,in,inl); |
152 if (b->init) | 152 if (b->init) |
153 { | 153 { |
154 if (ret > 0) | 154 if (ret > 0) |
155 { | 155 { |
156 EVP_DigestUpdate(ctx,(const unsigned char *)in, | 156 EVP_DigestUpdate(ctx,(const unsigned char *)in, |
157 (unsigned int)ret); | 157 (unsigned int)ret); |
158 } | 158 } |
159 } | 159 } |
160 » BIO_clear_retry_flags(b); | 160 » if(b->next_bio != NULL) |
161 » BIO_copy_next_retry(b); | 161 » » { |
| 162 » » BIO_clear_retry_flags(b); |
| 163 » » BIO_copy_next_retry(b); |
| 164 » » } |
162 return(ret); | 165 return(ret); |
163 } | 166 } |
164 | 167 |
165 static long md_ctrl(BIO *b, int cmd, long num, void *ptr) | 168 static long md_ctrl(BIO *b, int cmd, long num, void *ptr) |
166 { | 169 { |
167 EVP_MD_CTX *ctx,*dctx,**pctx; | 170 EVP_MD_CTX *ctx,*dctx,**pctx; |
168 const EVP_MD **ppmd; | 171 const EVP_MD **ppmd; |
169 EVP_MD *md; | 172 EVP_MD *md; |
170 long ret=1; | 173 long ret=1; |
171 BIO *dbio; | 174 BIO *dbio; |
(...skipping 15 matching lines...) Expand all Loading... |
187 { | 190 { |
188 ppmd=ptr; | 191 ppmd=ptr; |
189 *ppmd=ctx->digest; | 192 *ppmd=ctx->digest; |
190 } | 193 } |
191 else | 194 else |
192 ret=0; | 195 ret=0; |
193 break; | 196 break; |
194 case BIO_C_GET_MD_CTX: | 197 case BIO_C_GET_MD_CTX: |
195 pctx=ptr; | 198 pctx=ptr; |
196 *pctx=ctx; | 199 *pctx=ctx; |
| 200 b->init = 1; |
197 break; | 201 break; |
198 case BIO_C_SET_MD_CTX: | 202 case BIO_C_SET_MD_CTX: |
199 if (b->init) | 203 if (b->init) |
200 b->ptr=ptr; | 204 b->ptr=ptr; |
201 else | 205 else |
202 ret=0; | 206 ret=0; |
203 break; | 207 break; |
204 case BIO_C_DO_STATE_MACHINE: | 208 case BIO_C_DO_STATE_MACHINE: |
205 BIO_clear_retry_flags(b); | 209 BIO_clear_retry_flags(b); |
206 ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | 210 ret=BIO_ctrl(b->next_bio,cmd,num,ptr); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 | 246 |
243 static int md_gets(BIO *bp, char *buf, int size) | 247 static int md_gets(BIO *bp, char *buf, int size) |
244 { | 248 { |
245 EVP_MD_CTX *ctx; | 249 EVP_MD_CTX *ctx; |
246 unsigned int ret; | 250 unsigned int ret; |
247 | 251 |
248 | 252 |
249 ctx=bp->ptr; | 253 ctx=bp->ptr; |
250 if (size < ctx->digest->md_size) | 254 if (size < ctx->digest->md_size) |
251 return(0); | 255 return(0); |
252 » EVP_DigestFinal_ex(ctx,(unsigned char *)buf,&ret); | 256 » if (EVP_DigestFinal_ex(ctx,(unsigned char *)buf,&ret)<=0) |
| 257 » » return -1; |
| 258 » » |
253 return((int)ret); | 259 return((int)ret); |
254 } | 260 } |
255 | 261 |
256 /* | 262 /* |
257 static int md_puts(bp,str) | 263 static int md_puts(bp,str) |
258 BIO *bp; | 264 BIO *bp; |
259 char *str; | 265 char *str; |
260 { | 266 { |
261 return(-1); | 267 return(-1); |
262 } | 268 } |
263 */ | 269 */ |
264 | 270 |
OLD | NEW |