Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(342)

Side by Side Diff: core/fdrm/crypto/fx_crypt_unittest.cpp

Issue 2577223002: Better tests for password protected documents. (Closed)
Patch Set: revert pdfium_test Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/fdrm/crypto/fx_crypt_sha.cpp ('k') | core/fpdfapi/parser/cpdf_security_handler.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Originally from chromium's /src/base/md5_unittest.cc. 5 // Originally from chromium's /src/base/md5_unittest.cc.
6 6
7 #include "core/fdrm/crypto/fx_crypt.h" 7 #include "core/fdrm/crypto/fx_crypt.h"
8 8
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 CRYPT_MD5Start(&ctx); 191 CRYPT_MD5Start(&ctx);
192 CRYPT_MD5Update(&ctx, reinterpret_cast<const uint8_t*>("abc"), 3); 192 CRYPT_MD5Update(&ctx, reinterpret_cast<const uint8_t*>("abc"), 3);
193 193
194 uint8_t digest[16]; 194 uint8_t digest[16];
195 CRYPT_MD5Finish(&ctx, digest); 195 CRYPT_MD5Finish(&ctx, digest);
196 196
197 std::string actual = CRYPT_ToBase16(digest); 197 std::string actual = CRYPT_ToBase16(digest);
198 std::string expected = "900150983cd24fb0d6963f7d28e17f72"; 198 std::string expected = "900150983cd24fb0d6963f7d28e17f72";
199 EXPECT_EQ(expected, actual); 199 EXPECT_EQ(expected, actual);
200 } 200 }
201
202 TEST(FXCRYPT, Sha256TestB1) {
203 // Example B.1 from FIPS 180-2: one-block message.
204 const char* input = "abc";
205 const uint8_t expected[32] = {0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea,
206 0x41, 0x41, 0x40, 0xde, 0x5d, 0xae, 0x22, 0x23,
207 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c,
208 0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad};
209 uint8_t actual[32];
210 CRYPT_SHA256Generate(reinterpret_cast<const uint8_t*>(input), strlen(input),
211 actual);
212 for (size_t i = 0; i < 32; ++i)
213 EXPECT_EQ(expected[i], actual[i]) << " at byte " << i;
214 }
215
216 TEST(FXCRYPT, Sha256TestB2) {
217 // Example B.2 from FIPS 180-2: multi-block message.
218 const char* input =
219 "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
220 const uint8_t expected[32] = {0x24, 0x8d, 0x6a, 0x61, 0xd2, 0x06, 0x38, 0xb8,
221 0xe5, 0xc0, 0x26, 0x93, 0x0c, 0x3e, 0x60, 0x39,
222 0xa3, 0x3c, 0xe4, 0x59, 0x64, 0xff, 0x21, 0x67,
223 0xf6, 0xec, 0xed, 0xd4, 0x19, 0xdb, 0x06, 0xc1};
224 uint8_t actual[32];
225 CRYPT_SHA256Generate(reinterpret_cast<const uint8_t*>(input), strlen(input),
226 actual);
227 for (size_t i = 0; i < 32; ++i)
228 EXPECT_EQ(expected[i], actual[i]) << " at byte " << i;
229 }
OLDNEW
« no previous file with comments | « core/fdrm/crypto/fx_crypt_sha.cpp ('k') | core/fpdfapi/parser/cpdf_security_handler.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698