commit 8d16023c31e4b7626d44757bd0f47ad1ad1eb8ab Author: Jared Jennings Date: Thu Mar 27 18:42:23 2014 -0500 use OpenSSL EVP API instead of MD5 API to perform MD5 hashes using OpenSSL in ext/digest diff --git a/ext/digest/md5/md5ossl.c b/ext/digest/md5/md5ossl.c index 97c7902..fdde089 100644 --- a/ext/digest/md5/md5ossl.c +++ b/ext/digest/md5/md5ossl.c @@ -2,8 +2,15 @@ #include "md5ossl.h" -void -MD5_Finish(MD5_CTX *pctx, unsigned char *digest) +int +rb_digest_md5osslevp_Init(EVP_MD_CTX *pctx) { - MD5_Final(digest, pctx); + return EVP_DigestInit_ex(pctx, EVP_md5(), NULL); +} + +int +rb_digest_md5osslevp_Finish(EVP_MD_CTX *pctx, unsigned char *digest) +{ + /* if EVP_DigestFinal_ex fails, we ignore that */ + return EVP_DigestFinal_ex(pctx, digest, NULL); } diff --git a/ext/digest/md5/md5ossl.h b/ext/digest/md5/md5ossl.h index c50e20c..96eee63 100644 --- a/ext/digest/md5/md5ossl.h +++ b/ext/digest/md5/md5ossl.h @@ -4,10 +4,22 @@ #define MD5OSSL_H_INCLUDED #include -#include +#include -#define MD5_BLOCK_LENGTH MD5_CBLOCK +#define MD5_Init rb_digest_md5osslevp_Init +#define MD5_Update EVP_DigestUpdate +#define MD5_Finish rb_digest_md5osslevp_Finish +#define MD5_CTX EVP_MD_CTX -void MD5_Finish(MD5_CTX *pctx, unsigned char *digest); +/* We should use EVP_MD_size(3) and EVP_MD_block_size(3), but the + advantage of these is that they are flexible across digest + algorithms and we are fixing the digest algorithm here; and these + numbers must be constants because the rb_digest_metadata_t + structure is declared const. Simplest way is to write literals. */ +#define MD5_BLOCK_LENGTH 64 +#define MD5_DIGEST_LENGTH 16 + +int MD5_Init(MD5_CTX *pctx); +int MD5_Finish(MD5_CTX *pctx, unsigned char *digest); #endif