ruby-changes:37483
From: nobu <ko1@a...>
Date: Wed, 11 Feb 2015 11:09:30 +0900 (JST)
Subject: [ruby-changes:37483] nobu:r49564 (trunk): digest: define Finish func from Final func
nobu 2015-02-11 11:09:23 +0900 (Wed, 11 Feb 2015) New Revision: 49564 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=49564 Log: digest: define Finish func from Final func * ext/digest/digest.h (DEFINE_FINISH_FUNC_FROM_FINAL): macro for finish functions, by inverting arguments order. Removed files: trunk/ext/digest/md5/md5ossl.c trunk/ext/digest/rmd160/rmd160ossl.c trunk/ext/digest/sha1/sha1ossl.c trunk/ext/digest/sha2/sha2ossl.c Modified files: trunk/ChangeLog trunk/ext/digest/digest.h trunk/ext/digest/digest_conf.rb trunk/ext/digest/md5/md5ossl.h trunk/ext/digest/rmd160/rmd160ossl.h trunk/ext/digest/sha1/sha1ossl.h trunk/ext/digest/sha2/sha2ossl.h Index: ChangeLog =================================================================== --- ChangeLog (revision 49563) +++ ChangeLog (revision 49564) @@ -1,4 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 -Wed Feb 11 11:08:48 2015 Nobuyoshi Nakada <nobu@r...> +Wed Feb 11 11:09:21 2015 Nobuyoshi Nakada <nobu@r...> + + * 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. Index: ext/digest/digest.h =================================================================== --- ext/digest/digest.h (revision 49563) +++ ext/digest/digest.h (revision 49564) @@ -30,3 +30,22 @@ typedef struct { https://github.com/ruby/ruby/blob/trunk/ext/digest/digest.h#L30 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); \ +} Index: ext/digest/md5/md5ossl.c =================================================================== --- ext/digest/md5/md5ossl.c (revision 49563) +++ ext/digest/md5/md5ossl.c (revision 49564) @@ -1,9 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/ext/digest/md5/md5ossl.c#L0 -/* $Id$ */ - -#include "md5ossl.h" - -void -MD5_Finish(MD5_CTX *pctx, unsigned char *digest) -{ - MD5_Final(digest, pctx); -} Index: ext/digest/md5/md5ossl.h =================================================================== --- ext/digest/md5/md5ossl.h (revision 49563) +++ ext/digest/md5/md5ossl.h (revision 49564) @@ -8,6 +8,8 @@ https://github.com/ruby/ruby/blob/trunk/ext/digest/md5/md5ossl.h#L8 #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 Index: ext/digest/digest_conf.rb =================================================================== --- ext/digest/digest_conf.rb (revision 49563) +++ ext/digest/digest_conf.rb (revision 49564) @@ -10,7 +10,6 @@ def digest_conf(name, hdr = name, funcs https://github.com/ruby/ruby/blob/trunk/ext/digest/digest_conf.rb#L10 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 Index: ext/digest/rmd160/rmd160ossl.c =================================================================== --- ext/digest/rmd160/rmd160ossl.c (revision 49563) +++ ext/digest/rmd160/rmd160ossl.c (revision 49564) @@ -1,8 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/ext/digest/rmd160/rmd160ossl.c#L0 -/* $Id$ */ - -#include "defs.h" -#include "rmd160ossl.h" - -void RMD160_Finish(RMD160_CTX *ctx, char *buf) { - RIPEMD160_Final((unsigned char *)buf, ctx); -} Index: ext/digest/rmd160/rmd160ossl.h =================================================================== --- ext/digest/rmd160/rmd160ossl.h (revision 49563) +++ ext/digest/rmd160/rmd160ossl.h (revision 49564) @@ -14,6 +14,7 @@ https://github.com/ruby/ruby/blob/trunk/ext/digest/rmd160/rmd160ossl.h#L14 #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 Index: ext/digest/sha1/sha1ossl.c =================================================================== --- ext/digest/sha1/sha1ossl.c (revision 49563) +++ ext/digest/sha1/sha1ossl.c (revision 49564) @@ -1,10 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/ext/digest/sha1/sha1ossl.c#L0 -/* $Id$ */ - -#include "defs.h" -#include "sha1ossl.h" - -void -SHA1_Finish(SHA1_CTX *ctx, char *buf) -{ - SHA1_Final((unsigned char *)buf, ctx); -} Index: ext/digest/sha1/sha1ossl.h =================================================================== --- ext/digest/sha1/sha1ossl.h (revision 49563) +++ ext/digest/sha1/sha1ossl.h (revision 49564) @@ -15,6 +15,8 @@ https://github.com/ruby/ruby/blob/trunk/ext/digest/sha1/sha1ossl.h#L15 #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 Index: ext/digest/sha2/sha2ossl.c =================================================================== --- ext/digest/sha2/sha2ossl.c (revision 49563) +++ ext/digest/sha2/sha2ossl.c (revision 49564) @@ -1,13 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/ext/digest/sha2/sha2ossl.c#L0 -#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) Index: ext/digest/sha2/sha2ossl.h =================================================================== --- ext/digest/sha2/sha2ossl.h (revision 49563) +++ ext/digest/sha2/sha2ossl.h (revision 49564) @@ -8,10 +8,20 @@ https://github.com/ruby/ruby/blob/trunk/ext/digest/sha2/sha2ossl.h#L8 #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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/