ruby-changes:34744
From: nobu <ko1@a...>
Date: Tue, 15 Jul 2014 23:59:47 +0900 (JST)
Subject: [ruby-changes:34744] nobu:r46828 (trunk): md5ossl.c: indicate the result
nobu 2014-07-15 23:59:32 +0900 (Tue, 15 Jul 2014) New Revision: 46828 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=46828 Log: md5ossl.c: indicate the result * ext/digest/md5/md5ossl.c: use OpenSSL EVP API instead of MD5 API to perform MD5 hashes using OpenSSL in ext/digest. [ruby-core:61614] [Bug #9659] Modified files: trunk/ChangeLog trunk/ext/digest/md5/md5ossl.c trunk/ext/digest/md5/md5ossl.h Index: ChangeLog =================================================================== --- ChangeLog (revision 46827) +++ ChangeLog (revision 46828) @@ -1,4 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 -Tue Jul 15 23:59:27 2014 Jared Jennings <jared.jennings.ctr@u...> +Tue Jul 15 23:59:39 2014 Jared Jennings <jared.jennings.ctr@u...> + + * ext/digest/md5/md5ossl.c: use OpenSSL EVP API instead of MD5 API + to perform MD5 hashes using OpenSSL in ext/digest. + [ruby-core:61614] [Bug #9659] * ext/digest: make built-in digest function implementations indicate success or failure of init and final functions. Index: ext/digest/md5/md5ossl.c =================================================================== --- ext/digest/md5/md5ossl.c (revision 46827) +++ ext/digest/md5/md5ossl.c (revision 46828) @@ -2,8 +2,15 @@ https://github.com/ruby/ruby/blob/trunk/ext/digest/md5/md5ossl.c#L2 #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); } Index: ext/digest/md5/md5ossl.h =================================================================== --- ext/digest/md5/md5ossl.h (revision 46827) +++ ext/digest/md5/md5ossl.h (revision 46828) @@ -4,10 +4,22 @@ https://github.com/ruby/ruby/blob/trunk/ext/digest/md5/md5ossl.h#L4 #define MD5OSSL_H_INCLUDED #include <stddef.h> -#include <openssl/md5.h> +#include <openssl/evp.h> -#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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/