Return SOTER_INVALID_PARAMETER when the caller tries to reuse a hash context after finalising
Although it did not crash for OpenSSL backend before, this is to bring it in
line with BoringSSL and to make error codes consistent.
@@ -64,6 +64,11 @@ soter_status_t soter_hash_update(soter_hash_ctx_t *hash_ctx, const void *data, s
return SOTER_INVALID_PARAMETER;
}
+ if (!EVP_MD_CTX_md(hash_ctx->evp_md_ctx))
+ {
+ return SOTER_INVALID_PARAMETER;
+ }
+
if (EVP_DigestUpdate(hash_ctx->evp_md_ctx, data, length))
{
return SOTER_SUCCESS;
@@ -83,6 +88,11 @@ soter_status_t soter_hash_final(soter_hash_ctx_t *hash_ctx, uint8_t* hash_value,
return SOTER_INVALID_PARAMETER;
}
+ if (!EVP_MD_CTX_md(hash_ctx->evp_md_ctx))
+ {
+ return SOTER_INVALID_PARAMETER;
+ }
+
md_length = (size_t)EVP_MD_CTX_size(hash_ctx->evp_md_ctx);
if (!hash_value || (md_length > *hash_length))
