summaryrefslogtreecommitdiff
path: root/ext/digest/sha2
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 /ext/digest/sha2
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
Diffstat (limited to 'ext/digest/sha2')
-rw-r--r--ext/digest/sha2/sha2.c24
-rw-r--r--ext/digest/sha2/sha2.h30
2 files changed, 30 insertions, 24 deletions
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();