diff options
author | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2006-10-05 11:09:42 +0000 |
---|---|---|
committer | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2006-10-05 11:09:42 +0000 |
commit | b9673f64f10197b4c2742331e0cccb9c1352c7bc (patch) | |
tree | 817b68702a7f2cb4c7d71fdfde208355c5c76a76 /ext/digest/sha2 | |
parent | 9b616442e26cf50f42b13f7584493ae96bb3aedd (diff) | |
download | ruby-b9673f64f10197b4c2742331e0cccb9c1352c7bc.tar.gz |
* ext/digest/digest.[ch]: Since the argument order of
hash_final_func_t was inconsistent with others, change it and
rename to hash_finish_func_t to avoid confusion.
* ext/digest/digest.[ch]: Remove and eliminate the use of
hash_end_func_t. Implement hexdigest conversion in the base
class.
* ext/digest/md5/md5.c, ext/digest/md5/md5.h,
ext/digest/md5/md5init.c, ext/digest/md5/md5ossl.c,
ext/digest/md5/md5ossl.h: Remove MD5_End() and change
MD5_Final() to MD5_Finish().
* ext/digest/rmd160/depend, ext/digest/rmd160/extconf.rb,
ext/digest/rmd160/rmd160.c, ext/digest/rmd160/rmd160.h,
ext/digest/rmd160/rmd160hl.c, ext/digest/rmd160/rmd160init.c,
ext/digest/rmd160/rmd160ossl.c, ext/digest/rmd160/rmd160ossl.h:
Remove unused functions RMD160_End(), RMD160_File(),
RMD160_Data() and change RMD160_Final() to RMD160_Finish().
* ext/digest/sha1/extconf.rb, ext/digest/sha1/sha1.c,
ext/digest/sha1/sha1.h, ext/digest/sha1/sha1hl.c,
ext/digest/sha1/sha1init.c, ext/digest/sha1/sha1ossl.c,
ext/digest/sha1/sha1ossl.h: Likewise.
* ext/digest/sha2/extconf.rb, ext/digest/sha2/sha2.c,
ext/digest/sha2/sha2.h, ext/digest/sha2/sha2hl.c,
ext/digest/sha2/sha2init.c: Likewise.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11086 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/digest/sha2')
-rw-r--r-- | ext/digest/sha2/extconf.rb | 1 | ||||
-rw-r--r-- | ext/digest/sha2/sha2.c | 6 | ||||
-rw-r--r-- | ext/digest/sha2/sha2.h | 30 | ||||
-rw-r--r-- | ext/digest/sha2/sha2hl.c | 252 | ||||
-rw-r--r-- | ext/digest/sha2/sha2init.c | 3 |
5 files changed, 10 insertions, 282 deletions
diff --git a/ext/digest/sha2/extconf.rb b/ext/digest/sha2/extconf.rb index 200d386bef..c084a51a64 100644 --- a/ext/digest/sha2/extconf.rb +++ b/ext/digest/sha2/extconf.rb @@ -8,7 +8,6 @@ $INCFLAGS << " -I$(srcdir)/.." $objs = [ "sha2.#{$OBJEXT}", - "sha2hl.#{$OBJEXT}", "sha2init.#{$OBJEXT}", ] diff --git a/ext/digest/sha2/sha2.c b/ext/digest/sha2/sha2.c index 41ed2df106..1dd69c4e85 100644 --- a/ext/digest/sha2/sha2.c +++ b/ext/digest/sha2/sha2.c @@ -515,7 +515,7 @@ void SHA256_Update(SHA256_CTX* context, const sha2_byte *data, size_t len) { usedspace = freespace = 0; } -void SHA256_Final(sha2_byte digest[], SHA256_CTX* context) { +void SHA256_Finish(SHA256_CTX* context, sha2_byte digest[]) { sha2_word32 *d = (sha2_word32*)digest; unsigned int usedspace; @@ -852,7 +852,7 @@ void SHA512_Last(SHA512_CTX* context) { SHA512_Transform(context, (const sha2_word64*)context->buffer); } -void SHA512_Final(sha2_byte digest[], SHA512_CTX* context) { +void SHA512_Finish(SHA512_CTX* context, sha2_byte digest[]) { sha2_word64 *d = (sha2_word64*)digest; /* Sanity check: */ @@ -901,7 +901,7 @@ void SHA384_Update(SHA384_CTX* context, const sha2_byte* data, size_t len) { SHA512_Update((SHA512_CTX*)context, data, len); } -void SHA384_Final(sha2_byte digest[], SHA384_CTX* context) { +void SHA384_Finish(SHA384_CTX* context, sha2_byte digest[]) { sha2_word64 *d = (sha2_word64*)digest; /* Sanity check: */ diff --git a/ext/digest/sha2/sha2.h b/ext/digest/sha2/sha2.h index 4689ad93ce..db72cbbd3b 100644 --- a/ext/digest/sha2/sha2.h +++ b/ext/digest/sha2/sha2.h @@ -77,52 +77,34 @@ typedef SHA512_CTX SHA384_CTX; #ifdef RUBY #define SHA256_Init rb_Digest_SHA256_Init #define SHA256_Update rb_Digest_SHA256_Update -#define SHA256_Final rb_Digest_SHA256_Final -#define SHA256_End rb_Digest_SHA256_End -#define SHA256_Data rb_Digest_SHA256_Data -#define SHA256_File rb_Digest_SHA256_File +#define SHA256_Finish rb_Digest_SHA256_Finish #define SHA256_Equal rb_Digest_SHA256_Equal #define SHA384_Init rb_Digest_SHA384_Init #define SHA384_Update rb_Digest_SHA384_Update -#define SHA384_Final rb_Digest_SHA384_Final -#define SHA384_End rb_Digest_SHA384_End -#define SHA384_Data rb_Digest_SHA384_Data -#define SHA384_File rb_Digest_SHA384_File +#define SHA384_Finish rb_Digest_SHA384_Finish #define SHA384_Equal rb_Digest_SHA384_Equal #define SHA512_Init rb_Digest_SHA512_Init #define SHA512_Update rb_Digest_SHA512_Update -#define SHA512_Final rb_Digest_SHA512_Final -#define SHA512_End rb_Digest_SHA512_End -#define SHA512_Data rb_Digest_SHA512_Data -#define SHA512_File rb_Digest_SHA512_File +#define SHA512_Finish rb_Digest_SHA512_Finish #define SHA512_Equal rb_Digest_SHA512_Equal #endif /*** SHA-256/384/512 Function Prototypes ******************************/ void SHA256_Init _((SHA256_CTX *)); void SHA256_Update _((SHA256_CTX*, const uint8_t*, size_t)); -void SHA256_Final _((uint8_t[SHA256_DIGEST_LENGTH], SHA256_CTX*)); -char* SHA256_End _((SHA256_CTX*, char[SHA256_DIGEST_STRING_LENGTH])); -char* SHA256_Data _((const uint8_t*, size_t, char[SHA256_DIGEST_STRING_LENGTH])); -char *SHA256_File _((char *, char *)); +void SHA256_Finish _((SHA256_CTX*, uint8_t[SHA256_DIGEST_LENGTH])); int SHA256_Equal _((SHA256_CTX*, SHA256_CTX*)); void SHA384_Init _((SHA384_CTX*)); void SHA384_Update _((SHA384_CTX*, const uint8_t*, size_t)); -void SHA384_Final _((uint8_t[SHA384_DIGEST_LENGTH], SHA384_CTX*)); -char* SHA384_End _((SHA384_CTX*, char[SHA384_DIGEST_STRING_LENGTH])); -char* SHA384_Data _((const uint8_t*, size_t, char[SHA384_DIGEST_STRING_LENGTH])); -char *SHA384_File _((char *, char *)); +void SHA384_Finish _((SHA384_CTX*, uint8_t[SHA384_DIGEST_LENGTH])); int SHA384_Equal _((SHA384_CTX*, SHA384_CTX*)); void SHA512_Init _((SHA512_CTX*)); void SHA512_Update _((SHA512_CTX*, const uint8_t*, size_t)); -void SHA512_Final _((uint8_t[SHA512_DIGEST_LENGTH], SHA512_CTX*)); -char* SHA512_End _((SHA512_CTX*, char[SHA512_DIGEST_STRING_LENGTH])); -char* SHA512_Data _((const uint8_t*, size_t, char[SHA512_DIGEST_STRING_LENGTH])); -char *SHA512_File _((char *, char *)); +void SHA512_Finish _((SHA512_CTX*, uint8_t[SHA512_DIGEST_LENGTH])); int SHA512_Equal _((SHA512_CTX*, SHA512_CTX*)); #ifdef __cplusplus diff --git a/ext/digest/sha2/sha2hl.c b/ext/digest/sha2/sha2hl.c deleted file mode 100644 index 03fde538c3..0000000000 --- a/ext/digest/sha2/sha2hl.c +++ /dev/null @@ -1,252 +0,0 @@ -/* $NetBSD: sha2hl.c,v 1.1 2001/03/12 09:08:40 agc Exp $ */ -/* $RoughId: sha2hl.c,v 1.2 2001/07/13 19:49:10 knu Exp $ */ -/* $Id$ */ - -/* - * sha2hl.c - * This code includes some functions taken from sha2.c, hence the - * following licence reproduction. - * - * This code is not a verbatim copy, since some routines have been added, - * and some bugs have been fixed. - * - * Version 1.0.0beta1 - * - * Written by Aaron D. Gifford <me@aarongifford.com> - * - * Copyright 2000 Aaron D. Gifford. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) AND CONTRIBUTOR(S) ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTOR(S) BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - */ - -#include "sha2.h" - -#ifndef lint -/* __RCSID("$NetBSD: sha2hl.c,v 1.1 2001/03/12 09:08:40 agc Exp $"); */ -#endif /* not lint */ - -/* #include "namespace.h" */ - -#include <assert.h> -#include <errno.h> -#include <fcntl.h> -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#if defined(HAVE_UNISTD_H) -# include <unistd.h> -#endif - -#ifndef _DIAGASSERT -#define _DIAGASSERT(cond) assert(cond) -#endif - -/* - * Constant used by SHA256/384/512_End() functions for converting the - * digest to a readable hexadecimal character string: - */ -static const char sha2_hex_digits[] = "0123456789abcdef"; - -char * -SHA256_File(char *filename, char *buf) -{ - uint8_t buffer[BUFSIZ * 20]; - SHA256_CTX ctx; - int fd, num, oerrno; - - _DIAGASSERT(filename != NULL); - /* XXX: buf may be NULL ? */ - - SHA256_Init(&ctx); - - if ((fd = open(filename, O_RDONLY)) < 0) - return (0); - - while ((num = read(fd, buffer, sizeof(buffer))) > 0) - SHA256_Update(&ctx, buffer, (size_t) num); - - oerrno = errno; - close(fd); - errno = oerrno; - return (num < 0 ? 0 : SHA256_End(&ctx, buf)); -} - - -char * -SHA256_End(SHA256_CTX *ctx, char buffer[]) -{ - uint8_t digest[SHA256_DIGEST_LENGTH], *d = digest; - uint8_t *ret; - int i; - - /* Sanity check: */ - assert(ctx != NULL); - - if ((ret = buffer) != NULL) { - SHA256_Final(digest, ctx); - - for (i = 0; i < SHA256_DIGEST_LENGTH; i++) { - *buffer++ = sha2_hex_digits[(*d & 0xf0) >> 4]; - *buffer++ = sha2_hex_digits[*d & 0x0f]; - d++; - } - *buffer = (char) 0; - } else { - (void) memset(ctx, 0, sizeof(SHA256_CTX)); - } - (void) memset(digest, 0, SHA256_DIGEST_LENGTH); - return ret; -} - -char * -SHA256_Data(const uint8_t * data, size_t len, char *digest) -{ - SHA256_CTX ctx; - - SHA256_Init(&ctx); - SHA256_Update(&ctx, data, len); - return SHA256_End(&ctx, digest); -} - -char * -SHA384_File(char *filename, char *buf) -{ - SHA384_CTX ctx; - uint8_t buffer[BUFSIZ * 20]; - int fd, num, oerrno; - - _DIAGASSERT(filename != NULL); - /* XXX: buf may be NULL ? */ - - SHA384_Init(&ctx); - - if ((fd = open(filename, O_RDONLY)) < 0) - return (0); - - while ((num = read(fd, buffer, sizeof(buffer))) > 0) - SHA384_Update(&ctx, buffer, (size_t) num); - - oerrno = errno; - close(fd); - errno = oerrno; - return (num < 0 ? 0 : SHA384_End(&ctx, buf)); -} - -char * -SHA384_End(SHA384_CTX * ctx, char buffer[]) -{ - uint8_t digest[SHA384_DIGEST_LENGTH], *d = digest; - uint8_t *ret; - int i; - - /* Sanity check: */ - assert(ctx != NULL); - - if ((ret = buffer) != NULL) { - SHA384_Final(digest, ctx); - - for (i = 0; i < SHA384_DIGEST_LENGTH; i++) { - *buffer++ = sha2_hex_digits[(*d & 0xf0) >> 4]; - *buffer++ = sha2_hex_digits[*d & 0x0f]; - d++; - } - *buffer = (char) 0; - } else { - (void) memset(ctx, 0, sizeof(SHA384_CTX)); - } - (void) memset(digest, 0, SHA384_DIGEST_LENGTH); - return ret; -} - -char * -SHA384_Data(const uint8_t * data, size_t len, char *digest) -{ - SHA384_CTX ctx; - - SHA384_Init(&ctx); - SHA384_Update(&ctx, data, len); - return SHA384_End(&ctx, digest); -} - -char * -SHA512_File(char *filename, char *buf) -{ - SHA512_CTX ctx; - uint8_t buffer[BUFSIZ * 20]; - int fd, num, oerrno; - - _DIAGASSERT(filename != NULL); - /* XXX: buf may be NULL ? */ - - SHA512_Init(&ctx); - - if ((fd = open(filename, O_RDONLY)) < 0) - return (0); - - while ((num = read(fd, buffer, sizeof(buffer))) > 0) - SHA512_Update(&ctx, buffer, (size_t) num); - - oerrno = errno; - close(fd); - errno = oerrno; - return (num < 0 ? 0 : SHA512_End(&ctx, buf)); -} - -char * -SHA512_End(SHA512_CTX * ctx, char buffer[]) -{ - uint8_t digest[SHA512_DIGEST_LENGTH], *d = digest; - uint8_t *ret; - int i; - - /* Sanity check: */ - assert(ctx != NULL); - - if ((ret = buffer) != NULL) { - SHA512_Final(digest, ctx); - - for (i = 0; i < SHA512_DIGEST_LENGTH; i++) { - *buffer++ = sha2_hex_digits[(*d & 0xf0) >> 4]; - *buffer++ = sha2_hex_digits[*d & 0x0f]; - d++; - } - *buffer = (char) 0; - } else { - (void) memset(ctx, 0, sizeof(SHA512_CTX)); - } - (void) memset(digest, 0, SHA512_DIGEST_LENGTH); - return ret; -} - -char * -SHA512_Data(const uint8_t * data, size_t len, char *digest) -{ - SHA512_CTX ctx; - - SHA512_Init(&ctx); - SHA512_Update(&ctx, data, len); - return SHA512_End(&ctx, digest); -} diff --git a/ext/digest/sha2/sha2init.c b/ext/digest/sha2/sha2init.c index 27a2b7ee89..9484f2a7ba 100644 --- a/ext/digest/sha2/sha2init.c +++ b/ext/digest/sha2/sha2init.c @@ -12,8 +12,7 @@ static algo_t sha##bitlen = { \ sizeof(SHA##bitlen##_CTX), \ (hash_init_func_t)SHA##bitlen##_Init, \ (hash_update_func_t)SHA##bitlen##_Update, \ - (hash_end_func_t)SHA##bitlen##_End, \ - (hash_final_func_t)SHA##bitlen##_Final, \ + (hash_finish_func_t)SHA##bitlen##_Finish, \ (hash_equal_func_t)SHA##bitlen##_Equal, \ }; |