1 // Copyright 2021 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 ///////////////////////////////////////////////////////////////////////////////
16 #include "tink/aead/internal/wycheproof_aead.h"
17
18 #include <memory>
19 #include <string>
20 #include <vector>
21
22 #include "absl/strings/str_cat.h"
23 #include "absl/strings/string_view.h"
24 #include "tink/subtle/wycheproof_util.h"
25
26 namespace crypto {
27 namespace tink {
28 namespace internal {
29
30 using ::crypto::tink::subtle::WycheproofUtil;
31
ReadWycheproofTestVectors(absl::string_view file_name)32 std::vector<WycheproofTestVector> ReadWycheproofTestVectors(
33 absl::string_view file_name) {
34 std::unique_ptr<rapidjson::Document> root =
35 WycheproofUtil::ReadTestVectors(std::string(file_name));
36 std::vector<WycheproofTestVector> test_vectors;
37 for (const rapidjson::Value& test_group : (*root)["testGroups"].GetArray()) {
38 for (const rapidjson::Value& test : test_group["tests"].GetArray()) {
39 test_vectors.push_back(WycheproofTestVector{
40 test["comment"].GetString(),
41 WycheproofUtil::GetBytes(test["key"]),
42 WycheproofUtil::GetBytes(test["iv"]),
43 WycheproofUtil::GetBytes(test["msg"]),
44 WycheproofUtil::GetBytes(test["ct"]),
45 WycheproofUtil::GetBytes(test["aad"]),
46 WycheproofUtil::GetBytes(test["tag"]),
47 absl::StrCat(test["tcId"].GetInt()),
48 test["result"].GetString(),
49 });
50 }
51 }
52 return test_vectors;
53 }
54
55 } // namespace internal
56 } // namespace tink
57 } // namespace crypto
58