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

Side by Side Diff: crypto/encryptor_unittest.cc

Issue 10543146: Use NSS for symmetric key crypto operations on Windows and Mac. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use !defined(USE_OPENSSL) or #else instead of defined(USING_NSS) Created 8 years, 6 months 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "crypto/encryptor.h" 5 #include "crypto/encryptor.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 } 85 }
86 86
87 std::string decypted; 87 std::string decypted;
88 88
89 // This wrong key causes the last padding byte to be 5, which is a valid 89 // This wrong key causes the last padding byte to be 5, which is a valid
90 // padding length, and the second to last padding byte to be 137, which is 90 // padding length, and the second to last padding byte to be 137, which is
91 // invalid. If an implementation simply uses the last padding byte to 91 // invalid. If an implementation simply uses the last padding byte to
92 // determine the padding length without checking every padding byte, 92 // determine the padding length without checking every padding byte,
93 // Encryptor::Decrypt() will still return true. This is the case for NSS 93 // Encryptor::Decrypt() will still return true. This is the case for NSS
94 // (crbug.com/124434) and Mac OS X 10.7 (crbug.com/127586). 94 // (crbug.com/124434) and Mac OS X 10.7 (crbug.com/127586).
95 #if !defined(USE_NSS) 95 #if !defined(USE_NSS) && !defined(OS_WIN) && !defined(OS_MACOSX)
96 crypto::Encryptor decryptor; 96 crypto::Encryptor decryptor;
97 EXPECT_TRUE(decryptor.Init(wrong_key.get(), crypto::Encryptor::CBC, iv)); 97 EXPECT_TRUE(decryptor.Init(wrong_key.get(), crypto::Encryptor::CBC, iv));
98 EXPECT_FALSE(decryptor.Decrypt(ciphertext, &decypted)); 98 EXPECT_FALSE(decryptor.Decrypt(ciphertext, &decypted));
99 #endif 99 #endif
100 100
101 // This demonstrates that not all wrong keys can be detected by padding 101 // This demonstrates that not all wrong keys can be detected by padding
102 // error. This wrong key causes the last padding byte to be 1, which is 102 // error. This wrong key causes the last padding byte to be 1, which is
103 // a valid padding block of length 1. 103 // a valid padding block of length 1.
104 crypto::Encryptor decryptor2; 104 crypto::Encryptor decryptor2;
105 EXPECT_TRUE(decryptor2.Init(wrong_key2.get(), crypto::Encryptor::CBC, iv)); 105 EXPECT_TRUE(decryptor2.Init(wrong_key2.get(), crypto::Encryptor::CBC, iv));
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 crypto::Encryptor encryptor; 351 crypto::Encryptor encryptor;
352 // The IV must be exactly as long a the cipher block size. 352 // The IV must be exactly as long a the cipher block size.
353 EXPECT_EQ(16U, iv.size()); 353 EXPECT_EQ(16U, iv.size());
354 EXPECT_TRUE(encryptor.Init(sym_key.get(), crypto::Encryptor::CBC, iv)); 354 EXPECT_TRUE(encryptor.Init(sym_key.get(), crypto::Encryptor::CBC, iv));
355 355
356 std::string ciphertext; 356 std::string ciphertext;
357 EXPECT_TRUE(encryptor.Encrypt(plaintext, &ciphertext)); 357 EXPECT_TRUE(encryptor.Encrypt(plaintext, &ciphertext));
358 EXPECT_EQ(expected_ciphertext_hex, base::HexEncode(ciphertext.data(), 358 EXPECT_EQ(expected_ciphertext_hex, base::HexEncode(ciphertext.data(),
359 ciphertext.size())); 359 ciphertext.size()));
360 } 360 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698