// Copyright (c) 2017 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_256_gcm_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 gcmDecrypt256.rsp // downloaded from // https://csrc.nist.gov/Projects/Cryptographic-Algorithm-Validation-Program/CAVP-TESTING-BLOCK-CIPHER-MODES#GCMVS // on 2017-09-27. The test vectors in that file look like this: // // [Keylen = 256] // [IVlen = 96] // [PTlen = 0] // [AADlen = 0] // [Taglen = 128] // // Count = 0 // Key = f5a2b27c74355872eb3ef6c5feafaa740e6ae990d9d48c3bd9bb8235e589f010 // IV = 58d2240f580a31c1d24948e9 // CT = // AAD = // Tag = 15e051a5e4a5f5da6cea92e2ebee5bac // PT = // // Count = 1 // Key = e5a8123f2e2e007d4e379ba114a2fb66e6613f57c72d4e4f024964053028a831 // IV = 51e43385bf533e168427e1ad // CT = // AAD = // Tag = 38fe845c66e66bdd884c2aecafd280e6 // FAIL // // ... // // The gcmDecrypt256.rsp file is huge (3.0 MB), so a few test vectors were // selected 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(Aes256GcmDecrypter* decrypter, absl::string_view nonce, absl::string_view associated_data, absl::string_view ciphertext) { … } class Aes256GcmDecrypterTest : public QuicTest { … }; TEST_F(Aes256GcmDecrypterTest, Decrypt) { … } TEST_F(Aes256GcmDecrypterTest, GenerateHeaderProtectionMask) { … } } // namespace test } // namespace quic