summaryrefslogtreecommitdiffstats
path: root/src/util/crypto/libcrypto/crypto_hmac_sha1.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/crypto/libcrypto/crypto_hmac_sha1.c')
-rw-r--r--src/util/crypto/libcrypto/crypto_hmac_sha1.c33
1 files changed, 19 insertions, 14 deletions
diff --git a/src/util/crypto/libcrypto/crypto_hmac_sha1.c b/src/util/crypto/libcrypto/crypto_hmac_sha1.c
index 37d25794e..5a4ce356e 100644
--- a/src/util/crypto/libcrypto/crypto_hmac_sha1.c
+++ b/src/util/crypto/libcrypto/crypto_hmac_sha1.c
@@ -24,6 +24,8 @@
#include <openssl/evp.h>
+#include "sss_openssl.h"
+
#define HMAC_SHA1_BLOCKSIZE 64
int sss_hmac_sha1(const unsigned char *key,
@@ -33,23 +35,26 @@ int sss_hmac_sha1(const unsigned char *key,
unsigned char *out)
{
int ret;
- EVP_MD_CTX ctx;
+ EVP_MD_CTX *ctx;
unsigned char ikey[HMAC_SHA1_BLOCKSIZE], okey[HMAC_SHA1_BLOCKSIZE];
size_t i;
unsigned char hash[SSS_SHA1_LENGTH];
unsigned int res_len;
- EVP_MD_CTX_init(&ctx);
+ ctx = EVP_MD_CTX_new();
+ if (ctx == NULL) {
+ return ENOMEM;
+ }
if (key_len > HMAC_SHA1_BLOCKSIZE) {
/* keys longer than blocksize are shortened */
- if (!EVP_DigestInit_ex(&ctx, EVP_sha1(), NULL)) {
+ if (!EVP_DigestInit_ex(ctx, EVP_sha1(), NULL)) {
ret = EIO;
goto done;
}
- EVP_DigestUpdate(&ctx, (const unsigned char *)key, key_len);
- EVP_DigestFinal_ex(&ctx, ikey, &res_len);
+ EVP_DigestUpdate(ctx, (const unsigned char *)key, key_len);
+ EVP_DigestFinal_ex(ctx, ikey, &res_len);
memset(ikey + SSS_SHA1_LENGTH, 0, HMAC_SHA1_BLOCKSIZE - SSS_SHA1_LENGTH);
} else {
/* keys shorter than blocksize are zero-padded */
@@ -63,25 +68,25 @@ int sss_hmac_sha1(const unsigned char *key,
ikey[i] ^= 0x36;
}
- if (!EVP_DigestInit_ex(&ctx, EVP_sha1(), NULL)) {
+ if (!EVP_DigestInit_ex(ctx, EVP_sha1(), NULL)) {
ret = EIO;
goto done;
}
- EVP_DigestUpdate(&ctx, (const unsigned char *)ikey, HMAC_SHA1_BLOCKSIZE);
- EVP_DigestUpdate(&ctx, (const unsigned char *)in, in_len);
- EVP_DigestFinal_ex(&ctx, hash, &res_len);
+ EVP_DigestUpdate(ctx, (const unsigned char *)ikey, HMAC_SHA1_BLOCKSIZE);
+ EVP_DigestUpdate(ctx, (const unsigned char *)in, in_len);
+ EVP_DigestFinal_ex(ctx, hash, &res_len);
- if (!EVP_DigestInit_ex(&ctx, EVP_sha1(), NULL)) {
+ if (!EVP_DigestInit_ex(ctx, EVP_sha1(), NULL)) {
ret = EIO;
goto done;
}
- EVP_DigestUpdate(&ctx, (const unsigned char *)okey, HMAC_SHA1_BLOCKSIZE);
- EVP_DigestUpdate(&ctx, (const unsigned char *)hash, SSS_SHA1_LENGTH);
- EVP_DigestFinal_ex(&ctx, out, &res_len);
+ EVP_DigestUpdate(ctx, (const unsigned char *)okey, HMAC_SHA1_BLOCKSIZE);
+ EVP_DigestUpdate(ctx, (const unsigned char *)hash, SSS_SHA1_LENGTH);
+ EVP_DigestFinal_ex(ctx, out, &res_len);
ret = EOK;
done:
- EVP_MD_CTX_cleanup(&ctx);
+ EVP_MD_CTX_free(ctx);
return ret;
}