diff --git a/ext/openssl/openssl.c b/ext/openssl/openssl.c index c8ca39ad0aab..5ea2a7737434 100644 --- a/ext/openssl/openssl.c +++ b/ext/openssl/openssl.c @@ -32,7 +32,6 @@ #include "ext/standard/file.h" #include "ext/standard/info.h" #include "ext/standard/php_fopen_wrappers.h" -#include "ext/standard/md5.h" /* For make_digest_ex() */ #include "ext/standard/base64.h" #ifdef PHP_WIN32 # include "win32/winutil.h" @@ -4973,7 +4972,7 @@ PHP_FUNCTION(openssl_digest) int digest_str_len = siglen * 2; zend_string *digest_str = zend_string_alloc(digest_str_len, 0); - make_digest_ex(ZSTR_VAL(digest_str), (unsigned char*)ZSTR_VAL(sigbuf), siglen); + zend_bin2hex(ZSTR_VAL(digest_str), (unsigned char*)ZSTR_VAL(sigbuf), siglen); ZSTR_VAL(digest_str)[digest_str_len] = '\0'; zend_string_release_ex(sigbuf, 0); RETVAL_NEW_STR(digest_str); diff --git a/ext/openssl/openssl_backend_common.c b/ext/openssl/openssl_backend_common.c index 8adf1ac813f1..d7a520c17f7e 100644 --- a/ext/openssl/openssl_backend_common.c +++ b/ext/openssl/openssl_backend_common.c @@ -15,7 +15,6 @@ #include "php_openssl_backend.h" #include "zend_exceptions.h" -#include "ext/standard/md5.h" /* For make_digest_ex() */ #include "ext/standard/base64.h" #ifdef PHP_WIN32 # include "win32/winutil.h" @@ -611,7 +610,7 @@ zend_string* php_openssl_x509_fingerprint(X509 *peer, const char *method, bool r ret = zend_string_init((char*)md, n, 0); } else { ret = zend_string_alloc(n * 2, 0); - make_digest_ex(ZSTR_VAL(ret), md, n); + zend_bin2hex(ZSTR_VAL(ret), md, n); ZSTR_VAL(ret)[n * 2] = '\0'; } diff --git a/ext/standard/md5.c b/ext/standard/md5.c index 204514053cf0..c5badcd6b859 100644 --- a/ext/standard/md5.c +++ b/ext/standard/md5.c @@ -24,12 +24,10 @@ PHPAPI void make_digest(char *md5str, const unsigned char *digest) PHPAPI void make_digest_ex(char *md5str, const unsigned char *digest, size_t len) { - static const char hexits[17] = "0123456789abcdef"; - - for (size_t i = 0; i < len; i++) { - md5str[i * 2] = hexits[digest[i] >> 4]; - md5str[(i * 2) + 1] = hexits[digest[i] & 0x0F]; - } + zend_bin2hex(md5str, digest, len); + /* Some callers (e.g. ext/soap's WSDL cache key) memcpy() the whole + buffer including this terminator, so it must still be written here; + zend_bin2hex() itself does not null-terminate. */ md5str[len * 2] = '\0'; }