ext_digest_sha1_commoncrypto.diff   [plain text]


diff -Naur ../../ruby.orig/ruby/ext/digest/sha1/extconf.rb ./ext/digest/sha1/extconf.rb
--- ../../ruby.orig/ruby/ext/digest/sha1/extconf.rb	2012-01-09 04:00:39.000000000 -0800
+++ ./ext/digest/sha1/extconf.rb	2012-01-09 03:53:49.000000000 -0800
@@ -8,14 +8,12 @@
 
 $objs = [ "sha1init.#{$OBJEXT}" ]
 
-dir_config("openssl")
-
-if !with_config("bundled-sha1") &&
-    have_library("crypto") && have_header("openssl/sha.h")
-  $objs << "sha1ossl.#{$OBJEXT}"
-else
-  $objs << "sha1.#{$OBJEXT}"
-end
+#if !with_config("bundled-sha1") &&
+#    have_library("crypto") && have_header("openssl/sha.h")
+#  $objs << "sha1ossl.#{$OBJEXT}"
+#else
+  $objs << "sha1cc.#{$OBJEXT}"
+#end
 
 have_header("sys/cdefs.h")
 
diff -Naur ../../ruby.orig/ruby/ext/digest/sha1/sha1cc.c ./ext/digest/sha1/sha1cc.c
--- ../../ruby.orig/ruby/ext/digest/sha1/sha1cc.c	1969-12-31 16:00:00.000000000 -0800
+++ ./ext/digest/sha1/sha1cc.c	2012-01-12 00:51:47.000000000 -0800
@@ -0,0 +1,20 @@
+#include "defs.h"
+#include "sha1cc.h"
+
+void
+SHA1_Update(SHA1_CTX *ctx, const uint8_t *data, size_t len)
+{
+	uint8_t *ptr = data;
+	size_t i;
+
+	for (i = 0, ptr = data; i < (len / SHA1_STRIDE_SIZE); i++, ptr += SHA1_STRIDE_SIZE) {
+		CC_SHA1_Update(ctx, ptr, SHA1_STRIDE_SIZE);
+	}
+	CC_SHA1_Update(ctx, ptr, len % SHA1_STRIDE_SIZE);
+}
+
+void
+SHA1_Finish(SHA1_CTX *ctx, char *buf)
+{
+	CC_SHA1_Final((unsigned char *)buf, ctx);
+}
diff -Naur ../../ruby.orig/ruby/ext/digest/sha1/sha1cc.h ./ext/digest/sha1/sha1cc.h
--- ../../ruby.orig/ruby/ext/digest/sha1/sha1cc.h	1969-12-31 16:00:00.000000000 -0800
+++ ./ext/digest/sha1/sha1cc.h	2012-01-10 06:35:26.000000000 -0800
@@ -0,0 +1,20 @@
+#ifndef SHA1CC_H_INCLUDED
+#define SHA1CC_H_INCLUDED
+
+#include <CommonCrypto/CommonDigest.h>
+
+#define SHA1_CTX	CC_SHA1_CTX
+
+#define SHA1_BLOCK_LENGTH	CC_SHA1_BLOCK_BYTES
+#define SHA1_DIGEST_LENGTH	CC_SHA1_DIGEST_LENGTH
+
+#define SHA1_Init CC_SHA1_Init
+#define SHA1_Update CC_SHA1_Update_Block
+#define SHA1_Finish CC_SHA1_Finish
+
+#define SHA1_STRIDE_SIZE	16384
+
+void SHA1_Update(SHA1_CTX *context, const uint8_t *data, size_t len);
+void SHA1_Finish(SHA1_CTX *ctx, char *buf);
+
+#endif
diff -Naur ../../ruby.orig/ruby/ext/digest/sha1/sha1init.c ./ext/digest/sha1/sha1init.c
--- ../../ruby.orig/ruby/ext/digest/sha1/sha1init.c	2007-02-12 15:01:19.000000000 -0800
+++ ./ext/digest/sha1/sha1init.c	2012-01-09 03:48:29.000000000 -0800
@@ -2,7 +2,9 @@
 /* $Id: sha1init.c 11708 2007-02-12 23:01:19Z shyouhei $ */
 
 #include "digest.h"
-#if defined(HAVE_OPENSSL_SHA_H)
+#if defined(__APPLE__)
+#include "sha1cc.h"
+#elif defined(HAVE_OPENSSL_SHA_H)
 #include "sha1ossl.h"
 #else
 #include "sha1.h"