// Copyright (c) 2013 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "quiche/quic/core/crypto/aes_128_gcm_12_decrypter.h" #include <memory> #include <string> #include "absl/base/macros.h" #include "absl/strings/escaping.h" #include "absl/strings/string_view.h" #include "quiche/quic/core/quic_utils.h" #include "quiche/quic/platform/api/quic_test.h" #include "quiche/quic/test_tools/quic_test_utils.h" #include "quiche/common/test_tools/quiche_test_utils.h" namespace { // The AES GCM test vectors come from the file gcmDecrypt128.rsp // downloaded from http://csrc.nist.gov/groups/STM/cavp/index.html on // 2013-02-01. The test vectors in that file look like this: // // [Keylen = 128] // [IVlen = 96] // [PTlen = 0] // [AADlen = 0] // [Taglen = 128] // // Count = 0 // Key = cf063a34d4a9a76c2c86787d3f96db71 // IV = 113b9785971864c83b01c787 // CT = // AAD = // Tag = 72ac8493e3a5228b5d130a69d2510e42 // PT = // // Count = 1 // Key = a49a5e26a2f8cb63d05546c2a62f5343 // IV = 907763b19b9b4ab6bd4f0281 // CT = // AAD = // Tag = a2be08210d8c470a8df6e8fbd79ec5cf // FAIL // // ... // // The gcmDecrypt128.rsp file is huge (2.6 MB), so I selected just a // few test vectors for this unit test. // Describes a group of test vectors that all have a given key length, IV // length, plaintext length, AAD length, and tag length. struct TestGroupInfo { … }; // Each test vector consists of six strings of lowercase hexadecimal digits. // The strings may be empty (zero length). A test vector with a nullptr |key| // marks the end of an array of test vectors. struct TestVector { … }; const TestGroupInfo test_group_info[] = …; const TestVector test_group_0[] = …; const TestVector test_group_1[] = …; const TestVector test_group_2[] = …; const TestVector test_group_3[] = …; const TestVector test_group_4[] = …; const TestVector test_group_5[] = …; const TestVector* const test_group_array[] = …; } // namespace namespace quic { namespace test { // DecryptWithNonce wraps the |Decrypt| method of |decrypter| to allow passing // in an nonce and also to allocate the buffer needed for the plaintext. QuicData* DecryptWithNonce(Aes128Gcm12Decrypter* decrypter, absl::string_view nonce, absl::string_view associated_data, absl::string_view ciphertext) { … } class Aes128Gcm12DecrypterTest : public QuicTest { … }; TEST_F(Aes128Gcm12DecrypterTest, Decrypt) { … } } // namespace test } // namespace quic