Speed up digesting by avoiding unnecessary operations.

Conscrypt's MessageDigest implementations at the end of computing a
digest create and initialize a new EVP_MD_CTX and then also intialize
the digest struct there. This is done because the MessageDigest
instance could be reused for a new digesting session.

This change implements three optimizations:
1. MessageDigestSpi now reuses its EVP_MD_CTX instead of creating a
   new one for each new digesting session.
2. MessageDigestSpi now defers the initialization of the digest struct
   in EVP_MD_CTX till the first invocation of
   engineUpdate/engineDigest.
3. MessagDigestSpi (and SignatureSpi) no longer invoke EVP_MD_CTX_init
   after EVP_MD_CTX_create because EVP_MD_CTX_create initializes the
   EVP_MD_CTX it creates.

libcore's MessageDigestBenchmark on Nexus 5 shows:
* 10-15% faster performance for a single digest of 8192 bytes.
* 15-20% faster performance for reusing a MessageDigest instance to
  compute a digest of 8192 bytes ten times.

Change-Id: I8a0697310ef7efcd4db6870e54eb46102fd4a941
4 files changed