diff options
Diffstat (limited to 'src/lib/libcrypto/evp/digest.c')
| -rw-r--r-- | src/lib/libcrypto/evp/digest.c | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/src/lib/libcrypto/evp/digest.c b/src/lib/libcrypto/evp/digest.c index 982ba2b136..467e6b5ae9 100644 --- a/src/lib/libcrypto/evp/digest.c +++ b/src/lib/libcrypto/evp/digest.c | |||
| @@ -117,6 +117,10 @@ | |||
| 117 | #include <openssl/engine.h> | 117 | #include <openssl/engine.h> |
| 118 | #endif | 118 | #endif |
| 119 | 119 | ||
| 120 | #ifdef OPENSSL_FIPS | ||
| 121 | #include <openssl/fips.h> | ||
| 122 | #endif | ||
| 123 | |||
| 120 | void EVP_MD_CTX_init(EVP_MD_CTX *ctx) | 124 | void EVP_MD_CTX_init(EVP_MD_CTX *ctx) |
| 121 | { | 125 | { |
| 122 | memset(ctx,'\0',sizeof *ctx); | 126 | memset(ctx,'\0',sizeof *ctx); |
| @@ -225,12 +229,26 @@ skip_to_init: | |||
| 225 | } | 229 | } |
| 226 | if (ctx->flags & EVP_MD_CTX_FLAG_NO_INIT) | 230 | if (ctx->flags & EVP_MD_CTX_FLAG_NO_INIT) |
| 227 | return 1; | 231 | return 1; |
| 232 | #ifdef OPENSSL_FIPS | ||
| 233 | if (FIPS_mode()) | ||
| 234 | { | ||
| 235 | if (FIPS_digestinit(ctx, type)) | ||
| 236 | return 1; | ||
| 237 | OPENSSL_free(ctx->md_data); | ||
| 238 | ctx->md_data = NULL; | ||
| 239 | return 0; | ||
| 240 | } | ||
| 241 | #endif | ||
| 228 | return ctx->digest->init(ctx); | 242 | return ctx->digest->init(ctx); |
| 229 | } | 243 | } |
| 230 | 244 | ||
| 231 | int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *data, size_t count) | 245 | int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *data, size_t count) |
| 232 | { | 246 | { |
| 247 | #ifdef OPENSSL_FIPS | ||
| 248 | return FIPS_digestupdate(ctx, data, count); | ||
| 249 | #else | ||
| 233 | return ctx->update(ctx,data,count); | 250 | return ctx->update(ctx,data,count); |
| 251 | #endif | ||
| 234 | } | 252 | } |
| 235 | 253 | ||
| 236 | /* The caller can assume that this removes any secret data from the context */ | 254 | /* The caller can assume that this removes any secret data from the context */ |
| @@ -245,8 +263,10 @@ int EVP_DigestFinal(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *size) | |||
| 245 | /* The caller can assume that this removes any secret data from the context */ | 263 | /* The caller can assume that this removes any secret data from the context */ |
| 246 | int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *size) | 264 | int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *size) |
| 247 | { | 265 | { |
| 266 | #ifdef OPENSSL_FIPS | ||
| 267 | return FIPS_digestfinal(ctx, md, size); | ||
| 268 | #else | ||
| 248 | int ret; | 269 | int ret; |
| 249 | |||
| 250 | OPENSSL_assert(ctx->digest->md_size <= EVP_MAX_MD_SIZE); | 270 | OPENSSL_assert(ctx->digest->md_size <= EVP_MAX_MD_SIZE); |
| 251 | ret=ctx->digest->final(ctx,md); | 271 | ret=ctx->digest->final(ctx,md); |
| 252 | if (size != NULL) | 272 | if (size != NULL) |
| @@ -258,6 +278,7 @@ int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *size) | |||
| 258 | } | 278 | } |
| 259 | memset(ctx->md_data,0,ctx->digest->ctx_size); | 279 | memset(ctx->md_data,0,ctx->digest->ctx_size); |
| 260 | return ret; | 280 | return ret; |
| 281 | #endif | ||
| 261 | } | 282 | } |
| 262 | 283 | ||
| 263 | int EVP_MD_CTX_copy(EVP_MD_CTX *out, const EVP_MD_CTX *in) | 284 | int EVP_MD_CTX_copy(EVP_MD_CTX *out, const EVP_MD_CTX *in) |
| @@ -351,6 +372,7 @@ void EVP_MD_CTX_destroy(EVP_MD_CTX *ctx) | |||
| 351 | /* This call frees resources associated with the context */ | 372 | /* This call frees resources associated with the context */ |
| 352 | int EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx) | 373 | int EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx) |
| 353 | { | 374 | { |
| 375 | #ifndef OPENSSL_FIPS | ||
| 354 | /* Don't assume ctx->md_data was cleaned in EVP_Digest_Final, | 376 | /* Don't assume ctx->md_data was cleaned in EVP_Digest_Final, |
| 355 | * because sometimes only copies of the context are ever finalised. | 377 | * because sometimes only copies of the context are ever finalised. |
| 356 | */ | 378 | */ |
| @@ -363,6 +385,7 @@ int EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx) | |||
| 363 | OPENSSL_cleanse(ctx->md_data,ctx->digest->ctx_size); | 385 | OPENSSL_cleanse(ctx->md_data,ctx->digest->ctx_size); |
| 364 | OPENSSL_free(ctx->md_data); | 386 | OPENSSL_free(ctx->md_data); |
| 365 | } | 387 | } |
| 388 | #endif | ||
| 366 | if (ctx->pctx) | 389 | if (ctx->pctx) |
| 367 | EVP_PKEY_CTX_free(ctx->pctx); | 390 | EVP_PKEY_CTX_free(ctx->pctx); |
| 368 | #ifndef OPENSSL_NO_ENGINE | 391 | #ifndef OPENSSL_NO_ENGINE |
| @@ -371,6 +394,9 @@ int EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx) | |||
| 371 | * functional reference we held for this reason. */ | 394 | * functional reference we held for this reason. */ |
| 372 | ENGINE_finish(ctx->engine); | 395 | ENGINE_finish(ctx->engine); |
| 373 | #endif | 396 | #endif |
| 397 | #ifdef OPENSSL_FIPS | ||
| 398 | FIPS_md_ctx_cleanup(ctx); | ||
| 399 | #endif | ||
| 374 | memset(ctx,'\0',sizeof *ctx); | 400 | memset(ctx,'\0',sizeof *ctx); |
| 375 | 401 | ||
| 376 | return 1; | 402 | return 1; |
