1 /* suppress inclusion of conflicting openssl functions */
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)
11 #define EVP_md5(...) kCCHmacAlgMD5
12 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
13 #define APPLE_LION_OR_NEWER
14 #include <Security/Security.h>
15 /* Apple's TYPE_BOOL conflicts with config.c */
19 #ifdef APPLE_LION_OR_NEWER
20 #define git_CC_error_check(pattern, err) \
23 die(pattern, (long)CFErrorGetCode(err)); \
27 #define EVP_EncodeBlock git_CC_EVP_EncodeBlock
28 static inline int git_CC_EVP_EncodeBlock(unsigned char *out
,
29 const unsigned char *in
, int inlen
)
32 SecTransformRef encoder
;
33 CFDataRef input
, output
;
36 encoder
= SecEncodeTransformCreate(kSecBase64Encoding
, &err
);
37 git_CC_error_check("SecEncodeTransformCreate failed: %ld", err
);
39 input
= CFDataCreate(kCFAllocatorDefault
, in
, inlen
);
40 SecTransformSetAttribute(encoder
, kSecTransformInputAttributeName
,
42 git_CC_error_check("SecTransformSetAttribute failed: %ld", err
);
44 output
= SecTransformExecute(encoder
, &err
);
45 git_CC_error_check("SecTransformExecute failed: %ld", err
);
47 length
= CFDataGetLength(output
);
48 CFDataGetBytes(output
, CFRangeMake(0, length
), out
);
54 return (int)strlen((const char *)out
);
57 #define EVP_DecodeBlock git_CC_EVP_DecodeBlock
58 static int inline git_CC_EVP_DecodeBlock(unsigned char *out
,
59 const unsigned char *in
, int inlen
)
62 SecTransformRef decoder
;
63 CFDataRef input
, output
;
66 decoder
= SecDecodeTransformCreate(kSecBase64Encoding
, &err
);
67 git_CC_error_check("SecEncodeTransformCreate failed: %ld", err
);
69 input
= CFDataCreate(kCFAllocatorDefault
, in
, inlen
);
70 SecTransformSetAttribute(decoder
, kSecTransformInputAttributeName
,
72 git_CC_error_check("SecTransformSetAttribute failed: %ld", err
);
74 output
= SecTransformExecute(decoder
, &err
);
75 git_CC_error_check("SecTransformExecute failed: %ld", err
);
77 length
= CFDataGetLength(output
);
78 CFDataGetBytes(output
, CFRangeMake(0, length
), out
);
84 return (int)strlen((const char *)out
);
86 #endif /* APPLE_LION_OR_NEWER */