1 /* suppress inclusion of conflicting openssl functions */
5 #include <CommonCrypto/CommonHMAC.h>
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
)
14 CCHmac(alg
, key
, key_len
, data
, data_len
, md
);
18 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
19 #define APPLE_LION_OR_NEWER
20 #include <Security/Security.h>
21 /* Apple's TYPE_BOOL conflicts with config.c */
25 #ifndef SHA1_MAX_BLOCK_SIZE
26 #error Using Apple Common Crypto library requires setting SHA1_MAX_BLOCK_SIZE
29 #ifdef APPLE_LION_OR_NEWER
30 #define git_CC_error_check(pattern, err) \
33 die(pattern, (long)CFErrorGetCode(err)); \
37 #define EVP_EncodeBlock git_CC_EVP_EncodeBlock
38 static inline int git_CC_EVP_EncodeBlock(unsigned char *out
,
39 const unsigned char *in
, int inlen
)
42 SecTransformRef encoder
;
43 CFDataRef input
, output
;
46 encoder
= SecEncodeTransformCreate(kSecBase64Encoding
, &err
);
47 git_CC_error_check("SecEncodeTransformCreate failed: %ld", err
);
49 input
= CFDataCreate(kCFAllocatorDefault
, in
, inlen
);
50 SecTransformSetAttribute(encoder
, kSecTransformInputAttributeName
,
52 git_CC_error_check("SecTransformSetAttribute failed: %ld", err
);
54 output
= SecTransformExecute(encoder
, &err
);
55 git_CC_error_check("SecTransformExecute failed: %ld", err
);
57 length
= CFDataGetLength(output
);
58 CFDataGetBytes(output
, CFRangeMake(0, length
), out
);
64 return (int)strlen((const char *)out
);
67 #define EVP_DecodeBlock git_CC_EVP_DecodeBlock
68 static int inline git_CC_EVP_DecodeBlock(unsigned char *out
,
69 const unsigned char *in
, int inlen
)
72 SecTransformRef decoder
;
73 CFDataRef input
, output
;
76 decoder
= SecDecodeTransformCreate(kSecBase64Encoding
, &err
);
77 git_CC_error_check("SecEncodeTransformCreate failed: %ld", err
);
79 input
= CFDataCreate(kCFAllocatorDefault
, in
, inlen
);
80 SecTransformSetAttribute(decoder
, kSecTransformInputAttributeName
,
82 git_CC_error_check("SecTransformSetAttribute failed: %ld", err
);
84 output
= SecTransformExecute(decoder
, &err
);
85 git_CC_error_check("SecTransformExecute failed: %ld", err
);
87 length
= CFDataGetLength(output
);
88 CFDataGetBytes(output
, CFRangeMake(0, length
), out
);
94 return (int)strlen((const char *)out
);
96 #endif /* APPLE_LION_OR_NEWER */