diff options
| author | markus <> | 2002-09-05 12:51:50 +0000 |
|---|---|---|
| committer | markus <> | 2002-09-05 12:51:50 +0000 |
| commit | 15b5d84f9da2ce4bfae8580e56e34a859f74ad71 (patch) | |
| tree | bf939e82d7fd73cc8a01cf6959002209972091bc /src/lib/libcrypto/evp/bio_md.c | |
| parent | 027351f729b9e837200dae6e1520cda6577ab930 (diff) | |
| download | openbsd-15b5d84f9da2ce4bfae8580e56e34a859f74ad71.tar.gz openbsd-15b5d84f9da2ce4bfae8580e56e34a859f74ad71.tar.bz2 openbsd-15b5d84f9da2ce4bfae8580e56e34a859f74ad71.zip | |
import openssl-0.9.7-beta1
Diffstat (limited to 'src/lib/libcrypto/evp/bio_md.c')
| -rw-r--r-- | src/lib/libcrypto/evp/bio_md.c | 101 |
1 files changed, 46 insertions, 55 deletions
diff --git a/src/lib/libcrypto/evp/bio_md.c b/src/lib/libcrypto/evp/bio_md.c index fa5fdc055b..c632dfb202 100644 --- a/src/lib/libcrypto/evp/bio_md.c +++ b/src/lib/libcrypto/evp/bio_md.c | |||
| @@ -59,29 +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 "buffer.h" | 62 | #include <openssl/buffer.h> |
| 63 | #include "evp.h" | 63 | #include <openssl/evp.h> |
| 64 | 64 | ||
| 65 | /* BIO_put and BIO_get both add to the digest, | 65 | /* BIO_put and BIO_get both add to the digest, |
| 66 | * BIO_gets returns the digest */ | 66 | * BIO_gets returns the digest */ |
| 67 | 67 | ||
| 68 | #ifndef NOPROTO | 68 | static int md_write(BIO *h, char const *buf, int num); |
| 69 | static int md_write(BIO *h,char *buf,int num); | 69 | static int md_read(BIO *h, char *buf, int size); |
| 70 | static int md_read(BIO *h,char *buf,int size); | 70 | /*static int md_puts(BIO *h, const char *str); */ |
| 71 | /*static int md_puts(BIO *h,char *str); */ | 71 | static int md_gets(BIO *h, char *str, int size); |
| 72 | static int md_gets(BIO *h,char *str,int size); | 72 | static long md_ctrl(BIO *h, int cmd, long arg1, void *arg2); |
| 73 | static long md_ctrl(BIO *h,int cmd,long arg1,char *arg2); | ||
| 74 | static int md_new(BIO *h); | 73 | static int md_new(BIO *h); |
| 75 | static int md_free(BIO *data); | 74 | static int md_free(BIO *data); |
| 76 | #else | 75 | static long md_callback_ctrl(BIO *h,int cmd,bio_info_cb *fp); |
| 77 | static int md_write(); | ||
| 78 | static int md_read(); | ||
| 79 | /*static int md_puts(); */ | ||
| 80 | static int md_gets(); | ||
| 81 | static long md_ctrl(); | ||
| 82 | static int md_new(); | ||
| 83 | static int md_free(); | ||
| 84 | #endif | ||
| 85 | 76 | ||
| 86 | static BIO_METHOD methods_md= | 77 | static BIO_METHOD methods_md= |
| 87 | { | 78 | { |
| @@ -93,19 +84,19 @@ static BIO_METHOD methods_md= | |||
| 93 | md_ctrl, | 84 | md_ctrl, |
| 94 | md_new, | 85 | md_new, |
| 95 | md_free, | 86 | md_free, |
| 87 | md_callback_ctrl, | ||
| 96 | }; | 88 | }; |
| 97 | 89 | ||
| 98 | BIO_METHOD *BIO_f_md() | 90 | BIO_METHOD *BIO_f_md(void) |
| 99 | { | 91 | { |
| 100 | return(&methods_md); | 92 | return(&methods_md); |
| 101 | } | 93 | } |
| 102 | 94 | ||
| 103 | static int md_new(bi) | 95 | static int md_new(BIO *bi) |
| 104 | BIO *bi; | ||
| 105 | { | 96 | { |
| 106 | EVP_MD_CTX *ctx; | 97 | EVP_MD_CTX *ctx; |
| 107 | 98 | ||
| 108 | ctx=(EVP_MD_CTX *)Malloc(sizeof(EVP_MD_CTX)); | 99 | ctx=EVP_MD_CTX_create(); |
| 109 | if (ctx == NULL) return(0); | 100 | if (ctx == NULL) return(0); |
| 110 | 101 | ||
| 111 | bi->init=0; | 102 | bi->init=0; |
| @@ -114,27 +105,23 @@ BIO *bi; | |||
| 114 | return(1); | 105 | return(1); |
| 115 | } | 106 | } |
| 116 | 107 | ||
| 117 | static int md_free(a) | 108 | static int md_free(BIO *a) |
| 118 | BIO *a; | ||
| 119 | { | 109 | { |
| 120 | if (a == NULL) return(0); | 110 | if (a == NULL) return(0); |
| 121 | Free(a->ptr); | 111 | EVP_MD_CTX_destroy(a->ptr); |
| 122 | a->ptr=NULL; | 112 | a->ptr=NULL; |
| 123 | a->init=0; | 113 | a->init=0; |
| 124 | a->flags=0; | 114 | a->flags=0; |
| 125 | return(1); | 115 | return(1); |
| 126 | } | 116 | } |
| 127 | 117 | ||
| 128 | static int md_read(b,out,outl) | 118 | static int md_read(BIO *b, char *out, int outl) |
| 129 | BIO *b; | ||
| 130 | char *out; | ||
| 131 | int outl; | ||
| 132 | { | 119 | { |
| 133 | int ret=0; | 120 | int ret=0; |
| 134 | EVP_MD_CTX *ctx; | 121 | EVP_MD_CTX *ctx; |
| 135 | 122 | ||
| 136 | if (out == NULL) return(0); | 123 | if (out == NULL) return(0); |
| 137 | ctx=(EVP_MD_CTX *)b->ptr; | 124 | ctx=b->ptr; |
| 138 | 125 | ||
| 139 | if ((ctx == NULL) || (b->next_bio == NULL)) return(0); | 126 | if ((ctx == NULL) || (b->next_bio == NULL)) return(0); |
| 140 | 127 | ||
| @@ -152,16 +139,13 @@ int outl; | |||
| 152 | return(ret); | 139 | return(ret); |
| 153 | } | 140 | } |
| 154 | 141 | ||
| 155 | static int md_write(b,in,inl) | 142 | static int md_write(BIO *b, const char *in, int inl) |
| 156 | BIO *b; | ||
| 157 | char *in; | ||
| 158 | int inl; | ||
| 159 | { | 143 | { |
| 160 | int ret=0; | 144 | int ret=0; |
| 161 | EVP_MD_CTX *ctx; | 145 | EVP_MD_CTX *ctx; |
| 162 | 146 | ||
| 163 | if ((in == NULL) || (inl <= 0)) return(0); | 147 | if ((in == NULL) || (inl <= 0)) return(0); |
| 164 | ctx=(EVP_MD_CTX *)b->ptr; | 148 | ctx=b->ptr; |
| 165 | 149 | ||
| 166 | if ((ctx != NULL) && (b->next_bio != NULL)) | 150 | if ((ctx != NULL) && (b->next_bio != NULL)) |
| 167 | ret=BIO_write(b->next_bio,in,inl); | 151 | ret=BIO_write(b->next_bio,in,inl); |
| @@ -178,25 +162,21 @@ int inl; | |||
| 178 | return(ret); | 162 | return(ret); |
| 179 | } | 163 | } |
| 180 | 164 | ||
| 181 | static long md_ctrl(b,cmd,num,ptr) | 165 | static long md_ctrl(BIO *b, int cmd, long num, void *ptr) |
| 182 | BIO *b; | ||
| 183 | int cmd; | ||
| 184 | long num; | ||
| 185 | char *ptr; | ||
| 186 | { | 166 | { |
| 187 | EVP_MD_CTX *ctx,*dctx,**pctx; | 167 | EVP_MD_CTX *ctx,*dctx,**pctx; |
| 188 | EVP_MD **ppmd; | 168 | const EVP_MD **ppmd; |
| 189 | EVP_MD *md; | 169 | EVP_MD *md; |
| 190 | long ret=1; | 170 | long ret=1; |
| 191 | BIO *dbio; | 171 | BIO *dbio; |
| 192 | 172 | ||
| 193 | ctx=(EVP_MD_CTX *)b->ptr; | 173 | ctx=b->ptr; |
| 194 | 174 | ||
| 195 | switch (cmd) | 175 | switch (cmd) |
| 196 | { | 176 | { |
| 197 | case BIO_CTRL_RESET: | 177 | case BIO_CTRL_RESET: |
| 198 | if (b->init) | 178 | if (b->init) |
| 199 | EVP_DigestInit(ctx,ctx->digest); | 179 | EVP_DigestInit_ex(ctx,ctx->digest, NULL); |
| 200 | else | 180 | else |
| 201 | ret=0; | 181 | ret=0; |
| 202 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | 182 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); |
| @@ -204,7 +184,7 @@ char *ptr; | |||
| 204 | case BIO_C_GET_MD: | 184 | case BIO_C_GET_MD: |
| 205 | if (b->init) | 185 | if (b->init) |
| 206 | { | 186 | { |
| 207 | ppmd=(EVP_MD **)ptr; | 187 | ppmd=ptr; |
| 208 | *ppmd=ctx->digest; | 188 | *ppmd=ctx->digest; |
| 209 | } | 189 | } |
| 210 | else | 190 | else |
| @@ -213,7 +193,7 @@ char *ptr; | |||
| 213 | case BIO_C_GET_MD_CTX: | 193 | case BIO_C_GET_MD_CTX: |
| 214 | if (b->init) | 194 | if (b->init) |
| 215 | { | 195 | { |
| 216 | pctx=(EVP_MD_CTX **)ptr; | 196 | pctx=ptr; |
| 217 | *pctx=ctx; | 197 | *pctx=ctx; |
| 218 | } | 198 | } |
| 219 | else | 199 | else |
| @@ -226,14 +206,14 @@ char *ptr; | |||
| 226 | break; | 206 | break; |
| 227 | 207 | ||
| 228 | case BIO_C_SET_MD: | 208 | case BIO_C_SET_MD: |
| 229 | md=(EVP_MD *)ptr; | 209 | md=ptr; |
| 230 | EVP_DigestInit(ctx,md); | 210 | EVP_DigestInit_ex(ctx,md, NULL); |
| 231 | b->init=1; | 211 | b->init=1; |
| 232 | break; | 212 | break; |
| 233 | case BIO_CTRL_DUP: | 213 | case BIO_CTRL_DUP: |
| 234 | dbio=(BIO *)ptr; | 214 | dbio=ptr; |
| 235 | dctx=(EVP_MD_CTX *)dbio->ptr; | 215 | dctx=dbio->ptr; |
| 236 | memcpy(dctx,ctx,sizeof(ctx)); | 216 | EVP_MD_CTX_copy_ex(dctx,ctx); |
| 237 | b->init=1; | 217 | b->init=1; |
| 238 | break; | 218 | break; |
| 239 | default: | 219 | default: |
| @@ -243,19 +223,30 @@ char *ptr; | |||
| 243 | return(ret); | 223 | return(ret); |
| 244 | } | 224 | } |
| 245 | 225 | ||
| 246 | static int md_gets(bp,buf,size) | 226 | static long md_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) |
| 247 | BIO *bp; | 227 | { |
| 248 | char *buf; | 228 | long ret=1; |
| 249 | int size; | 229 | |
| 230 | if (b->next_bio == NULL) return(0); | ||
| 231 | switch (cmd) | ||
| 232 | { | ||
| 233 | default: | ||
| 234 | ret=BIO_callback_ctrl(b->next_bio,cmd,fp); | ||
| 235 | break; | ||
| 236 | } | ||
| 237 | return(ret); | ||
| 238 | } | ||
| 239 | |||
| 240 | static int md_gets(BIO *bp, char *buf, int size) | ||
| 250 | { | 241 | { |
| 251 | EVP_MD_CTX *ctx; | 242 | EVP_MD_CTX *ctx; |
| 252 | unsigned int ret; | 243 | unsigned int ret; |
| 253 | 244 | ||
| 254 | 245 | ||
| 255 | ctx=(EVP_MD_CTX *)bp->ptr; | 246 | ctx=bp->ptr; |
| 256 | if (size < ctx->digest->md_size) | 247 | if (size < ctx->digest->md_size) |
| 257 | return(0); | 248 | return(0); |
| 258 | EVP_DigestFinal(ctx,(unsigned char *)buf,&ret); | 249 | EVP_DigestFinal_ex(ctx,(unsigned char *)buf,&ret); |
| 259 | return((int)ret); | 250 | return((int)ret); |
| 260 | } | 251 | } |
| 261 | 252 | ||
