aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog10
-rw-r--r--ext/digest/sha2/sha2.c6
-rwxr-xr-xtest/digest/test_digest.rb9
3 files changed, 23 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index a0c86149b0..744f117e3a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+Fri Jul 15 09:10:41 2011 Hiroshi Nakamura <nahi@ruby-lang.org>
+
+ * ext/digest/sha2/sha2.c (SHA256_Update, SHA512_Update): avoid Bus
+ Error caused by unalignment access on Sparc-Solaris (and possibly on
+ other similar environment.) This patch just do memcpy always instead
+ of checking architecture. I see no perf drop on my 64bit env. For
+ more details, see #4320.
+
+ * test/digest/test_digest.rb: add test for unalignment access.
+
Fri Jul 15 01:51:25 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
* regint.h (PLATFORM_UNALIGNED_WORD_ACCESS): Power PC does not
diff --git a/ext/digest/sha2/sha2.c b/ext/digest/sha2/sha2.c
index ac7f7b5b7a..0566b93cb7 100644
--- a/ext/digest/sha2/sha2.c
+++ b/ext/digest/sha2/sha2.c
@@ -559,7 +559,8 @@ void SHA256_Update(SHA256_CTX* context, const sha2_byte *data, size_t len) {
}
while (len >= SHA256_BLOCK_LENGTH) {
/* Process as many complete blocks as we can */
- SHA256_Transform(context, (sha2_word32*)data);
+ MEMCPY_BCOPY(context->buffer, data, SHA256_BLOCK_LENGTH);
+ SHA256_Transform(context, (sha2_word32*)context->buffer);
context->bitcount += SHA256_BLOCK_LENGTH << 3;
len -= SHA256_BLOCK_LENGTH;
data += SHA256_BLOCK_LENGTH;
@@ -880,7 +881,8 @@ void SHA512_Update(SHA512_CTX* context, const sha2_byte *data, size_t len) {
}
while (len >= SHA512_BLOCK_LENGTH) {
/* Process as many complete blocks as we can */
- SHA512_Transform(context, (sha2_word64*)data);
+ MEMCPY_BCOPY(context->buffer, data, SHA512_BLOCK_LENGTH);
+ SHA512_Transform(context, (sha2_word64*)context->buffer);
ADDINC128(context->bitcount, SHA512_BLOCK_LENGTH << 3);
len -= SHA512_BLOCK_LENGTH;
data += SHA512_BLOCK_LENGTH;
diff --git a/test/digest/test_digest.rb b/test/digest/test_digest.rb
index ac3db00f5e..661129083a 100755
--- a/test/digest/test_digest.rb
+++ b/test/digest/test_digest.rb
@@ -78,6 +78,15 @@ module TestDigest
}
end
+ def test_alignment
+ md = self.class::ALGO.new
+ assert_nothing_raised('#4320') {
+ md.update('a' * 97)
+ md.update('a' * 97)
+ md.hexdigest
+ }
+ end
+
class TestMD5 < Test::Unit::TestCase
include TestDigest
ALGO = Digest::MD5