EVP_DigestInit_ex() may be used to recycle an existing EVP_MD_CTX without having
authormiod <miod@openbsd.org>
Sun, 13 Jul 2014 11:14:02 +0000 (11:14 +0000)
committermiod <miod@openbsd.org>
Sun, 13 Jul 2014 11:14:02 +0000 (11:14 +0000)
commit05901b497de1bdf3d67cb1093d3582b2dc1b0416
tree3c89813d4bec2485dfada394e03d4ff448d4d1a8
parentcf2dce2d5e4c7a394684bf61fd4e27ab7f005b35
EVP_DigestInit_ex() may be used to recycle an existing EVP_MD_CTX without having
to reinitialize all of it, especially if it is used with the same MD algorithm.

However, when the MD algorithm changes, it needs to perform more cleanups.
Make that code more closer to what EVP_MD_CTX_cleanup() does by:
- only freeing md_data if EVP_MD_CTX_FLAG_REUSE is not set
- performing an explicit_bzero of md_data before freeing it
- making sure we call EVP_PKEY_CTX_free on the pctx if the allocation for the
  new md_data fails.

ok tedu@
lib/libcrypto/evp/digest.c
lib/libssl/src/crypto/evp/digest.c