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

Unified Diff: base/crypto/encryptor_unittest.cc

Issue 4777001: Implements encryptor_openssl.cc (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: lint Created 10 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: base/crypto/encryptor_unittest.cc
diff --git a/base/crypto/encryptor_unittest.cc b/base/crypto/encryptor_unittest.cc
index bc66e55450ffc6e9f75d5ebb488e4d8eb5f1d83f..c560c5044ca7286586aac8772e147945ebe5813f 100644
--- a/base/crypto/encryptor_unittest.cc
+++ b/base/crypto/encryptor_unittest.cc
@@ -8,6 +8,7 @@
#include "base/crypto/symmetric_key.h"
#include "base/scoped_ptr.h"
+#include "base/string_number_conversions.h"
#include "testing/gtest/include/gtest/gtest.h"
TEST(EncryptorTest, EncryptDecrypt) {
@@ -108,3 +109,31 @@ TEST(EncryptorTest, EncryptAES256CBC) {
EXPECT_EQ(plaintext, decypted);
}
+
+// Expected output derived from the NSS implementation.
+TEST(EncryptorTest, EncryptAES128CBCRegression) {
+ std::string key = "128=SixteenBytes";
+ std::string iv = "Sweet Sixteen IV";
+ std::string plaintext = "Plain text with a g-clef U+1D11E \360\235\204\236";
+ std::string expected_ciphertext_hex =
+ "D4A67A0BA33C30F207344D81D1E944BBE65587C3D7D9939A"
+ "C070C62B9C15A3EA312EA4AD1BC7929F4D3C16B03AD5ADA8";
+
+ scoped_ptr<base::SymmetricKey> sym_key(base::SymmetricKey::Import(
+ base::SymmetricKey::AES, key));
+ ASSERT_TRUE(NULL != sym_key.get());
+
+ base::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(), base::Encryptor::CBC, iv));
+
+ std::string ciphertext;
+ EXPECT_TRUE(encryptor.Encrypt(plaintext, &ciphertext));
+ EXPECT_EQ(expected_ciphertext_hex, base::HexEncode(ciphertext.data(),
+ ciphertext.size()));
+
+ std::string decypted;
+ EXPECT_TRUE(encryptor.Decrypt(ciphertext, &decypted));
+ EXPECT_EQ(plaintext, decypted);
+}

Powered by Google App Engine
This is Rietveld 408576698