summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--ext/digest/digest.h19
-rw-r--r--ext/digest/digest_conf.rb1
-rw-r--r--ext/digest/md5/md5ossl.c9
-rw-r--r--ext/digest/md5/md5ossl.h4
-rw-r--r--ext/digest/rmd160/rmd160ossl.c8
-rw-r--r--ext/digest/rmd160/rmd160ossl.h3
-rw-r--r--ext/digest/sha1/sha1ossl.c10
-rw-r--r--ext/digest/sha1/sha1ossl.h4
-rw-r--r--ext/digest/sha2/sha2ossl.c13
-rw-r--r--ext/digest/sha2/sha2ossl.h16
11 files changed, 44 insertions, 48 deletions
diff --git a/ChangeLog b/ChangeLog
index c7952d3997f..51152286e22 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,7 @@
-Wed Feb 11 11:08:48 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Wed Feb 11 11:09:21 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * ext/digest/digest.h (DEFINE_FINISH_FUNC_FROM_FINAL): macro for
+ finish functions, by inverting arguments order.
* ext/digest/digest_conf.rb (digest_conf): extract common
configurations.
diff --git a/ext/digest/digest.h b/ext/digest/digest.h
index 85848d5682c..30359ad3481 100644
--- a/ext/digest/digest.h
+++ b/ext/digest/digest.h
@@ -30,3 +30,22 @@ typedef struct {
rb_digest_hash_update_func_t update_func;
rb_digest_hash_finish_func_t finish_func;
} rb_digest_metadata_t;
+
+#define DEFINE_UPDATE_FUNC_FOR_UINT(name) \
+void \
+rb_digest_##name##_update(void *ctx, unsigned char *ptr, size_t size) \
+{ \
+ const unsigned int stride = 16384; \
+ \
+ for (; size > stride; size -= stride, ptr += stride) { \
+ name##_Update(ctx, ptr, stride); \
+ } \
+ if (size > 0) name##_Update(ctx, ptr, size); \
+}
+
+#define DEFINE_FINISH_FUNC_FROM_FINAL(name) \
+int \
+rb_digest_##name##_finish(void *ctx, unsigned char *ptr) \
+{ \
+ return name##_Final(ptr, ctx); \
+}
diff --git a/ext/digest/digest_conf.rb b/ext/digest/digest_conf.rb
index f2cb1f36e81..4b8b6f4c58c 100644
--- a/ext/digest/digest_conf.rb
+++ b/ext/digest/digest_conf.rb
@@ -10,7 +10,6 @@ def digest_conf(name, hdr = name, funcs = nil)
if funcs.all? {|func| OpenSSL.check_func("#{func}_Transform", hdr)} &&
funcs.all? {|func| have_type("#{func}_CTX", hdr)}
$defs << "-D#{name.upcase}_USE_OPENSSL"
- $objs << "#{name}ossl.#{$OBJEXT}"
return :ossl
end
end
diff --git a/ext/digest/md5/md5ossl.c b/ext/digest/md5/md5ossl.c
deleted file mode 100644
index d94ae2cd2f3..00000000000
--- a/ext/digest/md5/md5ossl.c
+++ /dev/null
@@ -1,9 +0,0 @@
-/* $Id$ */
-
-#include "md5ossl.h"
-
-void
-MD5_Finish(MD5_CTX *pctx, unsigned char *digest)
-{
- MD5_Final(digest, pctx);
-}
diff --git a/ext/digest/md5/md5ossl.h b/ext/digest/md5/md5ossl.h
index 1680c4f5c9f..2e9347ed944 100644
--- a/ext/digest/md5/md5ossl.h
+++ b/ext/digest/md5/md5ossl.h
@@ -8,6 +8,8 @@
#define MD5_BLOCK_LENGTH MD5_CBLOCK
-void MD5_Finish(MD5_CTX *pctx, unsigned char *digest);
+static DEFINE_FINISH_FUNC_FROM_FINAL(MD5);
+#undef MD5_Finish
+#define MD5_Finish rb_digest_MD5_finish
#endif
diff --git a/ext/digest/rmd160/rmd160ossl.c b/ext/digest/rmd160/rmd160ossl.c
deleted file mode 100644
index f24e63e3d8f..00000000000
--- a/ext/digest/rmd160/rmd160ossl.c
+++ /dev/null
@@ -1,8 +0,0 @@
-/* $Id$ */
-
-#include "defs.h"
-#include "rmd160ossl.h"
-
-void RMD160_Finish(RMD160_CTX *ctx, char *buf) {
- RIPEMD160_Final((unsigned char *)buf, ctx);
-}
diff --git a/ext/digest/rmd160/rmd160ossl.h b/ext/digest/rmd160/rmd160ossl.h
index 3df38a01c0d..e6bf5ea8d0b 100644
--- a/ext/digest/rmd160/rmd160ossl.h
+++ b/ext/digest/rmd160/rmd160ossl.h
@@ -14,6 +14,7 @@
#define RMD160_BLOCK_LENGTH RIPEMD160_CBLOCK
#define RMD160_DIGEST_LENGTH RIPEMD160_DIGEST_LENGTH
-void RMD160_Finish(RMD160_CTX *ctx, char *buf);
+static DEFINE_FINISH_FUNC_FROM_FINAL(RIPEMD160)
+#define RMD160_Finish rb_digest_RIPEMD160_finish
#endif
diff --git a/ext/digest/sha1/sha1ossl.c b/ext/digest/sha1/sha1ossl.c
deleted file mode 100644
index 452cf35084c..00000000000
--- a/ext/digest/sha1/sha1ossl.c
+++ /dev/null
@@ -1,10 +0,0 @@
-/* $Id$ */
-
-#include "defs.h"
-#include "sha1ossl.h"
-
-void
-SHA1_Finish(SHA1_CTX *ctx, char *buf)
-{
- SHA1_Final((unsigned char *)buf, ctx);
-}
diff --git a/ext/digest/sha1/sha1ossl.h b/ext/digest/sha1/sha1ossl.h
index 8f9984cc64c..80580b6460e 100644
--- a/ext/digest/sha1/sha1ossl.h
+++ b/ext/digest/sha1/sha1ossl.h
@@ -15,6 +15,8 @@
#endif
#define SHA1_DIGEST_LENGTH SHA_DIGEST_LENGTH
-void SHA1_Finish(SHA1_CTX *ctx, char *buf);
+static DEFINE_FINISH_FUNC_FROM_FINAL(SHA1);
+#undef SHA1_Finish
+#define SHA1_Finish rb_digest_SHA1_finish
#endif
diff --git a/ext/digest/sha2/sha2ossl.c b/ext/digest/sha2/sha2ossl.c
deleted file mode 100644
index 34353be8b86..00000000000
--- a/ext/digest/sha2/sha2ossl.c
+++ /dev/null
@@ -1,13 +0,0 @@
-#include "defs.h"
-#include "sha2ossl.h"
-
-#define SHA_Finish(bit) \
- void SHA##bit##_Finish(SHA##bit##_CTX *ctx, char *buf) \
- { SHA##bit##_Final((unsigned char *)buf, ctx);}
-#ifndef __DragonFly__
-#define SHA384_Final SHA512_Final
-#endif
-
-SHA_Finish(256)
-SHA_Finish(384)
-SHA_Finish(512)
diff --git a/ext/digest/sha2/sha2ossl.h b/ext/digest/sha2/sha2ossl.h
index 4229d14cf9c..f7258ee64af 100644
--- a/ext/digest/sha2/sha2ossl.h
+++ b/ext/digest/sha2/sha2ossl.h
@@ -8,10 +8,20 @@
#define SHA384_BLOCK_LENGTH SHA512_CBLOCK
#define SHA512_BLOCK_LENGTH SHA512_CBLOCK
+#ifndef __DragonFly__
+#define SHA384_Final SHA512_Final
+#endif
+
typedef SHA512_CTX SHA384_CTX;
-void SHA256_Finish(SHA256_CTX *ctx, char *buf);
-void SHA384_Finish(SHA384_CTX *ctx, char *buf);
-void SHA512_Finish(SHA512_CTX *ctx, char *buf);
+#undef SHA256_Finish
+#undef SHA384_Finish
+#undef SHA512_Finish
+#define SHA256_Finish rb_digest_SHA256_finish
+#define SHA384_Finish rb_digest_SHA384_finish
+#define SHA512_Finish rb_digest_SHA512_finish
+static DEFINE_FINISH_FUNC_FROM_FINAL(SHA256);
+static DEFINE_FINISH_FUNC_FROM_FINAL(SHA384);
+static DEFINE_FINISH_FUNC_FROM_FINAL(SHA512);
#endif