Lines Matching refs:ctx

124 void EVP_MD_CTX_init(EVP_MD_CTX *ctx)
126 memset(ctx,'\0',sizeof *ctx);
131 EVP_MD_CTX *ctx=OPENSSL_malloc(sizeof *ctx);
133 if (ctx)
134 EVP_MD_CTX_init(ctx);
136 return ctx;
139 int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type)
141 EVP_MD_CTX_init(ctx);
142 return EVP_DigestInit_ex(ctx, type, NULL);
145 int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
147 EVP_MD_CTX_clear_flags(ctx,EVP_MD_CTX_FLAG_CLEANED);
153 if (ctx->engine && ctx->digest && (!type ||
154 (type && (type->type == ctx->digest->type))))
161 if(ctx->engine)
162 ENGINE_finish(ctx->engine);
190 ctx->engine = impl;
193 ctx->engine = NULL;
196 if(!ctx->digest)
202 if (ctx->digest != type)
204 if (ctx->digest && ctx->digest->ctx_size)
205 OPENSSL_free(ctx->md_data);
206 ctx->digest=type;
207 if (!(ctx->flags & EVP_MD_CTX_FLAG_NO_INIT) && type->ctx_size)
209 ctx->update = type->update;
210 ctx->md_data=OPENSSL_malloc(type->ctx_size);
211 if (ctx->md_data == NULL)
222 if (ctx->pctx)
225 r = EVP_PKEY_CTX_ctrl(ctx->pctx, -1, EVP_PKEY_OP_TYPE_SIG,
226 EVP_PKEY_CTRL_DIGESTINIT, 0, ctx);
230 if (ctx->flags & EVP_MD_CTX_FLAG_NO_INIT)
235 if (FIPS_digestinit(ctx, type))
237 OPENSSL_free(ctx->md_data);
238 ctx->md_data = NULL;
242 return ctx->digest->init(ctx);
245 int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *data, size_t count)
248 return FIPS_digestupdate(ctx, data, count);
250 return ctx->update(ctx,data,count);
255 int EVP_DigestFinal(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *size)
258 ret = EVP_DigestFinal_ex(ctx, md, size);
259 EVP_MD_CTX_cleanup(ctx);
264 int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *size)
267 return FIPS_digestfinal(ctx, md, size);
271 OPENSSL_assert(ctx->digest->md_size <= EVP_MAX_MD_SIZE);
272 ret=ctx->digest->final(ctx,md);
274 *size=ctx->digest->md_size;
275 if (ctx->digest->cleanup)
277 ctx->digest->cleanup(ctx);
278 EVP_MD_CTX_set_flags(ctx,EVP_MD_CTX_FLAG_CLEANED);
280 memset(ctx->md_data,0,ctx->digest->ctx_size);
354 EVP_MD_CTX ctx;
357 EVP_MD_CTX_init(&ctx);
358 EVP_MD_CTX_set_flags(&ctx,EVP_MD_CTX_FLAG_ONESHOT);
359 ret=EVP_DigestInit_ex(&ctx, type, impl)
360 && EVP_DigestUpdate(&ctx, data, count)
361 && EVP_DigestFinal_ex(&ctx, md, size);
362 EVP_MD_CTX_cleanup(&ctx);
367 void EVP_MD_CTX_destroy(EVP_MD_CTX *ctx)
369 if (ctx)
371 EVP_MD_CTX_cleanup(ctx);
372 OPENSSL_free(ctx);
377 int EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx)
380 /* Don't assume ctx->md_data was cleaned in EVP_Digest_Final,
383 if (ctx->digest && ctx->digest->cleanup
384 && !EVP_MD_CTX_test_flags(ctx,EVP_MD_CTX_FLAG_CLEANED))
385 ctx->digest->cleanup(ctx);
386 if (ctx->digest && ctx->digest->ctx_size && ctx->md_data
387 && !EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_REUSE))
389 OPENSSL_cleanse(ctx->md_data,ctx->digest->ctx_size);
390 OPENSSL_free(ctx->md_data);
393 if (ctx->pctx)
394 EVP_PKEY_CTX_free(ctx->pctx);
396 if(ctx->engine)
399 ENGINE_finish(ctx->engine);
402 FIPS_md_ctx_cleanup(ctx);
404 memset(ctx,'\0',sizeof *ctx);