зеркало из https://github.com/github/ruby.git
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
This commit is contained in:
Родитель
b632ca436c
Коммит
935275bb59
|
@ -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
|
* ext/digest/digest_conf.rb (digest_conf): extract common
|
||||||
configurations.
|
configurations.
|
||||||
|
|
|
@ -30,3 +30,22 @@ typedef struct {
|
||||||
rb_digest_hash_update_func_t update_func;
|
rb_digest_hash_update_func_t update_func;
|
||||||
rb_digest_hash_finish_func_t finish_func;
|
rb_digest_hash_finish_func_t finish_func;
|
||||||
} rb_digest_metadata_t;
|
} 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); \
|
||||||
|
}
|
||||||
|
|
|
@ -10,7 +10,6 @@ def digest_conf(name, hdr = name, funcs = nil)
|
||||||
if funcs.all? {|func| OpenSSL.check_func("#{func}_Transform", hdr)} &&
|
if funcs.all? {|func| OpenSSL.check_func("#{func}_Transform", hdr)} &&
|
||||||
funcs.all? {|func| have_type("#{func}_CTX", hdr)}
|
funcs.all? {|func| have_type("#{func}_CTX", hdr)}
|
||||||
$defs << "-D#{name.upcase}_USE_OPENSSL"
|
$defs << "-D#{name.upcase}_USE_OPENSSL"
|
||||||
$objs << "#{name}ossl.#{$OBJEXT}"
|
|
||||||
return :ossl
|
return :ossl
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
/* $Id$ */
|
|
||||||
|
|
||||||
#include "md5ossl.h"
|
|
||||||
|
|
||||||
void
|
|
||||||
MD5_Finish(MD5_CTX *pctx, unsigned char *digest)
|
|
||||||
{
|
|
||||||
MD5_Final(digest, pctx);
|
|
||||||
}
|
|
|
@ -8,6 +8,8 @@
|
||||||
|
|
||||||
#define MD5_BLOCK_LENGTH MD5_CBLOCK
|
#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
|
#endif
|
||||||
|
|
|
@ -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);
|
|
||||||
}
|
|
|
@ -14,6 +14,7 @@
|
||||||
#define RMD160_BLOCK_LENGTH RIPEMD160_CBLOCK
|
#define RMD160_BLOCK_LENGTH RIPEMD160_CBLOCK
|
||||||
#define RMD160_DIGEST_LENGTH RIPEMD160_DIGEST_LENGTH
|
#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
|
#endif
|
||||||
|
|
|
@ -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);
|
|
||||||
}
|
|
|
@ -15,6 +15,8 @@
|
||||||
#endif
|
#endif
|
||||||
#define SHA1_DIGEST_LENGTH SHA_DIGEST_LENGTH
|
#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
|
#endif
|
||||||
|
|
|
@ -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)
|
|
|
@ -8,10 +8,20 @@
|
||||||
#define SHA384_BLOCK_LENGTH SHA512_CBLOCK
|
#define SHA384_BLOCK_LENGTH SHA512_CBLOCK
|
||||||
#define SHA512_BLOCK_LENGTH SHA512_CBLOCK
|
#define SHA512_BLOCK_LENGTH SHA512_CBLOCK
|
||||||
|
|
||||||
|
#ifndef __DragonFly__
|
||||||
|
#define SHA384_Final SHA512_Final
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef SHA512_CTX SHA384_CTX;
|
typedef SHA512_CTX SHA384_CTX;
|
||||||
|
|
||||||
void SHA256_Finish(SHA256_CTX *ctx, char *buf);
|
#undef SHA256_Finish
|
||||||
void SHA384_Finish(SHA384_CTX *ctx, char *buf);
|
#undef SHA384_Finish
|
||||||
void SHA512_Finish(SHA512_CTX *ctx, char *buf);
|
#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
|
#endif
|
||||||
|
|
Загрузка…
Ссылка в новой задаче