| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "crypto/aead_openssl.h" | |
| 6 | |
| 7 #include <string> | |
| 8 | |
| 9 #include "testing/gtest/include/gtest/gtest.h" | |
| 10 | |
| 11 namespace { | |
| 12 | |
| 13 TEST(AeadTest, SealOpen) { | |
| 14 crypto::Aead aead(crypto::Aead::AES_128_CTR_HMAC_SHA256); | |
| 15 std::string key(aead.KeyLength(), 0); | |
| 16 aead.Init(&key); | |
| 17 std::string nonce(aead.NonceLength(), 0); | |
| 18 std::string plaintext("this is the plaintext"); | |
| 19 std::string ad("this is the additional data"); | |
| 20 std::string ciphertext; | |
| 21 EXPECT_TRUE(aead.Seal(plaintext, nonce, ad, &ciphertext)); | |
| 22 EXPECT_LT(0U, ciphertext.size()); | |
| 23 | |
| 24 std::string decrypted; | |
| 25 EXPECT_TRUE(aead.Open(ciphertext, nonce, ad, &decrypted)); | |
| 26 | |
| 27 EXPECT_EQ(plaintext, decrypted); | |
| 28 } | |
| 29 | |
| 30 TEST(AeadTest, SealOpenWrongKey) { | |
| 31 crypto::Aead aead(crypto::Aead::AES_128_CTR_HMAC_SHA256); | |
| 32 std::string key(aead.KeyLength(), 0); | |
| 33 std::string wrong_key(aead.KeyLength(), 1); | |
| 34 aead.Init(&key); | |
| 35 crypto::Aead aead_wrong_key(crypto::Aead::AES_128_CTR_HMAC_SHA256); | |
| 36 aead_wrong_key.Init(&wrong_key); | |
| 37 | |
| 38 std::string nonce(aead.NonceLength(), 0); | |
| 39 std::string plaintext("this is the plaintext"); | |
| 40 std::string ad("this is the additional data"); | |
| 41 std::string ciphertext; | |
| 42 EXPECT_TRUE(aead.Seal(plaintext, nonce, ad, &ciphertext)); | |
| 43 EXPECT_LT(0U, ciphertext.size()); | |
| 44 | |
| 45 std::string decrypted; | |
| 46 EXPECT_FALSE(aead_wrong_key.Open(ciphertext, nonce, ad, &decrypted)); | |
| 47 EXPECT_EQ(0U, decrypted.size()); | |
| 48 } | |
| 49 | |
| 50 } // namespace | |
| OLD | NEW |