From 6175ca03be6d0d51359f9017123708987d0f5eb7 Mon Sep 17 00:00:00 2001 From: shyouhei Date: Wed, 15 Aug 2007 23:23:39 +0000 Subject: add tag v1_8_5_91 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/tags/v1_8_5_91@13046 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ruby_1_8_5/ext/digest/rmd160/rmd160hl.c | 96 +++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 ruby_1_8_5/ext/digest/rmd160/rmd160hl.c (limited to 'ruby_1_8_5/ext/digest/rmd160/rmd160hl.c') diff --git a/ruby_1_8_5/ext/digest/rmd160/rmd160hl.c b/ruby_1_8_5/ext/digest/rmd160/rmd160hl.c new file mode 100644 index 0000000000..14299d7c7a --- /dev/null +++ b/ruby_1_8_5/ext/digest/rmd160/rmd160hl.c @@ -0,0 +1,96 @@ +/* $NetBSD: rmd160hl.c,v 1.1.1.1 2001/03/06 11:21:05 agc Exp $ */ +/* $RoughId: rmd160hl.c,v 1.2 2001/07/13 19:49:10 knu Exp $ */ +/* $Id: rmd160hl.c,v 1.1 2001/07/13 20:06:14 knu Exp $ */ + +/* rmd160hl.c + * ---------------------------------------------------------------------------- + * "THE BEER-WARE LICENSE" (Revision 42): + * wrote this file. As long as you retain this notice you + * can do whatever you want with this stuff. If we meet some day, and you think + * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp + * ---------------------------------------------------------------------------- + * + * from OpenBSD: rmd160hl.c,v 1.2 1999/08/17 09:13:12 millert Exp $ + */ + +#include "rmd160.h" + +#ifndef lint +/* __RCSID("$NetBSD: rmd160hl.c,v 1.1.1.1 2001/03/06 11:21:05 agc Exp $"); */ +#endif /* not lint */ + +/* #include "namespace.h" */ + +#include +#include +#include +#include +#include +#if defined(HAVE_UNISTD_H) +# include +#endif + +#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); +} + +char * +RMD160_File(char *filename, char *buf) +{ + uint8_t buffer[BUFSIZ]; + RMD160_CTX ctx; + int fd, num, oerrno; + + _DIAGASSERT(filename != NULL); + /* XXX: buf may be NULL ? */ + + RMD160_Init(&ctx); + + if ((fd = open(filename, O_RDONLY)) < 0) + return(0); + + while ((num = read(fd, buffer, sizeof(buffer))) > 0) + RMD160_Update(&ctx, buffer, (size_t)num); + + oerrno = errno; + close(fd); + errno = oerrno; + return(num < 0 ? 0 : RMD160_End(&ctx, buf)); +} + +char * +RMD160_Data(const uint8_t *data, size_t len, char *buf) +{ + RMD160_CTX ctx; + + _DIAGASSERT(data != NULL); + /* XXX: buf may be NULL ? */ + + RMD160_Init(&ctx); + RMD160_Update(&ctx, data, len); + return(RMD160_End(&ctx, buf)); +} -- cgit v1.2.3