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 #ifndef SHA1_MAX_BLOCK_SIZE
20 #error Using Apple Common Crypto library requires setting SHA1_MAX_BLOCK_SIZE
23 #ifdef APPLE_LION_OR_NEWER
24 #define git_CC_error_check(pattern, err) \
27 die(pattern, (long)CFErrorGetCode(err)); \
31 #define EVP_EncodeBlock git_CC_EVP_EncodeBlock
32 static inline int git_CC_EVP_EncodeBlock(unsigned char *out
,
33 const unsigned char *in
, int inlen
)
36 SecTransformRef encoder
;
37 CFDataRef input
, output
;
40 encoder
= SecEncodeTransformCreate(kSecBase64Encoding
, &err
);
41 git_CC_error_check("SecEncodeTransformCreate failed: %ld", err
);
43 input
= CFDataCreate(kCFAllocatorDefault
, in
, inlen
);
44 SecTransformSetAttribute(encoder
, kSecTransformInputAttributeName
,
46 git_CC_error_check("SecTransformSetAttribute failed: %ld", err
);
48 output
= SecTransformExecute(encoder
, &err
);
49 git_CC_error_check("SecTransformExecute failed: %ld", err
);
51 length
= CFDataGetLength(output
);
52 CFDataGetBytes(output
, CFRangeMake(0, length
), out
);
58 return (int)strlen((const char *)out
);
61 #define EVP_DecodeBlock git_CC_EVP_DecodeBlock
62 static int inline git_CC_EVP_DecodeBlock(unsigned char *out
,
63 const unsigned char *in
, int inlen
)
66 SecTransformRef decoder
;
67 CFDataRef input
, output
;
70 decoder
= SecDecodeTransformCreate(kSecBase64Encoding
, &err
);
71 git_CC_error_check("SecEncodeTransformCreate failed: %ld", err
);
73 input
= CFDataCreate(kCFAllocatorDefault
, in
, inlen
);
74 SecTransformSetAttribute(decoder
, kSecTransformInputAttributeName
,
76 git_CC_error_check("SecTransformSetAttribute failed: %ld", err
);
78 output
= SecTransformExecute(decoder
, &err
);
79 git_CC_error_check("SecTransformExecute failed: %ld", err
);
81 length
= CFDataGetLength(output
);
82 CFDataGetBytes(output
, CFRangeMake(0, length
), out
);
88 return (int)strlen((const char *)out
);
90 #endif /* APPLE_LION_OR_NEWER */