mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
9b616442e2
commit
b9673f64f1
28 changed files with 123 additions and 631 deletions
31
ChangeLog
31
ChangeLog
|
@ -1,3 +1,34 @@
|
||||||
|
Thu Oct 5 19:28:35 2006 Akinori MUSHA <knu@iDaemons.org>
|
||||||
|
|
||||||
|
* 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.
|
||||||
|
|
||||||
Wed Oct 4 18:47:25 2006 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
|
Wed Oct 4 18:47:25 2006 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
|
||||||
|
|
||||||
* ext/tk/lib/tkextlib/*: bugfix and update
|
* ext/tk/lib/tkextlib/*: bugfix and update
|
||||||
|
|
|
@ -39,6 +39,26 @@ get_digest_base_metadata(VALUE klass)
|
||||||
return algo;
|
return algo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
hexdigest_str_new(const unsigned char *digest, size_t digest_len)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
VALUE str;
|
||||||
|
char *p;
|
||||||
|
static const char hex[] = "0123456789abcdef";
|
||||||
|
|
||||||
|
str = rb_str_new(0, digest_len * 2);
|
||||||
|
|
||||||
|
for (i = 0, p = RSTRING_PTR(str); i < digest_len; i++) {
|
||||||
|
unsigned char byte = digest[i];
|
||||||
|
|
||||||
|
p[i + i] = hex[byte >> 4];
|
||||||
|
p[i + i + 1] = hex[byte & 0x0f];
|
||||||
|
}
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
rb_digest_base_alloc(VALUE klass)
|
rb_digest_base_alloc(VALUE klass)
|
||||||
{
|
{
|
||||||
|
@ -52,7 +72,7 @@ rb_digest_base_alloc(VALUE klass)
|
||||||
|
|
||||||
algo = get_digest_base_metadata(klass);
|
algo = get_digest_base_metadata(klass);
|
||||||
|
|
||||||
/* XXX: An uninitialized buffer leads ALGO_Equal() to fail */
|
/* XXX: An uninitialized buffer may lead ALGO_Equal() to fail */
|
||||||
pctx = xcalloc(algo->ctx_size, 1);
|
pctx = xcalloc(algo->ctx_size, 1);
|
||||||
algo->init_func(pctx);
|
algo->init_func(pctx);
|
||||||
|
|
||||||
|
@ -75,7 +95,7 @@ rb_digest_base_s_digest(VALUE klass, VALUE str)
|
||||||
algo->update_func(pctx, RSTRING_PTR(str), RSTRING_LEN(str));
|
algo->update_func(pctx, RSTRING_PTR(str), RSTRING_LEN(str));
|
||||||
|
|
||||||
str = rb_str_new(0, algo->digest_len);
|
str = rb_str_new(0, algo->digest_len);
|
||||||
algo->final_func(RSTRING_PTR(str), pctx);
|
algo->finish_func(pctx, RSTRING_PTR(str));
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
@ -85,6 +105,8 @@ rb_digest_base_s_hexdigest(VALUE klass, VALUE str)
|
||||||
{
|
{
|
||||||
algo_t *algo;
|
algo_t *algo;
|
||||||
void *pctx;
|
void *pctx;
|
||||||
|
void *digest;
|
||||||
|
size_t len;
|
||||||
volatile VALUE obj = rb_digest_base_alloc(klass);
|
volatile VALUE obj = rb_digest_base_alloc(klass);
|
||||||
|
|
||||||
algo = get_digest_base_metadata(klass);
|
algo = get_digest_base_metadata(klass);
|
||||||
|
@ -93,10 +115,11 @@ rb_digest_base_s_hexdigest(VALUE klass, VALUE str)
|
||||||
StringValue(str);
|
StringValue(str);
|
||||||
algo->update_func(pctx, RSTRING_PTR(str), RSTRING_LEN(str));
|
algo->update_func(pctx, RSTRING_PTR(str), RSTRING_LEN(str));
|
||||||
|
|
||||||
str = rb_str_new(0, algo->digest_len * 2);
|
len = algo->digest_len;
|
||||||
algo->end_func(pctx, RSTRING_PTR(str));
|
digest = xmalloc(len);
|
||||||
|
algo->finish_func(pctx, digest);
|
||||||
|
|
||||||
return str;
|
return hexdigest_str_new(digest, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
|
@ -150,19 +173,18 @@ rb_digest_base_digest(VALUE self)
|
||||||
{
|
{
|
||||||
algo_t *algo;
|
algo_t *algo;
|
||||||
void *pctx1, *pctx2;
|
void *pctx1, *pctx2;
|
||||||
size_t len;
|
size_t ctx_size;
|
||||||
VALUE str;
|
VALUE str;
|
||||||
|
|
||||||
algo = get_digest_base_metadata(rb_obj_class(self));
|
algo = get_digest_base_metadata(rb_obj_class(self));
|
||||||
Data_Get_Struct(self, void, pctx1);
|
Data_Get_Struct(self, void, pctx1);
|
||||||
|
|
||||||
|
ctx_size = algo->ctx_size;
|
||||||
|
pctx2 = xmalloc(ctx_size);
|
||||||
|
memcpy(pctx2, pctx1, ctx_size);
|
||||||
|
|
||||||
str = rb_str_new(0, algo->digest_len);
|
str = rb_str_new(0, algo->digest_len);
|
||||||
|
algo->finish_func(pctx2, RSTRING_PTR(str));
|
||||||
len = algo->ctx_size;
|
|
||||||
pctx2 = xmalloc(len);
|
|
||||||
memcpy(pctx2, pctx1, len);
|
|
||||||
|
|
||||||
algo->final_func(RSTRING_PTR(str), pctx2);
|
|
||||||
free(pctx2);
|
free(pctx2);
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
|
@ -173,22 +195,22 @@ rb_digest_base_hexdigest(VALUE self)
|
||||||
{
|
{
|
||||||
algo_t *algo;
|
algo_t *algo;
|
||||||
void *pctx1, *pctx2;
|
void *pctx1, *pctx2;
|
||||||
size_t len;
|
void *digest;
|
||||||
VALUE str;
|
size_t ctx_size, len;
|
||||||
|
|
||||||
algo = get_digest_base_metadata(rb_obj_class(self));
|
algo = get_digest_base_metadata(rb_obj_class(self));
|
||||||
Data_Get_Struct(self, void, pctx1);
|
Data_Get_Struct(self, void, pctx1);
|
||||||
|
|
||||||
str = rb_str_new(0, algo->digest_len * 2);
|
ctx_size = algo->ctx_size;
|
||||||
|
pctx2 = xmalloc(ctx_size);
|
||||||
|
memcpy(pctx2, pctx1, ctx_size);
|
||||||
|
|
||||||
len = algo->ctx_size;
|
len = algo->digest_len;
|
||||||
pctx2 = xmalloc(len);
|
digest = xmalloc(len);
|
||||||
memcpy(pctx2, pctx1, len);
|
algo->finish_func(pctx2, digest);
|
||||||
|
|
||||||
algo->end_func(pctx2, RSTRING_PTR(str));
|
|
||||||
free(pctx2);
|
free(pctx2);
|
||||||
|
|
||||||
return str;
|
return hexdigest_str_new(digest, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
|
|
|
@ -17,8 +17,7 @@
|
||||||
|
|
||||||
typedef void (*hash_init_func_t)(void *);
|
typedef void (*hash_init_func_t)(void *);
|
||||||
typedef void (*hash_update_func_t)(void *, unsigned char *, size_t);
|
typedef void (*hash_update_func_t)(void *, unsigned char *, size_t);
|
||||||
typedef void (*hash_end_func_t)(void *, unsigned char *);
|
typedef void (*hash_finish_func_t)(void *, unsigned char *);
|
||||||
typedef void (*hash_final_func_t)(unsigned char *, void *);
|
|
||||||
typedef int (*hash_equal_func_t)(void *, void *);
|
typedef int (*hash_equal_func_t)(void *, void *);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -26,7 +25,6 @@ typedef struct {
|
||||||
size_t ctx_size;
|
size_t ctx_size;
|
||||||
hash_init_func_t init_func;
|
hash_init_func_t init_func;
|
||||||
hash_update_func_t update_func;
|
hash_update_func_t update_func;
|
||||||
hash_end_func_t end_func;
|
hash_finish_func_t finish_func;
|
||||||
hash_final_func_t final_func;
|
|
||||||
hash_equal_func_t equal_func;
|
hash_equal_func_t equal_func;
|
||||||
} algo_t;
|
} algo_t;
|
||||||
|
|
|
@ -41,6 +41,12 @@
|
||||||
1999-05-03 lpd Original version.
|
1999-05-03 lpd Original version.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
This code was modified for use in Ruby.
|
||||||
|
|
||||||
|
- Akinori MUSHA <knu@idaemons.org>
|
||||||
|
*/
|
||||||
|
|
||||||
/*$OrigId: md5c.c,v 1.2 2001/03/26 08:57:14 matz Exp $ */
|
/*$OrigId: md5c.c,v 1.2 2001/03/26 08:57:14 matz Exp $ */
|
||||||
/*$RoughId: md5.c,v 1.2 2001/07/13 19:48:41 knu Exp $ */
|
/*$RoughId: md5.c,v 1.2 2001/07/13 19:48:41 knu Exp $ */
|
||||||
/*$Id$ */
|
/*$Id$ */
|
||||||
|
@ -391,7 +397,7 @@ MD5_Update(MD5_CTX *pms, const uint8_t *data, size_t nbytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
MD5_Final(uint8_t *digest, MD5_CTX *pms)
|
MD5_Finish(MD5_CTX *pms, uint8_t *digest)
|
||||||
{
|
{
|
||||||
static const uint8_t pad[64] = {
|
static const uint8_t pad[64] = {
|
||||||
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
@ -413,18 +419,6 @@ MD5_Final(uint8_t *digest, MD5_CTX *pms)
|
||||||
digest[i] = (uint8_t)(pms->state[i >> 2] >> ((i & 3) << 3));
|
digest[i] = (uint8_t)(pms->state[i >> 2] >> ((i & 3) << 3));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
MD5_End(MD5_CTX *pctx, uint8_t *hexdigest)
|
|
||||||
{
|
|
||||||
unsigned char digest[16];
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
MD5_Final(digest, pctx);
|
|
||||||
|
|
||||||
for (i = 0; i < 16; i++)
|
|
||||||
sprintf(hexdigest + i * 2, "%02x", digest[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
int MD5_Equal(MD5_CTX* pctx1, MD5_CTX* pctx2) {
|
int MD5_Equal(MD5_CTX* pctx1, MD5_CTX* pctx2) {
|
||||||
return memcmp(pctx1->count, pctx2->count, sizeof(pctx1->count)) == 0
|
return memcmp(pctx1->count, pctx2->count, sizeof(pctx1->count)) == 0
|
||||||
&& memcmp(pctx1->state, pctx2->state, sizeof(pctx1->state)) == 0
|
&& memcmp(pctx1->state, pctx2->state, sizeof(pctx1->state)) == 0
|
||||||
|
|
|
@ -63,17 +63,16 @@ typedef struct md5_state_s {
|
||||||
} MD5_CTX;
|
} MD5_CTX;
|
||||||
|
|
||||||
#ifdef RUBY
|
#ifdef RUBY
|
||||||
|
/* avoid name clash */
|
||||||
#define MD5_Init rb_Digest_MD5_Init
|
#define MD5_Init rb_Digest_MD5_Init
|
||||||
#define MD5_Update rb_Digest_MD5_Update
|
#define MD5_Update rb_Digest_MD5_Update
|
||||||
#define MD5_Final rb_Digest_MD5_Final
|
#define MD5_Finish rb_Digest_MD5_Finish
|
||||||
#define MD5_End rb_Digest_MD5_End
|
|
||||||
#define MD5_Equal rb_Digest_MD5_Equal
|
#define MD5_Equal rb_Digest_MD5_Equal
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void MD5_Init _((MD5_CTX *pms));
|
void MD5_Init _((MD5_CTX *pms));
|
||||||
void MD5_Update _((MD5_CTX *pms, const uint8_t *data, size_t nbytes));
|
void MD5_Update _((MD5_CTX *pms, const uint8_t *data, size_t nbytes));
|
||||||
void MD5_Final _((uint8_t *digest, MD5_CTX *pms));
|
void MD5_Finish _((MD5_CTX *pms, uint8_t *digest));
|
||||||
void MD5_End _((MD5_CTX *pctx, uint8_t *hexdigest));
|
|
||||||
int MD5_Equal _((MD5_CTX *pctx1, MD5_CTX *pctx2));
|
int MD5_Equal _((MD5_CTX *pctx1, MD5_CTX *pctx2));
|
||||||
|
|
||||||
#define MD5_BLOCK_LENGTH 64
|
#define MD5_BLOCK_LENGTH 64
|
||||||
|
|
|
@ -13,8 +13,7 @@ static algo_t md5 = {
|
||||||
sizeof(MD5_CTX),
|
sizeof(MD5_CTX),
|
||||||
(hash_init_func_t)MD5_Init,
|
(hash_init_func_t)MD5_Init,
|
||||||
(hash_update_func_t)MD5_Update,
|
(hash_update_func_t)MD5_Update,
|
||||||
(hash_end_func_t)MD5_End,
|
(hash_finish_func_t)MD5_Finish,
|
||||||
(hash_final_func_t)MD5_Final,
|
|
||||||
(hash_equal_func_t)MD5_Equal,
|
(hash_equal_func_t)MD5_Equal,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -6,15 +6,9 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
void
|
void
|
||||||
MD5_End(MD5_CTX *pctx, unsigned char *hexdigest)
|
MD5_Finish(MD5_CTX *pctx, unsigned char *digest)
|
||||||
{
|
{
|
||||||
unsigned char digest[16];
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
MD5_Final(digest, pctx);
|
MD5_Final(digest, pctx);
|
||||||
|
|
||||||
for (i = 0; i < 16; i++)
|
|
||||||
sprintf(hexdigest + i * 2, "%02x", digest[i]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <openssl/md5.h>
|
#include <openssl/md5.h>
|
||||||
|
|
||||||
void MD5_End(MD5_CTX *pctx, unsigned char *hexdigest);
|
void MD5_Finish(MD5_CTX *pctx, unsigned char *digest);
|
||||||
int MD5_Equal(MD5_CTX *pctx1, MD5_CTX *pctx2);
|
int MD5_Equal(MD5_CTX *pctx1, MD5_CTX *pctx2);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
rmd160.o: rmd160.c rmd160.h $(srcdir)/../defs.h $(hdrdir)/ruby.h \
|
rmd160.o: rmd160.c rmd160.h $(srcdir)/../defs.h $(hdrdir)/ruby.h \
|
||||||
$(topdir)/config.h $(hdrdir)/defines.h $(hdrdir)/intern.h
|
$(topdir)/config.h $(hdrdir)/defines.h $(hdrdir)/intern.h
|
||||||
rmd160hl.o: rmd160hl.c rmd160.h $(srcdir)/../defs.h $(hdrdir)/ruby.h \
|
|
||||||
$(topdir)/config.h $(hdrdir)/defines.h $(hdrdir)/intern.h
|
|
||||||
rmd160init.o: rmd160init.c $(srcdir)/../digest.h $(hdrdir)/ruby.h \
|
rmd160init.o: rmd160init.c $(srcdir)/../digest.h $(hdrdir)/ruby.h \
|
||||||
$(topdir)/config.h $(hdrdir)/defines.h $(hdrdir)/intern.h \
|
$(topdir)/config.h $(hdrdir)/defines.h $(hdrdir)/intern.h \
|
||||||
rmd160.h $(srcdir)/../defs.h
|
rmd160.h $(srcdir)/../defs.h
|
||||||
|
|
|
@ -14,7 +14,7 @@ if !with_config("bundled-rmd160") &&
|
||||||
have_library("crypto") && have_header("openssl/ripemd.h")
|
have_library("crypto") && have_header("openssl/ripemd.h")
|
||||||
$objs << "rmd160ossl.#{$OBJEXT}"
|
$objs << "rmd160ossl.#{$OBJEXT}"
|
||||||
else
|
else
|
||||||
$objs << "rmd160.#{$OBJEXT}" << "rmd160hl.#{$OBJEXT}"
|
$objs << "rmd160.#{$OBJEXT}"
|
||||||
end
|
end
|
||||||
|
|
||||||
have_header("sys/cdefs.h")
|
have_header("sys/cdefs.h")
|
||||||
|
|
|
@ -409,7 +409,7 @@ RMD160_Update(RMD160_CTX *context, const uint8_t *data, size_t nbytes)
|
||||||
/********************************************************************/
|
/********************************************************************/
|
||||||
|
|
||||||
void
|
void
|
||||||
RMD160_Final(uint8_t digest[20], RMD160_CTX *context)
|
RMD160_Finish(RMD160_CTX *context, uint8_t digest[20])
|
||||||
{
|
{
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
uint32_t X[16];
|
uint32_t X[16];
|
||||||
|
|
|
@ -39,26 +39,16 @@ typedef struct {
|
||||||
#define RMD160_Init rb_Digest_RMD160_Init
|
#define RMD160_Init rb_Digest_RMD160_Init
|
||||||
#define RMD160_Transform rb_Digest_RMD160_Transform
|
#define RMD160_Transform rb_Digest_RMD160_Transform
|
||||||
#define RMD160_Update rb_Digest_RMD160_Update
|
#define RMD160_Update rb_Digest_RMD160_Update
|
||||||
#define RMD160_Final rb_Digest_RMD160_Final
|
#define RMD160_Finish rb_Digest_RMD160_Finish
|
||||||
#define RMD160_Equal rb_Digest_RMD160_Equal
|
#define RMD160_Equal rb_Digest_RMD160_Equal
|
||||||
#ifndef _KERNEL
|
|
||||||
#define RMD160_End rb_Digest_RMD160_End
|
|
||||||
#define RMD160_File rb_Digest_RMD160_File
|
|
||||||
#define RMD160_Data rb_Digest_RMD160_Data
|
|
||||||
#endif /* _KERNEL */
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
__BEGIN_DECLS
|
__BEGIN_DECLS
|
||||||
void RMD160_Init _((RMD160_CTX *));
|
void RMD160_Init _((RMD160_CTX *));
|
||||||
void RMD160_Transform _((uint32_t[5], const uint32_t[16]));
|
void RMD160_Transform _((uint32_t[5], const uint32_t[16]));
|
||||||
void RMD160_Update _((RMD160_CTX *, const uint8_t *, size_t));
|
void RMD160_Update _((RMD160_CTX *, const uint8_t *, size_t));
|
||||||
void RMD160_Final _((uint8_t[20], RMD160_CTX *));
|
void RMD160_Finish _((RMD160_CTX *, uint8_t[20]));
|
||||||
int RMD160_Equal _((RMD160_CTX *, RMD160_CTX *));
|
int RMD160_Equal _((RMD160_CTX *, RMD160_CTX *));
|
||||||
#ifndef _KERNEL
|
|
||||||
char *RMD160_End _((RMD160_CTX *, char *));
|
|
||||||
char *RMD160_File _((char *, char *));
|
|
||||||
char *RMD160_Data _((const uint8_t *, size_t, char *));
|
|
||||||
#endif /* _KERNEL */
|
|
||||||
__END_DECLS
|
__END_DECLS
|
||||||
|
|
||||||
#define RMD160_BLOCK_LENGTH 64
|
#define RMD160_BLOCK_LENGTH 64
|
||||||
|
|
|
@ -1,96 +0,0 @@
|
||||||
/* $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
|
|
||||||
* ----------------------------------------------------------------------------
|
|
||||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
|
||||||
* <phk@login.dkuug.dk> 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 <assert.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#if defined(HAVE_UNISTD_H)
|
|
||||||
# include <unistd.h>
|
|
||||||
#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));
|
|
||||||
}
|
|
|
@ -13,8 +13,7 @@ static algo_t rmd160 = {
|
||||||
sizeof(RMD160_CTX),
|
sizeof(RMD160_CTX),
|
||||||
(hash_init_func_t)RMD160_Init,
|
(hash_init_func_t)RMD160_Init,
|
||||||
(hash_update_func_t)RMD160_Update,
|
(hash_update_func_t)RMD160_Update,
|
||||||
(hash_end_func_t)RMD160_End,
|
(hash_finish_func_t)RMD160_Finish,
|
||||||
(hash_final_func_t)RMD160_Final,
|
|
||||||
(hash_equal_func_t)RMD160_Equal,
|
(hash_equal_func_t)RMD160_Equal,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -5,31 +5,8 @@
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#ifndef _DIAGASSERT
|
void RMD160_Finish(RMD160_CTX *ctx, char *buf) {
|
||||||
#define _DIAGASSERT(cond) assert(cond)
|
RIPEMD160_Final(buf, ctx);
|
||||||
#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) {
|
int RMD160_Equal(RMD160_CTX* pctx1, RMD160_CTX* pctx2) {
|
||||||
|
|
|
@ -10,12 +10,11 @@
|
||||||
|
|
||||||
#define RMD160_Init RIPEMD160_Init
|
#define RMD160_Init RIPEMD160_Init
|
||||||
#define RMD160_Update RIPEMD160_Update
|
#define RMD160_Update RIPEMD160_Update
|
||||||
#define RMD160_Final RIPEMD160_Final
|
|
||||||
|
|
||||||
#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
|
||||||
|
|
||||||
char *RMD160_End(RMD160_CTX *ctx, char *buf);
|
void RMD160_Finish(RMD160_CTX *ctx, char *buf);
|
||||||
int RMD160_Equal(RMD160_CTX *pctx1, RMD160_CTX *pctx2);
|
int RMD160_Equal(RMD160_CTX *pctx1, RMD160_CTX *pctx2);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -14,7 +14,7 @@ if !with_config("bundled-sha1") &&
|
||||||
have_library("crypto") && have_header("openssl/sha.h")
|
have_library("crypto") && have_header("openssl/sha.h")
|
||||||
$objs << "sha1ossl.#{$OBJEXT}"
|
$objs << "sha1ossl.#{$OBJEXT}"
|
||||||
else
|
else
|
||||||
$objs << "sha1.#{$OBJEXT}" << "sha1hl.#{$OBJEXT}"
|
$objs << "sha1.#{$OBJEXT}"
|
||||||
end
|
end
|
||||||
|
|
||||||
have_header("sys/cdefs.h")
|
have_header("sys/cdefs.h")
|
||||||
|
|
|
@ -129,9 +129,7 @@ do_R4(uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d, uint32_t *e, CHAR64LON
|
||||||
/*
|
/*
|
||||||
* Hash a single 512-bit block. This is the core of the algorithm.
|
* Hash a single 512-bit block. This is the core of the algorithm.
|
||||||
*/
|
*/
|
||||||
void SHA1_Transform(state, buffer)
|
void SHA1_Transform(uint32_t state[5], const uint8_t buffer[64])
|
||||||
uint32_t state[5];
|
|
||||||
const uint8_t buffer[64];
|
|
||||||
{
|
{
|
||||||
uint32_t a, b, c, d, e;
|
uint32_t a, b, c, d, e;
|
||||||
CHAR64LONG16 *block;
|
CHAR64LONG16 *block;
|
||||||
|
@ -201,8 +199,7 @@ void SHA1_Transform(state, buffer)
|
||||||
/*
|
/*
|
||||||
* SHA1_Init - Initialize new context
|
* SHA1_Init - Initialize new context
|
||||||
*/
|
*/
|
||||||
void SHA1_Init(context)
|
void SHA1_Init(SHA1_CTX *context)
|
||||||
SHA1_CTX *context;
|
|
||||||
{
|
{
|
||||||
|
|
||||||
_DIAGASSERT(context != 0);
|
_DIAGASSERT(context != 0);
|
||||||
|
@ -220,10 +217,7 @@ void SHA1_Init(context)
|
||||||
/*
|
/*
|
||||||
* Run your data through this.
|
* Run your data through this.
|
||||||
*/
|
*/
|
||||||
void SHA1_Update(context, data, len)
|
void SHA1_Update(SHA1_CTX *context, const uint8_t *data, size_t len)
|
||||||
SHA1_CTX *context;
|
|
||||||
const uint8_t *data;
|
|
||||||
size_t len;
|
|
||||||
{
|
{
|
||||||
uint32_t i, j;
|
uint32_t i, j;
|
||||||
|
|
||||||
|
@ -250,9 +244,7 @@ void SHA1_Update(context, data, len)
|
||||||
/*
|
/*
|
||||||
* Add padding and return the message digest.
|
* Add padding and return the message digest.
|
||||||
*/
|
*/
|
||||||
void SHA1_Final(digest, context)
|
void SHA1_Finish(SHA1_CTX* context, uint8_t digest[20])
|
||||||
uint8_t digest[20];
|
|
||||||
SHA1_CTX* context;
|
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
uint8_t finalcount[8];
|
uint8_t finalcount[8];
|
||||||
|
|
|
@ -20,28 +20,19 @@ typedef struct {
|
||||||
} SHA1_CTX;
|
} SHA1_CTX;
|
||||||
|
|
||||||
#ifdef RUBY
|
#ifdef RUBY
|
||||||
|
/* avoid name clash */
|
||||||
#define SHA1_Transform rb_Digest_SHA1_Transform
|
#define SHA1_Transform rb_Digest_SHA1_Transform
|
||||||
#define SHA1_Init rb_Digest_SHA1_Init
|
#define SHA1_Init rb_Digest_SHA1_Init
|
||||||
#define SHA1_Update rb_Digest_SHA1_Update
|
#define SHA1_Update rb_Digest_SHA1_Update
|
||||||
#define SHA1_Final rb_Digest_SHA1_Final
|
#define SHA1_Finish rb_Digest_SHA1_Finish
|
||||||
#define SHA1_Equal rb_Digest_SHA1_Equal
|
#define SHA1_Equal rb_Digest_SHA1_Equal
|
||||||
#ifndef _KERNEL
|
|
||||||
#define SHA1_End rb_Digest_SHA1_End
|
|
||||||
#define SHA1_File rb_Digest_SHA1_File
|
|
||||||
#define SHA1_Data rb_Digest_SHA1_Data
|
|
||||||
#endif /* _KERNEL */
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void SHA1_Transform _((uint32_t state[5], const uint8_t buffer[64]));
|
void SHA1_Transform _((uint32_t state[5], const uint8_t buffer[64]));
|
||||||
void SHA1_Init _((SHA1_CTX *context));
|
void SHA1_Init _((SHA1_CTX *context));
|
||||||
void SHA1_Update _((SHA1_CTX *context, const uint8_t *data, size_t len));
|
void SHA1_Update _((SHA1_CTX *context, const uint8_t *data, size_t len));
|
||||||
void SHA1_Final _((uint8_t digest[20], SHA1_CTX *context));
|
void SHA1_Finish _((SHA1_CTX *context, uint8_t digest[20]));
|
||||||
int SHA1_Equal _((SHA1_CTX *pctx1, SHA1_CTX *pctx2));
|
int SHA1_Equal _((SHA1_CTX *pctx1, SHA1_CTX *pctx2));
|
||||||
#ifndef _KERNEL
|
|
||||||
char *SHA1_End _((SHA1_CTX *, char *));
|
|
||||||
char *SHA1_File _((char *, char *));
|
|
||||||
char *SHA1_Data _((const uint8_t *, size_t, char *));
|
|
||||||
#endif /* _KERNEL */
|
|
||||||
|
|
||||||
#define SHA1_BLOCK_LENGTH 64
|
#define SHA1_BLOCK_LENGTH 64
|
||||||
#define SHA1_DIGEST_LENGTH 20
|
#define SHA1_DIGEST_LENGTH 20
|
||||||
|
|
|
@ -1,102 +0,0 @@
|
||||||
/* $NetBSD: sha1hl.c,v 1.2 2001/03/10 15:55:14 tron Exp $ */
|
|
||||||
/* $RoughId: sha1hl.c,v 1.2 2001/07/13 19:49:10 knu Exp $ */
|
|
||||||
/* $Id$ */
|
|
||||||
|
|
||||||
/* sha1hl.c
|
|
||||||
* ----------------------------------------------------------------------------
|
|
||||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
|
||||||
* <phk@login.dkuug.dk> 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
|
|
||||||
* ----------------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* #include "namespace.h" */
|
|
||||||
|
|
||||||
#include "sha1.h"
|
|
||||||
#include <fcntl.h>
|
|
||||||
|
|
||||||
#include <assert.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#if defined(HAVE_UNISTD_H)
|
|
||||||
# include <unistd.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(LIBC_SCCS) && !defined(lint)
|
|
||||||
/* __RCSID("$NetBSD: sha1hl.c,v 1.2 2001/03/10 15:55:14 tron Exp $"); */
|
|
||||||
#endif /* LIBC_SCCS and not lint */
|
|
||||||
|
|
||||||
#ifndef _DIAGASSERT
|
|
||||||
#define _DIAGASSERT(cond) assert(cond)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/* ARGSUSED */
|
|
||||||
char *
|
|
||||||
SHA1_End(ctx, buf)
|
|
||||||
SHA1_CTX *ctx;
|
|
||||||
char *buf;
|
|
||||||
{
|
|
||||||
int 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;
|
|
||||||
|
|
||||||
SHA1_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 *
|
|
||||||
SHA1_File (filename, buf)
|
|
||||||
char *filename;
|
|
||||||
char *buf;
|
|
||||||
{
|
|
||||||
uint8_t buffer[BUFSIZ];
|
|
||||||
SHA1_CTX ctx;
|
|
||||||
int fd, num, oerrno;
|
|
||||||
|
|
||||||
_DIAGASSERT(filename != NULL);
|
|
||||||
/* XXX: buf may be NULL ? */
|
|
||||||
|
|
||||||
SHA1_Init(&ctx);
|
|
||||||
|
|
||||||
if ((fd = open(filename,O_RDONLY)) < 0)
|
|
||||||
return(0);
|
|
||||||
|
|
||||||
while ((num = read(fd, buffer, sizeof(buffer))) > 0)
|
|
||||||
SHA1_Update(&ctx, buffer, (size_t)num);
|
|
||||||
|
|
||||||
oerrno = errno;
|
|
||||||
close(fd);
|
|
||||||
errno = oerrno;
|
|
||||||
return(num < 0 ? 0 : SHA1_End(&ctx, buf));
|
|
||||||
}
|
|
||||||
|
|
||||||
char *
|
|
||||||
SHA1_Data (data, len, buf)
|
|
||||||
const uint8_t *data;
|
|
||||||
size_t len;
|
|
||||||
char *buf;
|
|
||||||
{
|
|
||||||
SHA1_CTX ctx;
|
|
||||||
|
|
||||||
_DIAGASSERT(data != NULL);
|
|
||||||
/* XXX: buf may be NULL ? */
|
|
||||||
|
|
||||||
SHA1_Init(&ctx);
|
|
||||||
SHA1_Update(&ctx, data, len);
|
|
||||||
return(SHA1_End(&ctx, buf));
|
|
||||||
}
|
|
|
@ -13,8 +13,7 @@ static algo_t sha1 = {
|
||||||
sizeof(SHA1_CTX),
|
sizeof(SHA1_CTX),
|
||||||
(hash_init_func_t)SHA1_Init,
|
(hash_init_func_t)SHA1_Init,
|
||||||
(hash_update_func_t)SHA1_Update,
|
(hash_update_func_t)SHA1_Update,
|
||||||
(hash_end_func_t)SHA1_End,
|
(hash_finish_func_t)SHA1_Finish,
|
||||||
(hash_final_func_t)SHA1_Final,
|
|
||||||
(hash_equal_func_t)SHA1_Equal,
|
(hash_equal_func_t)SHA1_Equal,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -2,37 +2,17 @@
|
||||||
|
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
#include "sha1ossl.h"
|
#include "sha1ossl.h"
|
||||||
#include <assert.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#ifndef _DIAGASSERT
|
void
|
||||||
#define _DIAGASSERT(cond) assert(cond)
|
SHA1_Finish(SHA1_CTX *ctx, char *buf)
|
||||||
#endif
|
|
||||||
|
|
||||||
char *
|
|
||||||
SHA1_End(SHA1_CTX *ctx, char *buf)
|
|
||||||
{
|
{
|
||||||
int i;
|
SHA1_Final(buf, ctx);
|
||||||
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;
|
|
||||||
|
|
||||||
SHA1_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 SHA1_Equal(SHA1_CTX* pctx1, SHA1_CTX* pctx2) {
|
int
|
||||||
|
SHA1_Equal(SHA1_CTX* pctx1, SHA1_CTX* pctx2)
|
||||||
|
{
|
||||||
return pctx1->num == pctx2->num
|
return pctx1->num == pctx2->num
|
||||||
&& pctx1->h0 == pctx2->h0
|
&& pctx1->h0 == pctx2->h0
|
||||||
&& pctx1->h1 == pctx2->h1
|
&& pctx1->h1 == pctx2->h1
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
#define SHA1_BLOCK_LENGTH SHA_BLOCK_LENGTH
|
#define SHA1_BLOCK_LENGTH SHA_BLOCK_LENGTH
|
||||||
#define SHA1_DIGEST_LENGTH SHA_DIGEST_LENGTH
|
#define SHA1_DIGEST_LENGTH SHA_DIGEST_LENGTH
|
||||||
|
|
||||||
char *SHA1_End(SHA1_CTX *ctx, char *buf);
|
void SHA1_Finish(SHA1_CTX *ctx, char *buf);
|
||||||
int SHA1_Equal(SHA1_CTX *pctx1, SHA1_CTX *pctx2);
|
int SHA1_Equal(SHA1_CTX *pctx1, SHA1_CTX *pctx2);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -8,7 +8,6 @@ $INCFLAGS << " -I$(srcdir)/.."
|
||||||
|
|
||||||
$objs = [
|
$objs = [
|
||||||
"sha2.#{$OBJEXT}",
|
"sha2.#{$OBJEXT}",
|
||||||
"sha2hl.#{$OBJEXT}",
|
|
||||||
"sha2init.#{$OBJEXT}",
|
"sha2init.#{$OBJEXT}",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -515,7 +515,7 @@ void SHA256_Update(SHA256_CTX* context, const sha2_byte *data, size_t len) {
|
||||||
usedspace = freespace = 0;
|
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;
|
sha2_word32 *d = (sha2_word32*)digest;
|
||||||
unsigned int usedspace;
|
unsigned int usedspace;
|
||||||
|
|
||||||
|
@ -852,7 +852,7 @@ void SHA512_Last(SHA512_CTX* context) {
|
||||||
SHA512_Transform(context, (const sha2_word64*)context->buffer);
|
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;
|
sha2_word64 *d = (sha2_word64*)digest;
|
||||||
|
|
||||||
/* Sanity check: */
|
/* 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);
|
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;
|
sha2_word64 *d = (sha2_word64*)digest;
|
||||||
|
|
||||||
/* Sanity check: */
|
/* Sanity check: */
|
||||||
|
|
|
@ -77,52 +77,34 @@ typedef SHA512_CTX SHA384_CTX;
|
||||||
#ifdef RUBY
|
#ifdef RUBY
|
||||||
#define SHA256_Init rb_Digest_SHA256_Init
|
#define SHA256_Init rb_Digest_SHA256_Init
|
||||||
#define SHA256_Update rb_Digest_SHA256_Update
|
#define SHA256_Update rb_Digest_SHA256_Update
|
||||||
#define SHA256_Final rb_Digest_SHA256_Final
|
#define SHA256_Finish rb_Digest_SHA256_Finish
|
||||||
#define SHA256_End rb_Digest_SHA256_End
|
|
||||||
#define SHA256_Data rb_Digest_SHA256_Data
|
|
||||||
#define SHA256_File rb_Digest_SHA256_File
|
|
||||||
#define SHA256_Equal rb_Digest_SHA256_Equal
|
#define SHA256_Equal rb_Digest_SHA256_Equal
|
||||||
|
|
||||||
#define SHA384_Init rb_Digest_SHA384_Init
|
#define SHA384_Init rb_Digest_SHA384_Init
|
||||||
#define SHA384_Update rb_Digest_SHA384_Update
|
#define SHA384_Update rb_Digest_SHA384_Update
|
||||||
#define SHA384_Final rb_Digest_SHA384_Final
|
#define SHA384_Finish rb_Digest_SHA384_Finish
|
||||||
#define SHA384_End rb_Digest_SHA384_End
|
|
||||||
#define SHA384_Data rb_Digest_SHA384_Data
|
|
||||||
#define SHA384_File rb_Digest_SHA384_File
|
|
||||||
#define SHA384_Equal rb_Digest_SHA384_Equal
|
#define SHA384_Equal rb_Digest_SHA384_Equal
|
||||||
|
|
||||||
#define SHA512_Init rb_Digest_SHA512_Init
|
#define SHA512_Init rb_Digest_SHA512_Init
|
||||||
#define SHA512_Update rb_Digest_SHA512_Update
|
#define SHA512_Update rb_Digest_SHA512_Update
|
||||||
#define SHA512_Final rb_Digest_SHA512_Final
|
#define SHA512_Finish rb_Digest_SHA512_Finish
|
||||||
#define SHA512_End rb_Digest_SHA512_End
|
|
||||||
#define SHA512_Data rb_Digest_SHA512_Data
|
|
||||||
#define SHA512_File rb_Digest_SHA512_File
|
|
||||||
#define SHA512_Equal rb_Digest_SHA512_Equal
|
#define SHA512_Equal rb_Digest_SHA512_Equal
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*** SHA-256/384/512 Function Prototypes ******************************/
|
/*** SHA-256/384/512 Function Prototypes ******************************/
|
||||||
void SHA256_Init _((SHA256_CTX *));
|
void SHA256_Init _((SHA256_CTX *));
|
||||||
void SHA256_Update _((SHA256_CTX*, const uint8_t*, size_t));
|
void SHA256_Update _((SHA256_CTX*, const uint8_t*, size_t));
|
||||||
void SHA256_Final _((uint8_t[SHA256_DIGEST_LENGTH], SHA256_CTX*));
|
void SHA256_Finish _((SHA256_CTX*, uint8_t[SHA256_DIGEST_LENGTH]));
|
||||||
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 *));
|
|
||||||
int SHA256_Equal _((SHA256_CTX*, SHA256_CTX*));
|
int SHA256_Equal _((SHA256_CTX*, SHA256_CTX*));
|
||||||
|
|
||||||
void SHA384_Init _((SHA384_CTX*));
|
void SHA384_Init _((SHA384_CTX*));
|
||||||
void SHA384_Update _((SHA384_CTX*, const uint8_t*, size_t));
|
void SHA384_Update _((SHA384_CTX*, const uint8_t*, size_t));
|
||||||
void SHA384_Final _((uint8_t[SHA384_DIGEST_LENGTH], SHA384_CTX*));
|
void SHA384_Finish _((SHA384_CTX*, uint8_t[SHA384_DIGEST_LENGTH]));
|
||||||
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 *));
|
|
||||||
int SHA384_Equal _((SHA384_CTX*, SHA384_CTX*));
|
int SHA384_Equal _((SHA384_CTX*, SHA384_CTX*));
|
||||||
|
|
||||||
void SHA512_Init _((SHA512_CTX*));
|
void SHA512_Init _((SHA512_CTX*));
|
||||||
void SHA512_Update _((SHA512_CTX*, const uint8_t*, size_t));
|
void SHA512_Update _((SHA512_CTX*, const uint8_t*, size_t));
|
||||||
void SHA512_Final _((uint8_t[SHA512_DIGEST_LENGTH], SHA512_CTX*));
|
void SHA512_Finish _((SHA512_CTX*, uint8_t[SHA512_DIGEST_LENGTH]));
|
||||||
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 *));
|
|
||||||
int SHA512_Equal _((SHA512_CTX*, SHA512_CTX*));
|
int SHA512_Equal _((SHA512_CTX*, SHA512_CTX*));
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -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);
|
|
||||||
}
|
|
|
@ -12,8 +12,7 @@ static algo_t sha##bitlen = { \
|
||||||
sizeof(SHA##bitlen##_CTX), \
|
sizeof(SHA##bitlen##_CTX), \
|
||||||
(hash_init_func_t)SHA##bitlen##_Init, \
|
(hash_init_func_t)SHA##bitlen##_Init, \
|
||||||
(hash_update_func_t)SHA##bitlen##_Update, \
|
(hash_update_func_t)SHA##bitlen##_Update, \
|
||||||
(hash_end_func_t)SHA##bitlen##_End, \
|
(hash_finish_func_t)SHA##bitlen##_Finish, \
|
||||||
(hash_final_func_t)SHA##bitlen##_Final, \
|
|
||||||
(hash_equal_func_t)SHA##bitlen##_Equal, \
|
(hash_equal_func_t)SHA##bitlen##_Equal, \
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue