summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-07-15 14:59:20 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-07-15 14:59:20 +0000
commitaadebb29da14b65f47cf3e08ac164e6fe191febe (patch)
tree24a6148536d413890c668b7ce50e10942188711a
parent6046b9f149ec748a11d7b23c6cf485fb3e079e5a (diff)
ext/digest: return values of init and final
* ext/digest: make built-in digest function implementations indicate success or failure of init and final functions. [ruby-core:61614] [Bug #9659] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46827 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog6
-rw-r--r--ext/digest/md5/md5.c6
-rw-r--r--ext/digest/md5/md5.h4
-rw-r--r--ext/digest/rmd160/rmd160.c6
-rw-r--r--ext/digest/rmd160/rmd160.h4
-rw-r--r--ext/digest/sha1/sha1.c6
-rw-r--r--ext/digest/sha1/sha1.h4
-rw-r--r--ext/digest/sha2/sha2.c24
-rw-r--r--ext/digest/sha2/sha2.h30
9 files changed, 53 insertions, 37 deletions
diff --git a/ChangeLog b/ChangeLog
index 6f1b0fe..678e21b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,8 @@
-Tue Jul 15 23:58:59 2014 Jared Jennings <jared.jennings.ctr@us.af.mil>
+Tue Jul 15 23:59:27 2014 Jared Jennings <jared.jennings.ctr@us.af.mil>
+
+ * ext/digest: make built-in digest function implementations
+ indicate success or failure of init and final functions.
+ [ruby-core:61614] [Bug #9659]
* ext/digest/digest.c: expect digest init and finish functions to
indicate success or failure; raise exception on failure.
diff --git a/ext/digest/md5/md5.c b/ext/digest/md5/md5.c
index 8d7d33c..4ff280b 100644
--- a/ext/digest/md5/md5.c
+++ b/ext/digest/md5/md5.c
@@ -350,7 +350,7 @@ md5_process(MD5_CTX *pms, const uint8_t *data /*[64]*/)
pms->state[3] += d;
}
-void
+int
MD5_Init(MD5_CTX *pms)
{
pms->count[0] = pms->count[1] = 0;
@@ -358,6 +358,7 @@ MD5_Init(MD5_CTX *pms)
pms->state[1] = /*0xefcdab89*/ T_MASK ^ 0x10325476;
pms->state[2] = /*0x98badcfe*/ T_MASK ^ 0x67452301;
pms->state[3] = 0x10325476;
+ return 1;
}
void
@@ -398,7 +399,7 @@ MD5_Update(MD5_CTX *pms, const uint8_t *data, size_t nbytes)
memcpy(pms->buffer, p, left);
}
-void
+int
MD5_Finish(MD5_CTX *pms, uint8_t *digest)
{
static const uint8_t pad[64] = {
@@ -419,4 +420,5 @@ MD5_Finish(MD5_CTX *pms, uint8_t *digest)
MD5_Update(pms, data, 8);
for (i = 0; i < 16; ++i)
digest[i] = (uint8_t)(pms->state[i >> 2] >> ((i & 3) << 3));
+ return 1;
}
diff --git a/ext/digest/md5/md5.h b/ext/digest/md5/md5.h
index f4580ef..a0faa25 100644
--- a/ext/digest/md5/md5.h
+++ b/ext/digest/md5/md5.h
@@ -69,9 +69,9 @@ typedef struct md5_state_s {
#define MD5_Finish rb_Digest_MD5_Finish
#endif
-void MD5_Init _((MD5_CTX *pms));
+int 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_Finish _((MD5_CTX *pms, uint8_t *digest));
#define MD5_BLOCK_LENGTH 64
#define MD5_DIGEST_LENGTH 16
diff --git a/ext/digest/rmd160/rmd160.c b/ext/digest/rmd160/rmd160.c
index bac7783..058d004 100644
--- a/ext/digest/rmd160/rmd160.c
+++ b/ext/digest/rmd160/rmd160.c
@@ -124,7 +124,7 @@
/********************************************************************/
-void
+int
RMD160_Init(RMD160_CTX *context)
{
@@ -138,6 +138,7 @@ RMD160_Init(RMD160_CTX *context)
context->state[4] = 0xc3d2e1f0U;
context->length[0] = context->length[1] = 0;
context->buflen = 0;
+ return 1;
}
/********************************************************************/
@@ -412,7 +413,7 @@ RMD160_Update(RMD160_CTX *context, const uint8_t *data, size_t nbytes)
/********************************************************************/
-void
+int
RMD160_Finish(RMD160_CTX *context, uint8_t digest[20])
{
uint32_t i;
@@ -456,6 +457,7 @@ RMD160_Finish(RMD160_CTX *context, uint8_t digest[20])
digest[i + 3] = (context->state[i>>2] >> 24);
}
}
+ return 1;
}
/************************ end of file rmd160.c **********************/
diff --git a/ext/digest/rmd160/rmd160.h b/ext/digest/rmd160/rmd160.h
index 2c98f11..098fa05 100644
--- a/ext/digest/rmd160/rmd160.h
+++ b/ext/digest/rmd160/rmd160.h
@@ -43,10 +43,10 @@ typedef struct {
#endif
__BEGIN_DECLS
-void RMD160_Init _((RMD160_CTX *));
+int 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_Finish _((RMD160_CTX *, uint8_t[20]));
__END_DECLS
#define RMD160_BLOCK_LENGTH 64
diff --git a/ext/digest/sha1/sha1.c b/ext/digest/sha1/sha1.c
index 6196ca6..5311227 100644
--- a/ext/digest/sha1/sha1.c
+++ b/ext/digest/sha1/sha1.c
@@ -199,7 +199,7 @@ void SHA1_Transform(uint32_t state[5], const uint8_t buffer[64])
/*
* SHA1_Init - Initialize new context
*/
-void SHA1_Init(SHA1_CTX *context)
+int SHA1_Init(SHA1_CTX *context)
{
_DIAGASSERT(context != 0);
@@ -211,6 +211,7 @@ void SHA1_Init(SHA1_CTX *context)
context->state[3] = 0x10325476;
context->state[4] = 0xC3D2E1F0;
context->count[0] = context->count[1] = 0;
+ return 1;
}
@@ -244,7 +245,7 @@ void SHA1_Update(SHA1_CTX *context, const uint8_t *data, size_t len)
/*
* Add padding and return the message digest.
*/
-void SHA1_Finish(SHA1_CTX* context, uint8_t digest[20])
+int SHA1_Finish(SHA1_CTX* context, uint8_t digest[20])
{
size_t i;
uint8_t finalcount[8];
@@ -266,4 +267,5 @@ void SHA1_Finish(SHA1_CTX* context, uint8_t digest[20])
digest[i] = (uint8_t)
((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255);
}
+ return 1;
}
diff --git a/ext/digest/sha1/sha1.h b/ext/digest/sha1/sha1.h
index 55997e7..6f1c388 100644
--- a/ext/digest/sha1/sha1.h
+++ b/ext/digest/sha1/sha1.h
@@ -28,9 +28,9 @@ typedef struct {
#endif
void SHA1_Transform _((uint32_t state[5], const uint8_t buffer[64]));
-void SHA1_Init _((SHA1_CTX *context));
+int 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_Finish _((SHA1_CTX *context, uint8_t digest[20]));
#define SHA1_BLOCK_LENGTH 64
#define SHA1_DIGEST_LENGTH 20
diff --git a/ext/digest/sha2/sha2.c b/ext/digest/sha2/sha2.c
index 3457790..d0629a2 100644
--- a/ext/digest/sha2/sha2.c
+++ b/ext/digest/sha2/sha2.c
@@ -341,13 +341,14 @@ static const char *sha2_hex_digits = "0123456789abcdef";
/*** SHA-256: *********************************************************/
-void SHA256_Init(SHA256_CTX* context) {
+int SHA256_Init(SHA256_CTX* context) {
if (context == (SHA256_CTX*)0) {
- return;
+ return 0;
}
MEMCPY_BCOPY(context->state, sha256_initial_hash_value, SHA256_DIGEST_LENGTH);
MEMSET_BZERO(context->buffer, SHA256_BLOCK_LENGTH);
context->bitcount = 0;
+ return 1;
}
#ifdef SHA2_UNROLL_TRANSFORM
@@ -574,7 +575,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) {
+int SHA256_Final(sha2_byte digest[], SHA256_CTX* context) {
sha2_word32 *d = (sha2_word32*)digest;
unsigned int usedspace;
@@ -636,6 +637,7 @@ void SHA256_Final(sha2_byte digest[], SHA256_CTX* context) {
/* Clean up state data: */
MEMSET_BZERO(context, sizeof(*context));
usedspace = 0;
+ return 1;
}
char *SHA256_End(SHA256_CTX* context, char buffer[]) {
@@ -670,13 +672,14 @@ char* SHA256_Data(const sha2_byte* data, size_t len, char digest[SHA256_DIGEST_S
/*** SHA-512: *********************************************************/
-void SHA512_Init(SHA512_CTX* context) {
+int SHA512_Init(SHA512_CTX* context) {
if (context == (SHA512_CTX*)0) {
- return;
+ return 0;
}
MEMCPY_BCOPY(context->state, sha512_initial_hash_value, SHA512_DIGEST_LENGTH);
MEMSET_BZERO(context->buffer, SHA512_BLOCK_LENGTH);
context->bitcount[0] = context->bitcount[1] = 0;
+ return 1;
}
#ifdef SHA2_UNROLL_TRANSFORM
@@ -940,7 +943,7 @@ void SHA512_Last(SHA512_CTX* context) {
SHA512_Transform(context, (sha2_word64*)context->buffer);
}
-void SHA512_Final(sha2_byte digest[], SHA512_CTX* context) {
+int SHA512_Final(sha2_byte digest[], SHA512_CTX* context) {
sha2_word64 *d = (sha2_word64*)digest;
/* Sanity check: */
@@ -967,6 +970,7 @@ void SHA512_Final(sha2_byte digest[], SHA512_CTX* context) {
/* Zero out state data */
MEMSET_BZERO(context, sizeof(*context));
+ return 1;
}
char *SHA512_End(SHA512_CTX* context, char buffer[]) {
@@ -1001,20 +1005,21 @@ char* SHA512_Data(const sha2_byte* data, size_t len, char digest[SHA512_DIGEST_S
/*** SHA-384: *********************************************************/
-void SHA384_Init(SHA384_CTX* context) {
+int SHA384_Init(SHA384_CTX* context) {
if (context == (SHA384_CTX*)0) {
- return;
+ return 0;
}
MEMCPY_BCOPY(context->state, sha384_initial_hash_value, SHA512_DIGEST_LENGTH);
MEMSET_BZERO(context->buffer, SHA384_BLOCK_LENGTH);
context->bitcount[0] = context->bitcount[1] = 0;
+ return 1;
}
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) {
+int SHA384_Final(sha2_byte digest[], SHA384_CTX* context) {
sha2_word64 *d = (sha2_word64*)digest;
/* Sanity check: */
@@ -1041,6 +1046,7 @@ void SHA384_Final(sha2_byte digest[], SHA384_CTX* context) {
/* Zero out state data */
MEMSET_BZERO(context, sizeof(*context));
+ return 1;
}
char *SHA384_End(SHA384_CTX* context, char buffer[]) {
diff --git a/ext/digest/sha2/sha2.h b/ext/digest/sha2/sha2.h
index 465398e..e58f15a 100644
--- a/ext/digest/sha2/sha2.h
+++ b/ext/digest/sha2/sha2.h
@@ -165,52 +165,52 @@ typedef SHA512_CTX SHA384_CTX;
#ifndef NOPROTO
-void SHA256_Init(SHA256_CTX *);
+int SHA256_Init(SHA256_CTX *);
void SHA256_Update(SHA256_CTX*, const uint8_t*, size_t);
-void SHA256_Final(uint8_t[SHA256_DIGEST_LENGTH], SHA256_CTX*);
+int 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]);
-void SHA384_Init(SHA384_CTX*);
+int SHA384_Init(SHA384_CTX*);
void SHA384_Update(SHA384_CTX*, const uint8_t*, size_t);
-void SHA384_Final(uint8_t[SHA384_DIGEST_LENGTH], SHA384_CTX*);
+int 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]);
-void SHA512_Init(SHA512_CTX*);
+int SHA512_Init(SHA512_CTX*);
void SHA512_Update(SHA512_CTX*, const uint8_t*, size_t);
-void SHA512_Final(uint8_t[SHA512_DIGEST_LENGTH], SHA512_CTX*);
+int 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]);
#else /* NOPROTO */
-void SHA256_Init();
+int SHA256_Init();
void SHA256_Update();
#ifdef RUBY
-void SHA256_Finish();
+int SHA256_Finish();
#else
-void SHA256_Final();
+int SHA256_Final();
#endif /* RUBY */
char* SHA256_End();
char* SHA256_Data();
-void SHA384_Init();
+int SHA384_Init();
void SHA384_Update();
#ifdef RUBY
-void SHA384_Finish();
+int SHA384_Finish();
#else
-void SHA384_Final();
+int SHA384_Final();
#endif /* RUBY */
char* SHA384_End();
char* SHA384_Data();
-void SHA512_Init();
+int SHA512_Init();
void SHA512_Update();
#ifdef RUBY
-void SHA512_Finish();
+int SHA512_Finish();
#else
-void SHA512_Final();
+int SHA512_Final();
#endif /* RUBY */
char* SHA512_End();
char* SHA512_Data();