1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* ext/digest/rmd160: Use OpenSSL's RMD160 engine if available. It

is much faster than what we have now (rmd160.[ch]).  Add a knob
  (--with-bundled-rmd160) to extconf.rb which makes it use the
  bundled one anyway.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2894 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
knu 2002-09-26 17:26:46 +00:00
parent 965393cbb8
commit 15d643f44c
6 changed files with 88 additions and 5 deletions

View file

@ -1,3 +1,10 @@
Fri Sep 27 02:25:14 2002 Akinori MUSHA <knu@iDaemons.org>
* ext/digest/rmd160: Use OpenSSL's RMD160 engine if available. It
is much faster than what we have now (rmd160.[ch]). Add a knob
(--with-bundled-rmd160) to extconf.rb which makes it use the
bundled one anyway.
Fri Sep 27 01:23:39 2002 Akinori MUSHA <knu@iDaemons.org>
* ext/digest/md5: Use OpenSSL's MD5 engine if available. It is

View file

@ -5,3 +5,4 @@ rmd160hl.o: rmd160hl.c rmd160.h $(srcdir)/../defs.h $(hdrdir)/ruby.h \
rmd160init.o: rmd160init.c $(srcdir)/../digest.h $(hdrdir)/ruby.h \
$(topdir)/config.h $(hdrdir)/defines.h $(hdrdir)/intern.h \
rmd160.h $(srcdir)/../defs.h
rmd160ossl.o: rmd160ossl.h $(srcdir)/../defs.h

View file

@ -5,11 +5,17 @@ require "mkmf"
$CFLAGS << " -DHAVE_CONFIG_H -I#{File.dirname(__FILE__)}/.."
$objs = [
"rmd160.#{$OBJEXT}",
"rmd160hl.#{$OBJEXT}",
"rmd160init.#{$OBJEXT}",
]
$objs = [ "rmd160init.#{$OBJEXT}" ]
dir_config("openssl")
if !with_config("bundled-rmd160") &&
have_library("crypto") && have_header("openssl/ripemd.h")
$objs << "rmd160ossl.#{$OBJEXT}"
$libs << " -lcrypto"
else
$objs << "rmd160.#{$OBJEXT}" << "rmd160hl.#{$OBJEXT}"
end
have_header("sys/cdefs.h")

View file

@ -2,7 +2,11 @@
/* $Id$ */
#include "digest.h"
#if defined(HAVE_OPENSSL_RIPEMD_H)
#include "rmd160ossl.h"
#else
#include "rmd160.h"
#endif
static algo_t rmd160 = {
RMD160_DIGEST_LENGTH,

View file

@ -0,0 +1,45 @@
/* $Id$ */
#include "rmd160ossl.h"
#include "defs.h"
#include <assert.h>
#include <stdlib.h>
#ifndef _DIAGASSERT
#define _DIAGASSERT(cond) assert(cond)
#endif
char *
RMD160_End(RMD160_CTX *ctx, char *buf)
{
size_t i;
char *p = buf;
uint8_t digest[20];
static const char hex[]="0123456789abcdef";
_DIAGASSERT(ctx != NULL);
/* buf may be NULL */
if (p == NULL && (p = malloc(41)) == NULL)
return 0;
RMD160_Final(digest,ctx);
for (i = 0; i < 20; i++) {
p[i + i] = hex[(uint32_t)digest[i] >> 4];
p[i + i + 1] = hex[digest[i] & 0x0f];
}
p[i + i] = '\0';
return(p);
}
int RMD160_Equal(RMD160_CTX* pctx1, RMD160_CTX* pctx2) {
return pctx1->num == pctx2->num
&& pctx1->A == pctx2->A
&& pctx1->B == pctx2->B
&& pctx1->C == pctx2->C
&& pctx1->D == pctx2->D
&& pctx1->E == pctx2->E
&& pctx1->Nl == pctx2->Nl
&& pctx1->Nh == pctx2->Nh
&& memcmp(pctx1->data, pctx2->data, sizeof(pctx1->data)) == 0;
}

View file

@ -0,0 +1,20 @@
/* $Id$ */
#ifndef RMD160OSSL_H_INCLUDED
#define RMD160OSSL_H_INCLUDED
#include <openssl/ripemd.h>
#define RMD160_CTX RIPEMD160_CTX
#define RMD160_Init RIPEMD160_Init
#define RMD160_Update RIPEMD160_Update
#define RMD160_Final RIPEMD160_Final
#define RMD160_BLOCK_LENGTH RIPEMD160_CBLOCK
#define RMD160_DIGEST_LENGTH RIPEMD160_DIGEST_LENGTH
char *RMD160_End(RMD160_CTX *ctx, char *buf);
int RMD160_Equal(RMD160_CTX *pctx1, RMD160_CTX *pctx2);
#endif