summaryrefslogtreecommitdiff
path: root/ext/digest
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-02-11 02:09:23 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-02-11 02:09:23 +0000
commit935275bb5952b59b65c6a038a4b825aea95562ae (patch)
tree4f6fe32cbd24811dcc0b38153d426adc845dde02 /ext/digest
parentb632ca436c5d06defc87df8b2a4774680e9cf6ef (diff)
digest: define Finish func from Final func
* ext/digest/digest.h (DEFINE_FINISH_FUNC_FROM_FINAL): macro for finish functions, by inverting arguments order. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49564 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/digest')
-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
10 files changed, 40 insertions, 47 deletions
diff --git a/ext/digest/digest.h b/ext/digest/digest.h
index 85848d5..30359ad 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 f2cb1f3..4b8b6f4 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 d94ae2c..0000000
--- 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 1680c4f..2e9347e 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 f24e63e..0000000
--- 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 3df38a0..e6bf5ea 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 452cf35..0000000
--- 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 8f9984c..80580b6 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 34353be..0000000
--- 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 4229d14..f7258ee 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