|
1 | 1 | #define COMMON_DIGEST_FOR_OPENSSL 1
|
2 | 2 | #include <CommonCrypto/CommonDigest.h>
|
3 | 3 |
|
| 4 | +/* |
| 5 | + * Prior to 10.5, OpenSSL-compatible definitions are missing for |
| 6 | + * SHA2 macros, though the CC_ versions are present. |
| 7 | + * Add the missing definitions we actually use here if needed. |
| 8 | + * Note that the definitions are the argless 10.6+-style. |
| 9 | + * The weird CTX mismatch is copied from the 10.6 header. |
| 10 | + */ |
| 11 | +#ifndef SHA256_DIGEST_LENGTH |
| 12 | +#define SHA256_DIGEST_LENGTH CC_SHA256_DIGEST_LENGTH |
| 13 | +#define SHA256_CTX CC_SHA256_CTX |
| 14 | +#define SHA256_Update CC_SHA256_Update |
| 15 | +#define SHA256_Final CC_SHA256_Final |
| 16 | +#endif /* !defined SHA256_DIGEST_LENGTH */ |
| 17 | + |
| 18 | +#ifndef SHA384_DIGEST_LENGTH |
| 19 | +#define SHA384_DIGEST_LENGTH CC_SHA384_DIGEST_LENGTH |
| 20 | +#define SHA512_CTX CC_SHA512_CTX |
| 21 | +#define SHA384_Update CC_SHA384_Update |
| 22 | +#define SHA384_Final CC_SHA384_Final |
| 23 | +#endif /* !defined SHA384_DIGEST_LENGTH */ |
| 24 | + |
| 25 | +#ifndef SHA512_DIGEST_LENGTH |
| 26 | +#define SHA512_DIGEST_LENGTH CC_SHA512_DIGEST_LENGTH |
| 27 | +#define SHA512_Update CC_SHA512_Update |
| 28 | +#define SHA512_Final CC_SHA512_Final |
| 29 | +#endif /* !defined SHA512_DIGEST_LENGTH */ |
| 30 | + |
4 | 31 | #define SHA256_BLOCK_LENGTH CC_SHA256_BLOCK_BYTES
|
5 | 32 | #define SHA384_BLOCK_LENGTH CC_SHA384_BLOCK_BYTES
|
6 | 33 | #define SHA512_BLOCK_LENGTH CC_SHA512_BLOCK_BYTES
|
@@ -29,3 +56,15 @@ static DEFINE_FINISH_FUNC_FROM_FINAL(SHA512)
|
29 | 56 | #undef SHA512_Finish
|
30 | 57 | #define SHA512_Update rb_digest_SHA512_update
|
31 | 58 | #define SHA512_Finish rb_digest_SHA512_finish
|
| 59 | + |
| 60 | +/* |
| 61 | + * Pre-10.6 defines are with args, which don't match the argless use in |
| 62 | + * the function pointer inits. Thus, we redefine SHA*_Init as well. |
| 63 | + * This is a NOP on 10.6+. |
| 64 | + */ |
| 65 | +#undef SHA256_Init |
| 66 | +#define SHA256_Init CC_SHA256_Init |
| 67 | +#undef SHA384_Init |
| 68 | +#define SHA384_Init CC_SHA384_Init |
| 69 | +#undef SHA512_Init |
| 70 | +#define SHA512_Init CC_SHA512_Init |
0 commit comments