summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2017-05-23 16:34:08 -0700
committerLei Zhang <thestig@chromium.org>2017-05-23 23:37:18 +0000
commit4d46901fe4ef3491bdb4375519b488de0142398e (patch)
treeb5e7c2dd6709b75478961a1274ead9a782e47458
parent640ce01e14c2e9b7b4ee3928988ff82eb230620e (diff)
downloadpdfium-4d46901fe4ef3491bdb4375519b488de0142398e.tar.xz
M59: Fix crypto calculation regression due to typo
Use the correct values to calculate SHA512. BUG=pdfium:727,chromium:725267 TBR=weili@chromium.org Change-Id: I7134091debaa04f17865170a4d4d62620062a9a1 Reviewed-on: https://pdfium-review.googlesource.com/5832 Reviewed-by: Lei Zhang <thestig@chromium.org>
-rw-r--r--core/fdrm/crypto/fx_crypt_sha.cpp16
-rw-r--r--core/fdrm/crypto/fx_crypt_unittest.cpp17
2 files changed, 25 insertions, 8 deletions
diff --git a/core/fdrm/crypto/fx_crypt_sha.cpp b/core/fdrm/crypto/fx_crypt_sha.cpp
index 49f77558f0..7c0e64a912 100644
--- a/core/fdrm/crypto/fx_crypt_sha.cpp
+++ b/core/fdrm/crypto/fx_crypt_sha.cpp
@@ -588,14 +588,14 @@ void CRYPT_SHA512Start(void* context) {
CRYPT_sha384_context* ctx = (CRYPT_sha384_context*)context;
memset(ctx, 0, sizeof(CRYPT_sha384_context));
- ctx->state[0] = 0xa09e667f3bcc908ULL;
- ctx->state[1] = 0xb67ae8584caa73bULL;
- ctx->state[2] = 0xc6ef372fe94f82bULL;
- ctx->state[3] = 0x54ff53a5f1d36f1ULL;
- ctx->state[4] = 0x10e527fade682d1ULL;
- ctx->state[5] = 0xb05688c2b3e6c1fULL;
- ctx->state[6] = 0xf83d9abfb41bd6bULL;
- ctx->state[7] = 0xbe0cd19137e2179ULL;
+ ctx->state[0] = 0x6a09e667f3bcc908ULL;
+ ctx->state[1] = 0xbb67ae8584caa73bULL;
+ ctx->state[2] = 0x3c6ef372fe94f82bULL;
+ ctx->state[3] = 0xa54ff53a5f1d36f1ULL;
+ ctx->state[4] = 0x510e527fade682d1ULL;
+ ctx->state[5] = 0x9b05688c2b3e6c1fULL;
+ ctx->state[6] = 0x1f83d9abfb41bd6bULL;
+ ctx->state[7] = 0x5be0cd19137e2179ULL;
}
void CRYPT_SHA512Update(void* context, const uint8_t* data, uint32_t size) {
diff --git a/core/fdrm/crypto/fx_crypt_unittest.cpp b/core/fdrm/crypto/fx_crypt_unittest.cpp
index 4e3da6e186..bea9378b8c 100644
--- a/core/fdrm/crypto/fx_crypt_unittest.cpp
+++ b/core/fdrm/crypto/fx_crypt_unittest.cpp
@@ -227,3 +227,20 @@ TEST(FXCRYPT, Sha256TestB2) {
for (size_t i = 0; i < 32; ++i)
EXPECT_EQ(expected[i], actual[i]) << " at byte " << i;
}
+
+TEST(FXCRYPT, Sha512Test) {
+ const char* const input =
+ "This is a simple test. To see whether it is getting correct value.";
+ const uint8_t expected[64] = {
+ 0x86, 0xB5, 0x05, 0x63, 0xA2, 0x6F, 0xD6, 0xFA, 0xEB, 0x9B, 0xC3,
+ 0xBB, 0x9E, 0xB7, 0x03, 0x82, 0xB6, 0x50, 0x55, 0x6B, 0x90, 0x69,
+ 0xD0, 0xA7, 0x53, 0x0A, 0x34, 0xDD, 0xEA, 0x11, 0xCC, 0x91, 0x5C,
+ 0xC7, 0x93, 0xCA, 0xAE, 0x30, 0xD1, 0x96, 0xBE, 0xD0, 0x35, 0x21,
+ 0x4A, 0xC6, 0x42, 0x56, 0x0C, 0xA3, 0x00, 0x69, 0x44, 0x77, 0xCC,
+ 0x3E, 0xD4, 0xD6, 0x10, 0x31, 0xC6, 0xC0, 0x58, 0xCF};
+ uint8_t actual[64];
+ CRYPT_SHA512Generate(reinterpret_cast<const uint8_t*>(input), strlen(input),
+ actual);
+ for (size_t i = 0; i < 64; ++i)
+ EXPECT_EQ(expected[i], actual[i]) << " at byte " << i;
+}