summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNobuyoshi Nakada <[email protected]>2024-09-26 05:24:20 +0900
committergit <[email protected]>2024-09-26 04:56:36 +0000
commita3fd24e22e4f7c38db891e1ddf8ea3461d28659f (patch)
tree41d9a9e7fcac5373f829a62b106ef730d99de499
parent7340c1ac71637e0cbe0d4905662aa7df40798d06 (diff)
[ruby/digest] Import patches for old macOS from MacPorts
https://github.com/ruby/digest/commit/07a5db2f77
-rw-r--r--ext/digest/md5/md5cc.h8
-rw-r--r--ext/digest/sha1/sha1cc.h8
-rw-r--r--ext/digest/sha2/sha2cc.h39
3 files changed, 55 insertions, 0 deletions
diff --git a/ext/digest/md5/md5cc.h b/ext/digest/md5/md5cc.h
index 0e7a58d2e0..657f573f85 100644
--- a/ext/digest/md5/md5cc.h
+++ b/ext/digest/md5/md5cc.h
@@ -25,3 +25,11 @@ static DEFINE_FINISH_FUNC_FROM_FINAL(MD5)
#undef MD5_Finish
#define MD5_Update rb_digest_MD5_update
#define MD5_Finish rb_digest_MD5_finish
+
+/*
+ * Pre-10.6 defines are with args, which don't match the argless use in
+ * the function pointer inits. Thus, we redefine MD5_Init as well.
+ * This is a NOP on 10.6+.
+ */
+#undef MD5_Init
+#define MD5_Init CC_MD5_Init
diff --git a/ext/digest/sha1/sha1cc.h b/ext/digest/sha1/sha1cc.h
index 2ed8d646ab..f39ecc6234 100644
--- a/ext/digest/sha1/sha1cc.h
+++ b/ext/digest/sha1/sha1cc.h
@@ -12,3 +12,11 @@ static DEFINE_FINISH_FUNC_FROM_FINAL(SHA1)
#undef SHA1_Finish
#define SHA1_Update rb_digest_SHA1_update
#define SHA1_Finish rb_digest_SHA1_finish
+
+/*
+ * Pre-10.6 defines are with args, which don't match the argless use in
+ * the function pointer inits. Thus, we redefine SHA1_Init as well.
+ * This is a NOP on 10.6+.
+ */
+#undef SHA1_Init
+#define SHA1_Init CC_SHA1_Init
diff --git a/ext/digest/sha2/sha2cc.h b/ext/digest/sha2/sha2cc.h
index 3f99604465..1245a2e2c7 100644
--- a/ext/digest/sha2/sha2cc.h
+++ b/ext/digest/sha2/sha2cc.h
@@ -1,6 +1,33 @@
#define COMMON_DIGEST_FOR_OPENSSL 1
#include <CommonCrypto/CommonDigest.h>
+/*
+ * Prior to 10.5, OpenSSL-compatible definitions are missing for
+ * SHA2 macros, though the CC_ versions are present.
+ * Add the missing definitions we actually use here if needed.
+ * Note that the definitions are the argless 10.6+-style.
+ * The weird CTX mismatch is copied from the 10.6 header.
+ */
+#ifndef SHA256_DIGEST_LENGTH
+#define SHA256_DIGEST_LENGTH CC_SHA256_DIGEST_LENGTH
+#define SHA256_CTX CC_SHA256_CTX
+#define SHA256_Update CC_SHA256_Update
+#define SHA256_Final CC_SHA256_Final
+#endif /* !defined SHA256_DIGEST_LENGTH */
+
+#ifndef SHA384_DIGEST_LENGTH
+#define SHA384_DIGEST_LENGTH CC_SHA384_DIGEST_LENGTH
+#define SHA512_CTX CC_SHA512_CTX
+#define SHA384_Update CC_SHA384_Update
+#define SHA384_Final CC_SHA384_Final
+#endif /* !defined SHA384_DIGEST_LENGTH */
+
+#ifndef SHA512_DIGEST_LENGTH
+#define SHA512_DIGEST_LENGTH CC_SHA512_DIGEST_LENGTH
+#define SHA512_Update CC_SHA512_Update
+#define SHA512_Final CC_SHA512_Final
+#endif /* !defined SHA512_DIGEST_LENGTH */
+
#define SHA256_BLOCK_LENGTH CC_SHA256_BLOCK_BYTES
#define SHA384_BLOCK_LENGTH CC_SHA384_BLOCK_BYTES
#define SHA512_BLOCK_LENGTH CC_SHA512_BLOCK_BYTES
@@ -29,3 +56,15 @@ static DEFINE_FINISH_FUNC_FROM_FINAL(SHA512)
#undef SHA512_Finish
#define SHA512_Update rb_digest_SHA512_update
#define SHA512_Finish rb_digest_SHA512_finish
+
+/*
+ * Pre-10.6 defines are with args, which don't match the argless use in
+ * the function pointer inits. Thus, we redefine SHA*_Init as well.
+ * This is a NOP on 10.6+.
+ */
+#undef SHA256_Init
+#define SHA256_Init CC_SHA256_Init
+#undef SHA384_Init
+#define SHA384_Init CC_SHA384_Init
+#undef SHA512_Init
+#define SHA512_Init CC_SHA512_Init