imap-send: use HMAC() function provided by OpenSSL

Fix compile errors with OpenSSL 1.1.0. HMAC_CTX is made opaque and HMAC_CTX_cleanup is removed in OpenSSL 1.1.0. But since we just want to calculate one HMAC, we can use HMAC() here, which exists since OpenSSL 0.9.6 at least. Signed-off-by: Kazuki Yamaguchi <k@rhe.jp> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Kazuki Yamaguchi committed Apr 9, 2016 at 01:22 UTC 1ed2c7b11570f5d16bdc70d151fa78c3dccf6d38
2 files changed +13 -10
compat/apple-common-crypto.h
+11 -5
@@ -3,12 +3,18 @@
3 #define HEADER_HMAC_H
4 #define HEADER_SHA_H
5 #include <CommonCrypto/CommonHMAC.h>
6 -#define HMAC_CTX CCHmacContext
7 -#define HMAC_Init(hmac, key, len, algo) CCHmacInit(hmac, algo, key, len)
8 -#define HMAC_Update CCHmacUpdate
9 -#define HMAC_Final(hmac, hash, ptr) CCHmacFinal(hmac, hash)
10 -#define HMAC_CTX_cleanup(ignore)
6 #define EVP_md5(...) kCCHmacAlgMD5
7 +/* CCHmac doesn't take md_len and the return type is void */
8 +#define HMAC git_CC_HMAC
9 +static inline unsigned char *git_CC_HMAC(CCHmacAlgorithm alg,
10 + const void *key, int key_len,
11 + const unsigned char *data, size_t data_len,
12 + unsigned char *md, unsigned int *md_len)
13 +{
14 + CCHmac(alg, key, key_len, data, data_len, md);
15 + return md;
16 +}
17 +
18 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
19 #define APPLE_LION_OR_NEWER
20 #include <Security/Security.h>
imap-send.c
+2 -5
@@ -862,7 +862,6 @@ static char hexchar(unsigned int b)
862 static char *cram(const char *challenge_64, const char *user, const char *pass)
863 {
864 int i, resp_len, encoded_len, decoded_len;
865 - HMAC_CTX hmac;
865 unsigned char hash[16];
866 char hex[33];
867 char *response, *response_64, *challenge;
@@ -877,10 +876,8 @@ static char *cram(const char *challenge_64, const char *user, const char *pass)
876 (unsigned char *)challenge_64, encoded_len);
877 if (decoded_len < 0)
878 die("invalid challenge %s", challenge_64);
880 - HMAC_Init(&hmac, (unsigned char *)pass, strlen(pass), EVP_md5());
881 - HMAC_Update(&hmac, (unsigned char *)challenge, decoded_len);
882 - HMAC_Final(&hmac, hash, NULL);
883 - HMAC_CTX_cleanup(&hmac);
879 + if (!HMAC(EVP_md5(), pass, strlen(pass), (unsigned char *)challenge, decoded_len, hash, NULL))
880 + die("HMAC error");
881
882 hex[32] = 0;
883 for (i = 0; i < 16; i++) {