[前][次][番号順一覧][スレッド一覧]

ruby-changes:34745

From: nobu <ko1@a...>
Date: Tue, 15 Jul 2014 23:59:58 +0900 (JST)
Subject: [ruby-changes:34745] nobu:r46827 (trunk): ext/digest: return values of init and final

nobu	2014-07-15 23:59:20 +0900 (Tue, 15 Jul 2014)

  New Revision: 46827

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=46827

  Log:
    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]

  Modified files:
    trunk/ChangeLog
    trunk/ext/digest/md5/md5.c
    trunk/ext/digest/md5/md5.h
    trunk/ext/digest/rmd160/rmd160.c
    trunk/ext/digest/rmd160/rmd160.h
    trunk/ext/digest/sha1/sha1.c
    trunk/ext/digest/sha1/sha1.h
    trunk/ext/digest/sha2/sha2.c
    trunk/ext/digest/sha2/sha2.h
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 46826)
+++ ChangeLog	(revision 46827)
@@ -1,4 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
-Tue Jul 15 23:58:59 2014  Jared Jennings  <jared.jennings.ctr@u...>
+Tue Jul 15 23:59:27 2014  Jared Jennings  <jared.jennings.ctr@u...>
+
+	* 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.
Index: ext/digest/md5/md5.c
===================================================================
--- ext/digest/md5/md5.c	(revision 46826)
+++ ext/digest/md5/md5.c	(revision 46827)
@@ -350,7 +350,7 @@ md5_process(MD5_CTX *pms, const uint8_t https://github.com/ruby/ruby/blob/trunk/ext/digest/md5/md5.c#L350
     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) https://github.com/ruby/ruby/blob/trunk/ext/digest/md5/md5.c#L358
     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 * https://github.com/ruby/ruby/blob/trunk/ext/digest/md5/md5.c#L399
 	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 https://github.com/ruby/ruby/blob/trunk/ext/digest/md5/md5.c#L420
     MD5_Update(pms, data, 8);
     for (i = 0; i < 16; ++i)
 	digest[i] = (uint8_t)(pms->state[i >> 2] >> ((i & 3) << 3));
+    return 1;
 }
Index: ext/digest/md5/md5.h
===================================================================
--- ext/digest/md5/md5.h	(revision 46826)
+++ ext/digest/md5/md5.h	(revision 46827)
@@ -69,9 +69,9 @@ typedef struct md5_state_s { https://github.com/ruby/ruby/blob/trunk/ext/digest/md5/md5.h#L69
 #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
Index: ext/digest/rmd160/rmd160.h
===================================================================
--- ext/digest/rmd160/rmd160.h	(revision 46826)
+++ ext/digest/rmd160/rmd160.h	(revision 46827)
@@ -43,10 +43,10 @@ typedef struct { https://github.com/ruby/ruby/blob/trunk/ext/digest/rmd160/rmd160.h#L43
 #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
Index: ext/digest/rmd160/rmd160.c
===================================================================
--- ext/digest/rmd160/rmd160.c	(revision 46826)
+++ ext/digest/rmd160/rmd160.c	(revision 46827)
@@ -124,7 +124,7 @@ https://github.com/ruby/ruby/blob/trunk/ext/digest/rmd160/rmd160.c#L124
 
 /********************************************************************/
 
-void
+int
 RMD160_Init(RMD160_CTX *context)
 {
 
@@ -138,6 +138,7 @@ RMD160_Init(RMD160_CTX *context) https://github.com/ruby/ruby/blob/trunk/ext/digest/rmd160/rmd160.c#L138
 	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 https://github.com/ruby/ruby/blob/trunk/ext/digest/rmd160/rmd160.c#L413
 
 /********************************************************************/
 
-void
+int
 RMD160_Finish(RMD160_CTX *context, uint8_t digest[20])
 {
 	uint32_t i;
@@ -456,6 +457,7 @@ RMD160_Finish(RMD160_CTX *context, uint8 https://github.com/ruby/ruby/blob/trunk/ext/digest/rmd160/rmd160.c#L457
 			digest[i + 3] = (context->state[i>>2] >> 24);
 		}
 	}
+	return 1;
 }
 
 /************************ end of file rmd160.c **********************/
Index: ext/digest/sha1/sha1.h
===================================================================
--- ext/digest/sha1/sha1.h	(revision 46826)
+++ ext/digest/sha1/sha1.h	(revision 46827)
@@ -28,9 +28,9 @@ typedef struct { https://github.com/ruby/ruby/blob/trunk/ext/digest/sha1/sha1.h#L28
 #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
Index: ext/digest/sha1/sha1.c
===================================================================
--- ext/digest/sha1/sha1.c	(revision 46826)
+++ ext/digest/sha1/sha1.c	(revision 46827)
@@ -199,7 +199,7 @@ void SHA1_Transform(uint32_t state[5], c https://github.com/ruby/ruby/blob/trunk/ext/digest/sha1/sha1.c#L199
 /*
  * 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) https://github.com/ruby/ruby/blob/trunk/ext/digest/sha1/sha1.c#L211
     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, cons https://github.com/ruby/ruby/blob/trunk/ext/digest/sha1/sha1.c#L245
 /*
  * 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, uint https://github.com/ruby/ruby/blob/trunk/ext/digest/sha1/sha1.c#L267
 	    digest[i] = (uint8_t)
 		((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255);
     }
+    return 1;
 }
Index: ext/digest/sha2/sha2.h
===================================================================
--- ext/digest/sha2/sha2.h	(revision 46826)
+++ ext/digest/sha2/sha2.h	(revision 46827)
@@ -165,52 +165,52 @@ typedef SHA512_CTX SHA384_CTX; https://github.com/ruby/ruby/blob/trunk/ext/digest/sha2/sha2.h#L165
 
 #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();
Index: ext/digest/sha2/sha2.c
===================================================================
--- ext/digest/sha2/sha2.c	(revision 46826)
+++ ext/digest/sha2/sha2.c	(revision 46827)
@@ -341,13 +341,14 @@ static const char *sha2_hex_digits = "01 https://github.com/ruby/ruby/blob/trunk/ext/digest/sha2/sha2.c#L341
 
 
 /*** 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, https://github.com/ruby/ruby/blob/trunk/ext/digest/sha2/sha2.c#L575
 	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[], SH https://github.com/ruby/ruby/blob/trunk/ext/digest/sha2/sha2.c#L637
 	/* 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, https://github.com/ruby/ruby/blob/trunk/ext/digest/sha2/sha2.c#L672
 
 
 /*** 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) { https://github.com/ruby/ruby/blob/trunk/ext/digest/sha2/sha2.c#L943
 	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[], SH https://github.com/ruby/ruby/blob/trunk/ext/digest/sha2/sha2.c#L970
 
 	/* 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, https://github.com/ruby/ruby/blob/trunk/ext/digest/sha2/sha2.c#L1005
 
 
 /*** 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[], SH https://github.com/ruby/ruby/blob/trunk/ext/digest/sha2/sha2.c#L1046
 
 	/* Zero out state data */
 	MEMSET_BZERO(context, sizeof(*context));
+	return 1;
 }
 
 char *SHA384_End(SHA384_CTX* context, char buffer[]) {

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]