summaryrefslogtreecommitdiff
path: root/ext/digest/sha1
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-10-11 17:25:45 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-10-11 17:25:45 +0000
commit368c8038f402db5c30eef7fc41ac09b6e6829ef4 (patch)
treec8f8d08bdb6d46fb3236647b0d62d915ca199239 /ext/digest/sha1
parentb3f7970ef9dbbb8e1470c10747cf45574b6fc399 (diff)
* ext/digest: Merge from trunk; metadata location changed,
Digest::Base#reset() added, Digest::Base#equal() changed, and digest/hmac added with some modifications for ruby 1.8. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@11137 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/digest/sha1')
-rw-r--r--ext/digest/sha1/sha1.c6
-rw-r--r--ext/digest/sha1/sha1.h2
-rw-r--r--ext/digest/sha1/sha1init.c8
-rw-r--r--ext/digest/sha1/sha1ossl.c15
-rw-r--r--ext/digest/sha1/sha1ossl.h5
5 files changed, 9 insertions, 27 deletions
diff --git a/ext/digest/sha1/sha1.c b/ext/digest/sha1/sha1.c
index 6545744bed..6196ca6b82 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 c9f84562fc..60e3b01fe2 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 a704dcbfde..e56f18bf63 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
@@ -29,6 +28,9 @@ Init_sha1()
cDigest_SHA1 = rb_define_class_under(mDigest, "SHA1", cDigest_Base);
- rb_cvar_set(cDigest_SHA1, rb_intern("metadata"),
- Data_Wrap_Struct(rb_cObject, 0, 0, &sha1), Qtrue);
+ rb_define_const(cDigest_SHA1, "DIGEST_LENGTH", INT2NUM(SHA1_DIGEST_LENGTH));
+ rb_define_const(cDigest_SHA1, "BLOCK_LENGTH", INT2NUM(SHA1_BLOCK_LENGTH));
+
+ rb_ivar_set(cDigest_SHA1, rb_intern("metadata"),
+ Data_Wrap_Struct(rb_cObject, 0, 0, &sha1));
}
diff --git a/ext/digest/sha1/sha1ossl.c b/ext/digest/sha1/sha1ossl.c
index 96365c7974..adf5cf267c 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 c2e19d66e8..8f9984cc64 100644
--- a/ext/digest/sha1/sha1ossl.h
+++ b/ext/digest/sha1/sha1ossl.h
@@ -8,10 +8,13 @@
#define SHA1_CTX SHA_CTX
+#ifdef SHA_BLOCK_LENGTH
#define SHA1_BLOCK_LENGTH SHA_BLOCK_LENGTH
+#else
+#define SHA1_BLOCK_LENGTH SHA_CBLOCK
+#endif
#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