summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-10-11 12:43:58 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-10-11 12:43:58 +0000
commit945a76d97b00f9c0d24b6d14da86b18284316000 (patch)
tree081ca1d78f2303a682f338b2605a2da30d19b96f /ext
parent76f721470b854fca0139f8aeab472341aade62c9 (diff)
* ext/digest/digest.c (rb_digest_base_alloc,
rb_digest_base_equal): Simplify the equality check and just compare resulted digests since state-level equality should not be significant. * ext/digest/digest.h: Ditto. * ext/digest/*/*.[ch]: Ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11131 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/digest/digest.c32
-rw-r--r--ext/digest/digest.h2
-rw-r--r--ext/digest/md5/md5.c6
-rw-r--r--ext/digest/md5/md5.h2
-rw-r--r--ext/digest/md5/md5init.c1
-rw-r--r--ext/digest/md5/md5ossl.c15
-rw-r--r--ext/digest/md5/md5ossl.h1
-rw-r--r--ext/digest/rmd160/rmd160.c7
-rw-r--r--ext/digest/rmd160/rmd160.h2
-rw-r--r--ext/digest/rmd160/rmd160init.c1
-rw-r--r--ext/digest/rmd160/rmd160ossl.c14
-rw-r--r--ext/digest/rmd160/rmd160ossl.h1
-rw-r--r--ext/digest/sha1/sha1.c6
-rw-r--r--ext/digest/sha1/sha1.h2
-rw-r--r--ext/digest/sha1/sha1init.c1
-rw-r--r--ext/digest/sha1/sha1ossl.c15
-rw-r--r--ext/digest/sha1/sha1ossl.h1
-rw-r--r--ext/digest/sha2/sha2.c18
-rw-r--r--ext/digest/sha2/sha2.h6
-rw-r--r--ext/digest/sha2/sha2init.c1
20 files changed, 14 insertions, 120 deletions
diff --git a/ext/digest/digest.c b/ext/digest/digest.c
index d95f8a6..dd78739 100644
--- a/ext/digest/digest.c
+++ b/ext/digest/digest.c
@@ -151,8 +151,7 @@ rb_digest_base_alloc(VALUE klass)
return Data_Wrap_Struct(klass, 0, free, 0);
}
- /* XXX: An uninitialized buffer may lead ALGO_Equal() to fail */
- pctx = xcalloc(algo->ctx_size, 1);
+ pctx = xmalloc(algo->ctx_size);
algo->init_func(pctx);
obj = Data_Wrap_Struct(klass, 0, free, pctx);
@@ -208,7 +207,7 @@ rb_digest_base_copy(VALUE copy, VALUE obj)
algo = get_digest_base_metadata(rb_obj_class(copy));
if (algo == NULL) {
- /* subclasses must define initialize_copy() */
+ /* initialize_copy() is undefined or something */
rb_notimplement();
}
@@ -375,25 +374,22 @@ rb_digest_base_equal(VALUE self, VALUE other)
VALUE str1, str2;
klass = rb_obj_class(self);
- algo = get_digest_base_metadata(klass);
if (rb_obj_class(other) == klass) {
- void *pctx1, *pctx2;
-
- Data_Get_Struct(self, void, pctx1);
- Data_Get_Struct(other, void, pctx2);
-
- return algo->equal_func(pctx1, pctx2) ? Qtrue : Qfalse;
+ str1 = rb_digest_base_digest(self);
+ str2 = rb_digest_base_digest(other);
+ } else {
+ StringValue(other);
+ str2 = other;
+
+ algo = get_digest_base_metadata(klass);
+
+ if (RSTRING_LEN(str2) == algo->digest_len)
+ str1 = rb_digest_base_digest(self);
+ else
+ str1 = rb_digest_base_hexdigest(self);
}
- StringValue(other);
- str2 = other;
-
- if (RSTRING_LEN(str2) == algo->digest_len)
- str1 = rb_digest_base_digest(self);
- else
- str1 = rb_digest_base_hexdigest(self);
-
if (RSTRING_LEN(str1) == RSTRING_LEN(str2)
&& rb_str_cmp(str1, str2) == 0)
return Qtrue;
diff --git a/ext/digest/digest.h b/ext/digest/digest.h
index 98aa87c..ee3c680 100644
--- a/ext/digest/digest.h
+++ b/ext/digest/digest.h
@@ -18,7 +18,6 @@
typedef void (*hash_init_func_t)(void *);
typedef void (*hash_update_func_t)(void *, unsigned char *, size_t);
typedef void (*hash_finish_func_t)(void *, unsigned char *);
-typedef int (*hash_equal_func_t)(void *, void *);
typedef struct {
size_t digest_len;
@@ -26,5 +25,4 @@ typedef struct {
hash_init_func_t init_func;
hash_update_func_t update_func;
hash_finish_func_t finish_func;
- hash_equal_func_t equal_func;
} algo_t;
diff --git a/ext/digest/md5/md5.c b/ext/digest/md5/md5.c
index 8f49476..993bc47 100644
--- a/ext/digest/md5/md5.c
+++ b/ext/digest/md5/md5.c
@@ -418,9 +418,3 @@ MD5_Finish(MD5_CTX *pms, uint8_t *digest)
for (i = 0; i < 16; ++i)
digest[i] = (uint8_t)(pms->state[i >> 2] >> ((i & 3) << 3));
}
-
-int MD5_Equal(MD5_CTX* pctx1, MD5_CTX* pctx2) {
- return memcmp(pctx1->count, pctx2->count, sizeof(pctx1->count)) == 0
- && memcmp(pctx1->state, pctx2->state, sizeof(pctx1->state)) == 0
- && memcmp(pctx1->buffer, pctx2->buffer, sizeof(pctx1->buffer)) == 0;
-}
diff --git a/ext/digest/md5/md5.h b/ext/digest/md5/md5.h
index a5de6fd..f4580ef 100644
--- a/ext/digest/md5/md5.h
+++ b/ext/digest/md5/md5.h
@@ -67,13 +67,11 @@ typedef struct md5_state_s {
#define MD5_Init rb_Digest_MD5_Init
#define MD5_Update rb_Digest_MD5_Update
#define MD5_Finish rb_Digest_MD5_Finish
-#define MD5_Equal rb_Digest_MD5_Equal
#endif
void MD5_Init _((MD5_CTX *pms));
void MD5_Update _((MD5_CTX *pms, const uint8_t *data, size_t nbytes));
void MD5_Finish _((MD5_CTX *pms, uint8_t *digest));
-int MD5_Equal _((MD5_CTX *pctx1, MD5_CTX *pctx2));
#define MD5_BLOCK_LENGTH 64
#define MD5_DIGEST_LENGTH 16
diff --git a/ext/digest/md5/md5init.c b/ext/digest/md5/md5init.c
index 4dc0c3b..781e8ea 100644
--- a/ext/digest/md5/md5init.c
+++ b/ext/digest/md5/md5init.c
@@ -14,7 +14,6 @@ static algo_t md5 = {
(hash_init_func_t)MD5_Init,
(hash_update_func_t)MD5_Update,
(hash_finish_func_t)MD5_Finish,
- (hash_equal_func_t)MD5_Equal,
};
void
diff --git a/ext/digest/md5/md5ossl.c b/ext/digest/md5/md5ossl.c
index 963243c..d94ae2c 100644
--- a/ext/digest/md5/md5ossl.c
+++ b/ext/digest/md5/md5ossl.c
@@ -1,24 +1,9 @@
/* $Id$ */
#include "md5ossl.h"
-#include <sys/types.h>
-#include <stdio.h>
-#include <string.h>
void
MD5_Finish(MD5_CTX *pctx, unsigned char *digest)
{
MD5_Final(digest, pctx);
}
-
-int
-MD5_Equal(MD5_CTX* pctx1, MD5_CTX* pctx2) {
- return pctx1->num == pctx2->num
- && pctx1->A == pctx2->A
- && pctx1->B == pctx2->B
- && pctx1->C == pctx2->C
- && pctx1->D == pctx2->D
- && pctx1->Nl == pctx2->Nl
- && pctx1->Nh == pctx2->Nh
- && memcmp(pctx1->data, pctx2->data, sizeof(pctx1->data)) == 0;
-}
diff --git a/ext/digest/md5/md5ossl.h b/ext/digest/md5/md5ossl.h
index ec629c5..1680c4f 100644
--- a/ext/digest/md5/md5ossl.h
+++ b/ext/digest/md5/md5ossl.h
@@ -9,6 +9,5 @@
#define MD5_BLOCK_LENGTH MD5_CBLOCK
void MD5_Finish(MD5_CTX *pctx, unsigned char *digest);
-int MD5_Equal(MD5_CTX *pctx1, MD5_CTX *pctx2);
#endif
diff --git a/ext/digest/rmd160/rmd160.c b/ext/digest/rmd160/rmd160.c
index 64ec0fb..8891872 100644
--- a/ext/digest/rmd160/rmd160.c
+++ b/ext/digest/rmd160/rmd160.c
@@ -454,11 +454,4 @@ RMD160_Finish(RMD160_CTX *context, uint8_t digest[20])
}
}
-int RMD160_Equal(RMD160_CTX* pctx1, RMD160_CTX* pctx2) {
- return pctx1->buflen == pctx2->buflen
- && memcmp(pctx1->length, pctx2->length, sizeof(pctx1->length)) == 0
- && memcmp(pctx1->state, pctx2->state, sizeof(pctx1->state)) == 0
- && memcmp(pctx1->bbuffer, pctx2->bbuffer, sizeof(pctx1->bbuffer)) == 0;
-}
-
/************************ end of file rmd160.c **********************/
diff --git a/ext/digest/rmd160/rmd160.h b/ext/digest/rmd160/rmd160.h
index ac52fb0..54d1ca9 100644
--- a/ext/digest/rmd160/rmd160.h
+++ b/ext/digest/rmd160/rmd160.h
@@ -40,7 +40,6 @@ typedef struct {
#define RMD160_Transform rb_Digest_RMD160_Transform
#define RMD160_Update rb_Digest_RMD160_Update
#define RMD160_Finish rb_Digest_RMD160_Finish
-#define RMD160_Equal rb_Digest_RMD160_Equal
#endif
__BEGIN_DECLS
@@ -48,7 +47,6 @@ void RMD160_Init _((RMD160_CTX *));
void RMD160_Transform _((uint32_t[5], const uint32_t[16]));
void RMD160_Update _((RMD160_CTX *, const uint8_t *, size_t));
void RMD160_Finish _((RMD160_CTX *, uint8_t[20]));
-int RMD160_Equal _((RMD160_CTX *, RMD160_CTX *));
__END_DECLS
#define RMD160_BLOCK_LENGTH 64
diff --git a/ext/digest/rmd160/rmd160init.c b/ext/digest/rmd160/rmd160init.c
index 08f3f1f..8967567 100644
--- a/ext/digest/rmd160/rmd160init.c
+++ b/ext/digest/rmd160/rmd160init.c
@@ -14,7 +14,6 @@ static algo_t rmd160 = {
(hash_init_func_t)RMD160_Init,
(hash_update_func_t)RMD160_Update,
(hash_finish_func_t)RMD160_Finish,
- (hash_equal_func_t)RMD160_Equal,
};
void
diff --git a/ext/digest/rmd160/rmd160ossl.c b/ext/digest/rmd160/rmd160ossl.c
index 247fd04..5d8c5ba 100644
--- a/ext/digest/rmd160/rmd160ossl.c
+++ b/ext/digest/rmd160/rmd160ossl.c
@@ -2,21 +2,7 @@
#include "defs.h"
#include "rmd160ossl.h"
-#include <assert.h>
-#include <stdlib.h>
void RMD160_Finish(RMD160_CTX *ctx, char *buf) {
RIPEMD160_Final(buf, ctx);
}
-
-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;
-}
diff --git a/ext/digest/rmd160/rmd160ossl.h b/ext/digest/rmd160/rmd160ossl.h
index ea6bd57..3df38a0 100644
--- a/ext/digest/rmd160/rmd160ossl.h
+++ b/ext/digest/rmd160/rmd160ossl.h
@@ -15,6 +15,5 @@
#define RMD160_DIGEST_LENGTH RIPEMD160_DIGEST_LENGTH
void RMD160_Finish(RMD160_CTX *ctx, char *buf);
-int RMD160_Equal(RMD160_CTX *pctx1, RMD160_CTX *pctx2);
#endif
diff --git a/ext/digest/sha1/sha1.c b/ext/digest/sha1/sha1.c
index 6545744..6196ca6 100644
--- a/ext/digest/sha1/sha1.c
+++ b/ext/digest/sha1/sha1.c
@@ -267,9 +267,3 @@ void SHA1_Finish(SHA1_CTX* context, uint8_t digest[20])
((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255);
}
}
-
-int SHA1_Equal(SHA1_CTX* pctx1, SHA1_CTX* pctx2) {
- return memcmp(pctx1->count, pctx2->count, sizeof(pctx1->count)) == 0
- && memcmp(pctx1->state, pctx2->state, sizeof(pctx1->state)) == 0
- && memcmp(pctx1->buffer, pctx2->buffer, sizeof(pctx1->buffer)) == 0;
-}
diff --git a/ext/digest/sha1/sha1.h b/ext/digest/sha1/sha1.h
index c9f8456..60e3b01 100644
--- a/ext/digest/sha1/sha1.h
+++ b/ext/digest/sha1/sha1.h
@@ -25,14 +25,12 @@ typedef struct {
#define SHA1_Init rb_Digest_SHA1_Init
#define SHA1_Update rb_Digest_SHA1_Update
#define SHA1_Finish rb_Digest_SHA1_Finish
-#define SHA1_Equal rb_Digest_SHA1_Equal
#endif
void SHA1_Transform _((uint32_t state[5], const uint8_t buffer[64]));
void SHA1_Init _((SHA1_CTX *context));
void SHA1_Update _((SHA1_CTX *context, const uint8_t *data, size_t len));
void SHA1_Finish _((SHA1_CTX *context, uint8_t digest[20]));
-int SHA1_Equal _((SHA1_CTX *pctx1, SHA1_CTX *pctx2));
#define SHA1_BLOCK_LENGTH 64
#define SHA1_DIGEST_LENGTH 20
diff --git a/ext/digest/sha1/sha1init.c b/ext/digest/sha1/sha1init.c
index 8a132e4..bd92c59 100644
--- a/ext/digest/sha1/sha1init.c
+++ b/ext/digest/sha1/sha1init.c
@@ -14,7 +14,6 @@ static algo_t sha1 = {
(hash_init_func_t)SHA1_Init,
(hash_update_func_t)SHA1_Update,
(hash_finish_func_t)SHA1_Finish,
- (hash_equal_func_t)SHA1_Equal,
};
void
diff --git a/ext/digest/sha1/sha1ossl.c b/ext/digest/sha1/sha1ossl.c
index 96365c7..adf5cf2 100644
--- a/ext/digest/sha1/sha1ossl.c
+++ b/ext/digest/sha1/sha1ossl.c
@@ -2,24 +2,9 @@
#include "defs.h"
#include "sha1ossl.h"
-#include <stdlib.h>
void
SHA1_Finish(SHA1_CTX *ctx, char *buf)
{
SHA1_Final(buf, ctx);
}
-
-int
-SHA1_Equal(SHA1_CTX* pctx1, SHA1_CTX* pctx2)
-{
- return pctx1->num == pctx2->num
- && pctx1->h0 == pctx2->h0
- && pctx1->h1 == pctx2->h1
- && pctx1->h2 == pctx2->h2
- && pctx1->h3 == pctx2->h3
- && pctx1->h4 == pctx2->h4
- && pctx1->Nl == pctx2->Nl
- && pctx1->Nh == pctx2->Nh
- && memcmp(pctx1->data, pctx2->data, sizeof(pctx1->data)) == 0;
-}
diff --git a/ext/digest/sha1/sha1ossl.h b/ext/digest/sha1/sha1ossl.h
index 8a5b9cf..8f9984c 100644
--- a/ext/digest/sha1/sha1ossl.h
+++ b/ext/digest/sha1/sha1ossl.h
@@ -16,6 +16,5 @@
#define SHA1_DIGEST_LENGTH SHA_DIGEST_LENGTH
void SHA1_Finish(SHA1_CTX *ctx, char *buf);
-int SHA1_Equal(SHA1_CTX *pctx1, SHA1_CTX *pctx2);
#endif
diff --git a/ext/digest/sha2/sha2.c b/ext/digest/sha2/sha2.c
index 1dd69c4..aca9ee9 100644
--- a/ext/digest/sha2/sha2.c
+++ b/ext/digest/sha2/sha2.c
@@ -578,12 +578,6 @@ void SHA256_Finish(SHA256_CTX* context, sha2_byte digest[]) {
usedspace = 0;
}
-int SHA256_Equal(SHA256_CTX* pctx1, SHA256_CTX* pctx2) {
- return pctx1->bitcount == pctx2->bitcount
- && memcmp(pctx1->state, pctx2->state, sizeof(pctx1->state)) == 0
- && memcmp(pctx1->buffer, pctx2->buffer, sizeof(pctx1->buffer)) == 0;
-}
-
/*** SHA-512: *********************************************************/
void SHA512_Init(SHA512_CTX* context) {
if (context == (SHA512_CTX*)0) {
@@ -881,12 +875,6 @@ void SHA512_Finish(SHA512_CTX* context, sha2_byte digest[]) {
MEMSET_BZERO(context, sizeof(SHA512_CTX));
}
-int SHA512_Equal(SHA512_CTX* pctx1, SHA512_CTX* pctx2) {
- return memcmp(pctx1->bitcount, pctx2->bitcount, sizeof(pctx1->bitcount)) == 0
- && memcmp(pctx1->state, pctx2->state, sizeof(pctx1->state)) == 0
- && memcmp(pctx1->buffer, pctx2->buffer, sizeof(pctx1->buffer)) == 0;
-}
-
/*** SHA-384: *********************************************************/
void SHA384_Init(SHA384_CTX* context) {
if (context == (SHA384_CTX*)0) {
@@ -929,9 +917,3 @@ void SHA384_Finish(SHA384_CTX* context, sha2_byte digest[]) {
/* Zero out state data */
MEMSET_BZERO(context, sizeof(SHA384_CTX));
}
-
-int SHA384_Equal(SHA384_CTX* pctx1, SHA384_CTX* pctx2) {
- return memcmp(pctx1->bitcount, pctx2->bitcount, sizeof(pctx1->bitcount)) == 0
- && memcmp(pctx1->state, pctx2->state, sizeof(pctx1->state)) == 0
- && memcmp(pctx1->buffer, pctx2->buffer, sizeof(pctx1->buffer)) == 0;
-}
diff --git a/ext/digest/sha2/sha2.h b/ext/digest/sha2/sha2.h
index db72cbb..917d415 100644
--- a/ext/digest/sha2/sha2.h
+++ b/ext/digest/sha2/sha2.h
@@ -78,34 +78,28 @@ typedef SHA512_CTX SHA384_CTX;
#define SHA256_Init rb_Digest_SHA256_Init
#define SHA256_Update rb_Digest_SHA256_Update
#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_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_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_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_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_Finish _((SHA512_CTX*, uint8_t[SHA512_DIGEST_LENGTH]));
-int SHA512_Equal _((SHA512_CTX*, SHA512_CTX*));
#ifdef __cplusplus
}
diff --git a/ext/digest/sha2/sha2init.c b/ext/digest/sha2/sha2init.c
index 4fb845c..cc815e7 100644
--- a/ext/digest/sha2/sha2init.c
+++ b/ext/digest/sha2/sha2init.c
@@ -13,7 +13,6 @@ static algo_t sha##bitlen = { \
(hash_init_func_t)SHA##bitlen##_Init, \
(hash_update_func_t)SHA##bitlen##_Update, \
(hash_finish_func_t)SHA##bitlen##_Finish, \
- (hash_equal_func_t)SHA##bitlen##_Equal, \
};
FOREACH_BITLEN(DEFINE_ALGO_METADATA)