Skip to content

Commit 1ed2c7b

Browse files
rheniumgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e465796 commit 1ed2c7b

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

compat/apple-common-crypto.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,18 @@
33
#define HEADER_HMAC_H
44
#define HEADER_SHA_H
55
#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)
116
#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+
1218
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
1319
#define APPLE_LION_OR_NEWER
1420
#include <Security/Security.h>

imap-send.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,6 @@ static char hexchar(unsigned int b)
862862
static char *cram(const char *challenge_64, const char *user, const char *pass)
863863
{
864864
int i, resp_len, encoded_len, decoded_len;
865-
HMAC_CTX hmac;
866865
unsigned char hash[16];
867866
char hex[33];
868867
char *response, *response_64, *challenge;
@@ -877,10 +876,8 @@ static char *cram(const char *challenge_64, const char *user, const char *pass)
877876
(unsigned char *)challenge_64, encoded_len);
878877
if (decoded_len < 0)
879878
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");
884881

885882
hex[32] = 0;
886883
for (i = 0; i < 16; i++) {

0 commit comments

Comments
 (0)