aboutsummaryrefslogtreecommitdiffstats
path: root/ext/openssl/ossl_hmac.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/openssl/ossl_hmac.c')
-rw-r--r--ext/openssl/ossl_hmac.c12
1 files changed, 2 insertions, 10 deletions
diff --git a/ext/openssl/ossl_hmac.c b/ext/openssl/ossl_hmac.c
index 5513cb20de..59d60af791 100644
--- a/ext/openssl/ossl_hmac.c
+++ b/ext/openssl/ossl_hmac.c
@@ -215,20 +215,12 @@ ossl_hmac_hexdigest(VALUE self)
{
HMAC_CTX *ctx;
unsigned char *buf;
- char *hexbuf;
unsigned int buf_len;
- VALUE hexdigest;
GetHMAC(self, ctx);
hmac_final(ctx, &buf, &buf_len);
- if (string2hex(buf, buf_len, &hexbuf, NULL) != 2 * (int)buf_len) {
- OPENSSL_free(buf);
- ossl_raise(eHMACError, "Memory alloc error");
- }
- OPENSSL_free(buf);
- hexdigest = ossl_buf2str(hexbuf, 2 * buf_len);
- return hexdigest;
+ return ossl_buf2hexstr(buf, buf_len);
}
/*
@@ -313,13 +305,13 @@ static VALUE
ossl_hmac_s_hexdigest(VALUE klass, VALUE digest, VALUE key, VALUE data)
{
unsigned char *buf;
- char *hexbuf;
unsigned int buf_len;
VALUE hexdigest;
StringValue(key);
StringValue(data);
+ /* buf is static buffer */
buf = HMAC(GetDigestPtr(digest), RSTRING_PTR(key), RSTRING_LENINT(key),
(unsigned char *)RSTRING_PTR(data), RSTRING_LEN(data), NULL, &buf_len);
if (string2hex(buf, buf_len, &hexbuf, NULL) != 2 * (int)buf_len) {