summaryrefslogtreecommitdiffstats
path: root/crypto/encryptor_unittest.cc
diff options
context:
space:
mode:
authorddorwin@chromium.org <ddorwin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-15 08:11:52 +0000
committerddorwin@chromium.org <ddorwin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-15 08:11:52 +0000
commit45a445210f04343da2a29d4f08e8cea905925b33 (patch)
treebe93e5caef6cca72af3192bf3892e2a82fe8a8c0 /crypto/encryptor_unittest.cc
parent8368a0a348e5e445cefbee7fec023a988f21fa75 (diff)
downloadchromium_src-45a445210f04343da2a29d4f08e8cea905925b33.zip
chromium_src-45a445210f04343da2a29d4f08e8cea905925b33.tar.gz
chromium_src-45a445210f04343da2a29d4f08e8cea905925b33.tar.bz2
Use NSS for symmetric key crypto operations on Windows and Mac.
Encryptor, HMAC, and SymmetricKey now use NSS on all platforms except Android. This allows us to use them inside the sandbox, something that was not possible when using the platform APIs. On Windows, Native Client 64-bit builds still use the the platform APIs. BUG=127803,124741 TEST=Existing tests since there is no change in functionality. Review URL: https://chromiumcodereview.appspot.com/10543146 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@142356 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'crypto/encryptor_unittest.cc')
-rw-r--r--crypto/encryptor_unittest.cc40
1 files changed, 25 insertions, 15 deletions
diff --git a/crypto/encryptor_unittest.cc b/crypto/encryptor_unittest.cc
index ac78b96..b0ec4bc 100644
--- a/crypto/encryptor_unittest.cc
+++ b/crypto/encryptor_unittest.cc
@@ -91,8 +91,8 @@ TEST(EncryptorTest, DecryptWrongKey) {
// invalid. If an implementation simply uses the last padding byte to
// determine the padding length without checking every padding byte,
// Encryptor::Decrypt() will still return true. This is the case for NSS
- // (crbug.com/124434) and Mac OS X 10.7 (crbug.com/127586).
-#if !defined(USE_NSS)
+ // (crbug.com/124434).
+#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));
@@ -113,7 +113,7 @@ TEST(EncryptorTest, DecryptWrongKey) {
}
// CTR mode encryption is only implemented using NSS.
-#if defined(USE_NSS)
+#if defined(USE_NSS) || defined(OS_WIN) || defined(OS_MACOSX)
TEST(EncryptorTest, EncryptDecryptCTR) {
scoped_ptr<crypto::SymmetricKey> key(
@@ -149,11 +149,13 @@ TEST(EncryptorTest, EncryptDecryptCTR) {
TEST(EncryptorTest, CTRCounter) {
const int kCounterSize = 16;
- const char kTest1[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
- uint8 buf[16];
+ const unsigned char kTest1[] =
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+ unsigned char buf[16];
// Increment 10 times.
- crypto::Encryptor::Counter counter1(std::string(kTest1, kCounterSize));
+ crypto::Encryptor::Counter counter1(
+ std::string(reinterpret_cast<const char*>(kTest1), kCounterSize));
for (int i = 0; i < 10; ++i)
counter1.Increment();
counter1.Write(buf);
@@ -161,18 +163,26 @@ TEST(EncryptorTest, CTRCounter) {
EXPECT_TRUE(buf[15] == 10);
// Check corner cases.
- const char kTest2[] = {0, 0, 0, 0, 0, 0, 0, 0,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
- const char kExpect2[] = {0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0};
- crypto::Encryptor::Counter counter2(std::string(kTest2, kCounterSize));
+ const unsigned char kTest2[] = {
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
+ };
+ const unsigned char kExpect2[] =
+ {0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0};
+ crypto::Encryptor::Counter counter2(
+ std::string(reinterpret_cast<const char*>(kTest2), kCounterSize));
counter2.Increment();
counter2.Write(buf);
EXPECT_EQ(0, memcmp(buf, kExpect2, kCounterSize));
- const char kTest3[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
- const char kExpect3[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
- crypto::Encryptor::Counter counter3(std::string(kTest3, kCounterSize));
+ const unsigned char kTest3[] = {
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
+ };
+ const unsigned char kExpect3[] =
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+ crypto::Encryptor::Counter counter3(
+ std::string(reinterpret_cast<const char*>(kTest3), kCounterSize));
counter3.Increment();
counter3.Write(buf);
EXPECT_EQ(0, memcmp(buf, kExpect3, kCounterSize));
@@ -312,7 +322,7 @@ TEST(EncryptorTest, EncryptAES192CBCRegression) {
// Not all platforms allow import/generation of symmetric keys with an
// unsupported size.
-#if !defined(OS_WIN) && !defined(USE_NSS)
+#if !defined(USE_NSS) && !defined(OS_WIN) && !defined(OS_MACOSX)
TEST(EncryptorTest, UnsupportedKeySize) {
std::string key = "7 = bad";
std::string iv = "Sweet Sixteen IV";