summaryrefslogtreecommitdiff
path: root/ext/digest
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-02-11 02:09:55 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-02-11 02:09:55 +0000
commitb97ceb66e97f2a36e5602f74a593c61292cbd33b (patch)
treebd3085b343ba5abd5b40338007e880c5fde64176 /ext/digest
parent935275bb5952b59b65c6a038a4b825aea95562ae (diff)
digest: CommonDigest
* ext/digest/digest_conf.rb (digest_conf): check for CommonDigest. * ext/digest/*/*cc.h: for Apple CommonCrypto/CommonDigest.h. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49565 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/digest')
-rw-r--r--ext/digest/digest_conf.rb9
-rw-r--r--ext/digest/md5/md5cc.h12
-rw-r--r--ext/digest/md5/md5init.c2
-rw-r--r--ext/digest/sha1/sha1cc.h14
-rw-r--r--ext/digest/sha1/sha1init.c2
-rw-r--r--ext/digest/sha2/sha2cc.h31
-rw-r--r--ext/digest/sha2/sha2init.c2
7 files changed, 72 insertions, 0 deletions
diff --git a/ext/digest/digest_conf.rb b/ext/digest/digest_conf.rb
index 4b8b6f4c58..b2a8195fa2 100644
--- a/ext/digest/digest_conf.rb
+++ b/ext/digest/digest_conf.rb
@@ -1,5 +1,14 @@
def digest_conf(name, hdr = name, funcs = nil)
unless with_config("bundled-#{name}")
+ cc = with_config("common-digest")
+ if cc == true or /\b#{name}\b/ =~ cc
+ if File.exist?("#$srcdir/#{name}cc.h") and
+ have_header("CommonCrypto/CommonDigest.h")
+ $defs << "-D#{name.upcase}_USE_COMMONDIGEST"
+ return :commondigest
+ end
+ end
+
dir_config("openssl")
pkg_config("openssl")
require File.expand_path('../../openssl/deprecation', __FILE__)
diff --git a/ext/digest/md5/md5cc.h b/ext/digest/md5/md5cc.h
new file mode 100644
index 0000000000..63a7ae9d67
--- /dev/null
+++ b/ext/digest/md5/md5cc.h
@@ -0,0 +1,12 @@
+#define COMMON_DIGEST_FOR_OPENSSL 1
+#include <CommonCrypto/CommonDigest.h>
+
+#define MD5_BLOCK_LENGTH CC_MD5_BLOCK_BYTES
+
+static DEFINE_UPDATE_FUNC_FOR_UINT(MD5);
+static DEFINE_FINISH_FUNC_FROM_FINAL(MD5);
+
+#undef MD5_Update
+#undef MD5_Finish
+#define MD5_Update rb_digest_MD5_update
+#define MD5_Finish rb_digest_MD5_finish
diff --git a/ext/digest/md5/md5init.c b/ext/digest/md5/md5init.c
index 93d01a2f41..db9298cbfc 100644
--- a/ext/digest/md5/md5init.c
+++ b/ext/digest/md5/md5init.c
@@ -4,6 +4,8 @@
#include "digest.h"
#if defined(MD5_USE__OPENSSL)
#include "md5ossl.h"
+#elif defined(MD5_USE_COMMONDIGEST)
+#include "md5cc.h"
#else
#include "md5.h"
#endif
diff --git a/ext/digest/sha1/sha1cc.h b/ext/digest/sha1/sha1cc.h
new file mode 100644
index 0000000000..1376c49ec7
--- /dev/null
+++ b/ext/digest/sha1/sha1cc.h
@@ -0,0 +1,14 @@
+#define COMMON_DIGEST_FOR_OPENSSL 1
+#include <CommonCrypto/CommonDigest.h>
+
+#define SHA1_BLOCK_LENGTH CC_SHA1_BLOCK_BYTES
+#define SHA1_DIGEST_LENGTH CC_SHA1_DIGEST_LENGTH
+#define SHA1_CTX CC_SHA1_CTX
+
+static DEFINE_UPDATE_FUNC_FOR_UINT(SHA1);
+static DEFINE_FINISH_FUNC_FROM_FINAL(SHA1);
+
+#undef SHA1_Update
+#undef SHA1_Finish
+#define SHA1_Update rb_digest_SHA1_update
+#define SHA1_Finish rb_digest_SHA1_finish
diff --git a/ext/digest/sha1/sha1init.c b/ext/digest/sha1/sha1init.c
index 72529fe0b7..1f0580883f 100644
--- a/ext/digest/sha1/sha1init.c
+++ b/ext/digest/sha1/sha1init.c
@@ -4,6 +4,8 @@
#include "digest.h"
#if defined(SHA1_USE_OPENSSL)
#include "sha1ossl.h"
+#elif defined(SHA1_USE_COMMONDIGEST)
+#include "sha1cc.h"
#else
#include "sha1.h"
#endif
diff --git a/ext/digest/sha2/sha2cc.h b/ext/digest/sha2/sha2cc.h
new file mode 100644
index 0000000000..49d463088f
--- /dev/null
+++ b/ext/digest/sha2/sha2cc.h
@@ -0,0 +1,31 @@
+#define COMMON_DIGEST_FOR_OPENSSL 1
+#include <CommonCrypto/CommonDigest.h>
+
+#define SHA256_BLOCK_LENGTH CC_SHA256_BLOCK_BYTES
+#define SHA384_BLOCK_LENGTH CC_SHA384_BLOCK_BYTES
+#define SHA512_BLOCK_LENGTH CC_SHA512_BLOCK_BYTES
+
+#define SHA384_CTX CC_SHA512_CTX
+
+static DEFINE_UPDATE_FUNC_FOR_UINT(SHA256);
+static DEFINE_FINISH_FUNC_FROM_FINAL(SHA256);
+static DEFINE_UPDATE_FUNC_FOR_UINT(SHA384);
+static DEFINE_FINISH_FUNC_FROM_FINAL(SHA384);
+static DEFINE_UPDATE_FUNC_FOR_UINT(SHA512);
+static DEFINE_FINISH_FUNC_FROM_FINAL(SHA512);
+
+
+#undef SHA256_Update
+#undef SHA256_Finish
+#define SHA256_Update rb_digest_SHA256_update
+#define SHA256_Finish rb_digest_SHA256_finish
+
+#undef SHA384_Update
+#undef SHA384_Finish
+#define SHA384_Update rb_digest_SHA384_update
+#define SHA384_Finish rb_digest_SHA384_finish
+
+#undef SHA512_Update
+#undef SHA512_Finish
+#define SHA512_Update rb_digest_SHA512_update
+#define SHA512_Finish rb_digest_SHA512_finish
diff --git a/ext/digest/sha2/sha2init.c b/ext/digest/sha2/sha2init.c
index 7b39bda649..09ccee5ac4 100644
--- a/ext/digest/sha2/sha2init.c
+++ b/ext/digest/sha2/sha2init.c
@@ -4,6 +4,8 @@
#include "digest.h"
#if defined(SHA2_USE_OPENSSL)
#include "sha2ossl.h"
+#elif defined(SHA2_USE_COMMONDIGEST)
+#include "sha2cc.h"
#else
#include "sha2.h"
#endif