]> granicus.if.org Git - postgresql/commitdiff
Some builds (depends on crypto engine support?) of OpenSSL
authorNeil Conway <neilc@samurai.com>
Sun, 13 Mar 2005 23:45:56 +0000 (23:45 +0000)
committerNeil Conway <neilc@samurai.com>
Sun, 13 Mar 2005 23:45:56 +0000 (23:45 +0000)
0.9.7x have EVP_DigestFinal function which which clears all of
EVP_MD_CTX.  This makes pgcrypto crash in functions which
re-use one digest context several times: hmac() and crypt()
with md5 algorithm.

Following patch fixes it by carring the digest info around
EVP_DigestFinal and re-initializing cipher.

Marko Kreen.

contrib/pgcrypto/openssl.c

index 665ff47fe2e35f884f99b085e16baad9ebb8ba6d..5cbf9c9fcdbb3f4f4bf147d31154355433282f0a 100644 (file)
@@ -26,7 +26,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $Id: openssl.c,v 1.10.4.1 2005/03/13 23:41:44 neilc Exp $
+ * $Id: openssl.c,v 1.10.4.2 2005/03/13 23:45:56 neilc Exp $
  */
 
 #include <postgres.h>
@@ -73,8 +73,15 @@ static void
 digest_finish(PX_MD * h, uint8 *dst)
 {
        EVP_MD_CTX *ctx = (EVP_MD_CTX *) h->p.ptr;
+       const EVP_MD *md = EVP_MD_CTX_md(ctx);
 
        EVP_DigestFinal(ctx, dst, NULL);
+
+       /*
+        * Some builds of 0.9.7x clear all of ctx in EVP_DigestFinal.
+        * Fix it by reinitializing ctx.
+        */
+       EVP_DigestInit(ctx, md);
 }
 
 static void