Make SHA1 computation thread-safe.

Previously SHA1Transform() kept a static buffer. As result SHA1 was not
always computed correctly when running that code in parallel on multiple
threads. That was causing spurious messages about invalid Message
Integrity attribute when running some tests in chromoting.

R=pthatcher@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/57379004

Cr-Commit-Position: refs/heads/master@{#9238}
This commit is contained in:
Sergey Ulanov 2015-05-20 11:25:37 -07:00
parent 5cdd7024d0
commit 8eb76ff32a

View File

@ -91,6 +91,11 @@
* 84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1 * 84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1
* A million repetitions of "a" * A million repetitions of "a"
* 34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F * 34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F
*
* -----------------
* Modified 05/2015
* By Sergey Ulanov <sergeyu@chromium.org>
* Removed static buffer to make computation thread-safe.
*/ */
// Enabling SHA1HANDSOFF preserves the caller's data buffer. // Enabling SHA1HANDSOFF preserves the caller's data buffer.
@ -157,7 +162,7 @@ void SHA1Transform(uint32 state[5], const uint8 buffer[64]) {
uint32 l[16]; uint32 l[16];
}; };
#ifdef SHA1HANDSOFF #ifdef SHA1HANDSOFF
static uint8 workspace[64]; uint8 workspace[64];
memcpy(workspace, buffer, 64); memcpy(workspace, buffer, 64);
CHAR64LONG16* block = reinterpret_cast<CHAR64LONG16*>(workspace); CHAR64LONG16* block = reinterpret_cast<CHAR64LONG16*>(workspace);
#else #else