diff options
author | Andras Becsi <andras.becsi@digia.com> | 2014-03-18 13:16:26 +0100 |
---|---|---|
committer | Frederik Gladhorn <frederik.gladhorn@digia.com> | 2014-03-20 15:55:39 +0100 |
commit | 3f0f86b0caed75241fa71c95a5d73bc0164348c5 (patch) | |
tree | 92b9fb00f2e9e90b0be2262093876d4f43b6cd13 /chromium/crypto/encryptor_unittest.cc | |
parent | e90d7c4b152c56919d963987e2503f9909a666d2 (diff) | |
download | qtwebengine-chromium-3f0f86b0caed75241fa71c95a5d73bc0164348c5.tar.gz |
Update to new stable branch 1750
This also includes an updated ninja and chromium dependencies
needed on Windows.
Change-Id: Icd597d80ed3fa4425933c9f1334c3c2e31291c42
Reviewed-by: Zoltan Arvai <zarvai@inf.u-szeged.hu>
Reviewed-by: Zeno Albisser <zeno.albisser@digia.com>
Diffstat (limited to 'chromium/crypto/encryptor_unittest.cc')
-rw-r--r-- | chromium/crypto/encryptor_unittest.cc | 82 |
1 files changed, 54 insertions, 28 deletions
diff --git a/chromium/crypto/encryptor_unittest.cc b/chromium/crypto/encryptor_unittest.cc index 2f569e19e0f..2a21a8e13db 100644 --- a/chromium/crypto/encryptor_unittest.cc +++ b/chromium/crypto/encryptor_unittest.cc @@ -29,10 +29,10 @@ TEST(EncryptorTest, EncryptDecrypt) { EXPECT_LT(0U, ciphertext.size()); - std::string decypted; - EXPECT_TRUE(encryptor.Decrypt(ciphertext, &decypted)); + std::string decrypted; + EXPECT_TRUE(encryptor.Decrypt(ciphertext, &decrypted)); - EXPECT_EQ(plaintext, decypted); + EXPECT_EQ(plaintext, decrypted); } TEST(EncryptorTest, DecryptWrongKey) { @@ -84,7 +84,7 @@ TEST(EncryptorTest, DecryptWrongKey) { static_cast<unsigned char>(ciphertext[i])); } - std::string decypted; + std::string decrypted; // This wrong key causes the last padding byte to be 5, which is a valid // padding length, and the second to last padding byte to be 137, which is @@ -95,7 +95,7 @@ TEST(EncryptorTest, DecryptWrongKey) { #if !defined(USE_NSS) && !defined(OS_WIN) && !defined(OS_MACOSX) crypto::Encryptor decryptor; EXPECT_TRUE(decryptor.Init(wrong_key.get(), crypto::Encryptor::CBC, iv)); - EXPECT_FALSE(decryptor.Decrypt(ciphertext, &decypted)); + EXPECT_FALSE(decryptor.Decrypt(ciphertext, &decrypted)); #endif // This demonstrates that not all wrong keys can be detected by padding @@ -103,13 +103,13 @@ TEST(EncryptorTest, DecryptWrongKey) { // a valid padding block of length 1. crypto::Encryptor decryptor2; EXPECT_TRUE(decryptor2.Init(wrong_key2.get(), crypto::Encryptor::CBC, iv)); - EXPECT_TRUE(decryptor2.Decrypt(ciphertext, &decypted)); + EXPECT_TRUE(decryptor2.Decrypt(ciphertext, &decrypted)); // This wrong key causes the last padding byte to be 253, which should be // rejected by all implementations. crypto::Encryptor decryptor3; EXPECT_TRUE(decryptor3.Init(wrong_key3.get(), crypto::Encryptor::CBC, iv)); - EXPECT_FALSE(decryptor3.Decrypt(ciphertext, &decypted)); + EXPECT_FALSE(decryptor3.Decrypt(ciphertext, &decrypted)); } namespace { @@ -205,11 +205,11 @@ void TestAESCTREncrypt( EXPECT_EQ(ciphertext_size, encrypted.size()); EXPECT_EQ(0, memcmp(encrypted.data(), ciphertext, encrypted.size())); - std::string decypted; + std::string decrypted; EXPECT_TRUE(encryptor.SetCounter(init_counter_str)); - EXPECT_TRUE(encryptor.Decrypt(encrypted, &decypted)); + EXPECT_TRUE(encryptor.Decrypt(encrypted, &decrypted)); - EXPECT_EQ(plaintext_str, decypted); + EXPECT_EQ(plaintext_str, decrypted); } void TestAESCTRMultipleDecrypt( @@ -236,12 +236,12 @@ void TestAESCTRMultipleDecrypt( int offset = 0; for (size_t i = 0; i < arraysize(kTestDecryptSizes); ++i) { - std::string decypted; + std::string decrypted; size_t len = kTestDecryptSizes[i]; EXPECT_TRUE( - encryptor.Decrypt(ciphertext_str.substr(offset, len), &decypted)); - EXPECT_EQ(len, decypted.size()); - EXPECT_EQ(0, memcmp(decypted.data(), plaintext + offset, len)); + encryptor.Decrypt(ciphertext_str.substr(offset, len), &decrypted)); + EXPECT_EQ(len, decrypted.size()); + EXPECT_EQ(0, memcmp(decrypted.data(), plaintext + offset, len)); offset += len; } } @@ -296,10 +296,10 @@ TEST(EncryptorTest, EncryptDecryptCTR) { EXPECT_TRUE(encryptor.Encrypt(plaintext, &ciphertext)); EXPECT_LT(0U, ciphertext.size()); - std::string decypted; + std::string decrypted; EXPECT_TRUE(encryptor.SetCounter(kInitialCounter)); - EXPECT_TRUE(encryptor.Decrypt(ciphertext, &decypted)); - EXPECT_EQ(plaintext, decypted); + EXPECT_TRUE(encryptor.Decrypt(ciphertext, &decrypted)); + EXPECT_EQ(plaintext, decrypted); plaintext = "0123456789012345"; EXPECT_TRUE(encryptor.SetCounter(kInitialCounter)); @@ -307,8 +307,8 @@ TEST(EncryptorTest, EncryptDecryptCTR) { EXPECT_LT(0U, ciphertext.size()); EXPECT_TRUE(encryptor.SetCounter(kInitialCounter)); - EXPECT_TRUE(encryptor.Decrypt(ciphertext, &decypted)); - EXPECT_EQ(plaintext, decypted); + EXPECT_TRUE(encryptor.Decrypt(ciphertext, &decrypted)); + EXPECT_EQ(plaintext, decrypted); } TEST(EncryptorTest, CTRCounter) { @@ -422,10 +422,10 @@ TEST(EncryptorTest, EncryptAES256CBC) { EXPECT_EQ(sizeof(kRawCiphertext), ciphertext.size()); EXPECT_EQ(0, memcmp(ciphertext.data(), kRawCiphertext, ciphertext.size())); - std::string decypted; - EXPECT_TRUE(encryptor.Decrypt(ciphertext, &decypted)); + std::string decrypted; + EXPECT_TRUE(encryptor.Decrypt(ciphertext, &decrypted)); - EXPECT_EQ(plaintext, decypted); + EXPECT_EQ(plaintext, decrypted); } // Expected output derived from the NSS implementation. @@ -451,9 +451,9 @@ TEST(EncryptorTest, EncryptAES128CBCRegression) { EXPECT_EQ(expected_ciphertext_hex, base::HexEncode(ciphertext.data(), ciphertext.size())); - std::string decypted; - EXPECT_TRUE(encryptor.Decrypt(ciphertext, &decypted)); - EXPECT_EQ(plaintext, decypted); + std::string decrypted; + EXPECT_TRUE(encryptor.Decrypt(ciphertext, &decrypted)); + EXPECT_EQ(plaintext, decrypted); } // Expected output derived from the NSS implementation. @@ -477,9 +477,9 @@ TEST(EncryptorTest, EncryptAES192CBCRegression) { EXPECT_EQ(expected_ciphertext_hex, base::HexEncode(ciphertext.data(), ciphertext.size())); - std::string decypted; - EXPECT_TRUE(encryptor.Decrypt(ciphertext, &decypted)); - EXPECT_EQ(plaintext, decypted); + std::string decrypted; + EXPECT_TRUE(encryptor.Decrypt(ciphertext, &decrypted)); + EXPECT_EQ(plaintext, decrypted); } // Not all platforms allow import/generation of symmetric keys with an @@ -530,3 +530,29 @@ TEST(EncryptorTest, EmptyEncrypt) { EXPECT_EQ(expected_ciphertext_hex, base::HexEncode(ciphertext.data(), ciphertext.size())); } + +TEST(EncryptorTest, CipherTextNotMultipleOfBlockSize) { + std::string key = "128=SixteenBytes"; + std::string iv = "Sweet Sixteen IV"; + + scoped_ptr<crypto::SymmetricKey> sym_key(crypto::SymmetricKey::Import( + crypto::SymmetricKey::AES, key)); + ASSERT_TRUE(sym_key.get()); + + crypto::Encryptor encryptor; + // The IV must be exactly as long a the cipher block size. + EXPECT_EQ(16U, iv.size()); + EXPECT_TRUE(encryptor.Init(sym_key.get(), crypto::Encryptor::CBC, iv)); + + // Use a separately allocated array to improve the odds of the memory tools + // catching invalid accesses. + // + // Otherwise when using std::string as the other tests do, accesses several + // bytes off the end of the buffer may fall inside the reservation of + // the string and not be detected. + scoped_ptr<char[]> ciphertext(new char[1]); + + std::string plaintext; + EXPECT_FALSE( + encryptor.Decrypt(base::StringPiece(ciphertext.get(), 1), &plaintext)); +} |