OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/aead_openssl.h" | 5 #include "crypto/aead_openssl.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
11 namespace { | 11 namespace { |
12 | 12 |
13 #if defined(USE_OPENSSL) | |
14 | |
15 TEST(AeadTest, SealOpen) { | 13 TEST(AeadTest, SealOpen) { |
16 crypto::Aead aead(crypto::Aead::AES_128_CTR_HMAC_SHA256); | 14 crypto::Aead aead(crypto::Aead::AES_128_CTR_HMAC_SHA256); |
17 std::string key(aead.KeyLength(), 0); | 15 std::string key(aead.KeyLength(), 0); |
18 aead.Init(&key); | 16 aead.Init(&key); |
19 std::string nonce(aead.NonceLength(), 0); | 17 std::string nonce(aead.NonceLength(), 0); |
20 std::string plaintext("this is the plaintext"); | 18 std::string plaintext("this is the plaintext"); |
21 std::string ad("this is the additional data"); | 19 std::string ad("this is the additional data"); |
22 std::string ciphertext; | 20 std::string ciphertext; |
23 EXPECT_TRUE(aead.Seal(plaintext, nonce, ad, &ciphertext)); | 21 EXPECT_TRUE(aead.Seal(plaintext, nonce, ad, &ciphertext)); |
24 EXPECT_LT(0U, ciphertext.size()); | 22 EXPECT_LT(0U, ciphertext.size()); |
(...skipping 17 matching lines...) Expand all Loading... |
42 std::string ad("this is the additional data"); | 40 std::string ad("this is the additional data"); |
43 std::string ciphertext; | 41 std::string ciphertext; |
44 EXPECT_TRUE(aead.Seal(plaintext, nonce, ad, &ciphertext)); | 42 EXPECT_TRUE(aead.Seal(plaintext, nonce, ad, &ciphertext)); |
45 EXPECT_LT(0U, ciphertext.size()); | 43 EXPECT_LT(0U, ciphertext.size()); |
46 | 44 |
47 std::string decrypted; | 45 std::string decrypted; |
48 EXPECT_FALSE(aead_wrong_key.Open(ciphertext, nonce, ad, &decrypted)); | 46 EXPECT_FALSE(aead_wrong_key.Open(ciphertext, nonce, ad, &decrypted)); |
49 EXPECT_EQ(0U, decrypted.size()); | 47 EXPECT_EQ(0U, decrypted.size()); |
50 } | 48 } |
51 | 49 |
52 #endif | |
53 | |
54 } // namespace | 50 } // namespace |
OLD | NEW |