diff options
Diffstat (limited to 'src/crypto/digest')
-rw-r--r-- | src/crypto/digest/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/crypto/digest/digest.c | 32 | ||||
-rw-r--r-- | src/crypto/digest/digests.c | 3 | ||||
-rw-r--r-- | src/crypto/digest/internal.h | 17 |
4 files changed, 13 insertions, 41 deletions
diff --git a/src/crypto/digest/CMakeLists.txt b/src/crypto/digest/CMakeLists.txt index 816d116..856e45a 100644 --- a/src/crypto/digest/CMakeLists.txt +++ b/src/crypto/digest/CMakeLists.txt @@ -1,4 +1,4 @@ -include_directories(. .. ../../include) +include_directories(../../include) add_library( digest diff --git a/src/crypto/digest/digest.c b/src/crypto/digest/digest.c index f09948b..eb71b07 100644 --- a/src/crypto/digest/digest.c +++ b/src/crypto/digest/digest.c @@ -116,8 +116,7 @@ int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in) { uint8_t *tmp_buf = NULL; if (in == NULL || in->digest == NULL) { - OPENSSL_PUT_ERROR(DIGEST, EVP_MD_CTX_copy_ex, - DIGEST_R_INPUT_NOT_INITIALIZED); + OPENSSL_PUT_ERROR(DIGEST, DIGEST_R_INPUT_NOT_INITIALIZED); return 0; } @@ -130,15 +129,15 @@ int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in) { } EVP_MD_CTX_cleanup(out); - memcpy(out, in, sizeof(EVP_MD_CTX)); + out->digest = in->digest; if (in->md_data && in->digest->ctx_size) { if (tmp_buf) { out->md_data = tmp_buf; } else { out->md_data = OPENSSL_malloc(in->digest->ctx_size); if (!out->md_data) { - OPENSSL_PUT_ERROR(DIGEST, EVP_MD_CTX_copy_ex, ERR_R_MALLOC_FAILURE); + OPENSSL_PUT_ERROR(DIGEST, ERR_R_MALLOC_FAILURE); return 0; } } @@ -146,6 +145,7 @@ int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in) { } assert(in->pctx == NULL || in->pctx_ops != NULL); + out->pctx_ops = in->pctx_ops; if (in->pctx && in->pctx_ops) { out->pctx = in->pctx_ops->dup(in->pctx); if (!out->pctx) { @@ -164,30 +164,20 @@ int EVP_MD_CTX_copy(EVP_MD_CTX *out, const EVP_MD_CTX *in) { int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *engine) { if (ctx->digest != type) { - if (ctx->digest && ctx->digest->ctx_size) { + if (ctx->digest && ctx->digest->ctx_size > 0) { OPENSSL_free(ctx->md_data); } ctx->digest = type; - if (!(ctx->flags & EVP_MD_CTX_FLAG_NO_INIT) && type->ctx_size) { - ctx->update = type->update; + if (type->ctx_size > 0) { ctx->md_data = OPENSSL_malloc(type->ctx_size); if (ctx->md_data == NULL) { - OPENSSL_PUT_ERROR(DIGEST, EVP_DigestInit_ex, ERR_R_MALLOC_FAILURE); + OPENSSL_PUT_ERROR(DIGEST, ERR_R_MALLOC_FAILURE); return 0; } } } assert(ctx->pctx == NULL || ctx->pctx_ops != NULL); - if (ctx->pctx_ops) { - if (!ctx->pctx_ops->begin_digest(ctx)) { - return 0; - } - } - - if (ctx->flags & EVP_MD_CTX_FLAG_NO_INIT) { - return 1; - } ctx->digest->init(ctx); return 1; @@ -199,7 +189,7 @@ int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type) { } int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *data, size_t len) { - ctx->update(ctx, data, len); + ctx->digest->update(ctx, data, len); return 1; } @@ -214,7 +204,7 @@ int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, uint8_t *md_out, unsigned int *size) { } int EVP_DigestFinal(EVP_MD_CTX *ctx, uint8_t *md, unsigned int *size) { - EVP_DigestFinal_ex(ctx, md, size); + (void)EVP_DigestFinal_ex(ctx, md, size); EVP_MD_CTX_cleanup(ctx); return 1; } @@ -253,10 +243,6 @@ int EVP_MD_CTX_type(const EVP_MD_CTX *ctx) { return EVP_MD_type(EVP_MD_CTX_md(ctx)); } -void EVP_MD_CTX_set_flags(EVP_MD_CTX *ctx, uint32_t flags) { - ctx->flags |= flags; -} - int EVP_add_digest(const EVP_MD *digest) { return 1; } diff --git a/src/crypto/digest/digests.c b/src/crypto/digest/digests.c index f5eda36..3307f26 100644 --- a/src/crypto/digest/digests.c +++ b/src/crypto/digest/digests.c @@ -67,7 +67,7 @@ #include "internal.h" #if defined(NDEBUG) -#define CHECK(x) x +#define CHECK(x) (void) (x) #else #define CHECK(x) assert(x) #endif @@ -262,6 +262,7 @@ struct nid_to_digest { }; static const struct nid_to_digest nid_to_digest_mapping[] = { + { NID_md4, EVP_md4, SN_md4, LN_md4 }, { NID_md5, EVP_md5, SN_md5, LN_md5 }, { NID_sha1, EVP_sha1, SN_sha1, LN_sha1 }, { NID_sha224, EVP_sha224, SN_sha224, LN_sha224 }, diff --git a/src/crypto/digest/internal.h b/src/crypto/digest/internal.h index 1572fa8..e3d812a 100644 --- a/src/crypto/digest/internal.h +++ b/src/crypto/digest/internal.h @@ -92,7 +92,7 @@ struct env_md_st { }; /* evp_md_pctx_ops contains function pointers to allow the |pctx| member of - * |EVP_MD_CTX| to be manipulated without breaking laying by calling EVP + * |EVP_MD_CTX| to be manipulated without breaking layering by calling EVP * functions. */ struct evp_md_pctx_ops { /* free is called when an |EVP_MD_CTX| is being freed and the |pctx| also @@ -102,23 +102,8 @@ struct evp_md_pctx_ops { /* dup is called when an |EVP_MD_CTX| is copied and so the |pctx| also needs * to be copied. */ EVP_PKEY_CTX* (*dup) (EVP_PKEY_CTX *pctx); - - /* begin_digest is called when a new digest operation is started. It returns - * one on success and zero otherwise. */ - int (*begin_digest) (EVP_MD_CTX *ctx); }; -/* EVP_MD_CTX_set_flags ORs |flags| into the flags member of |ctx|. */ -OPENSSL_EXPORT void EVP_MD_CTX_set_flags(EVP_MD_CTX *ctx, uint32_t flags); - -/* EVP_MD_CTX_FLAG_NO_INIT causes the |EVP_MD|'s |init| function not to be - * called, the |update| member not to be copied from the |EVP_MD| in - * |EVP_DigestInit_ex| and for |md_data| not to be initialised. - * - * TODO(davidben): This is an implementation detail of |EVP_PKEY_HMAC| and can - * be removed when it is gone. */ -#define EVP_MD_CTX_FLAG_NO_INIT 1 - #if defined(__cplusplus) } /* extern C */ |