Add ICU message format support
[chromium-blink-merge.git] / third_party / boringssl / boringssl_unittest.cc
blob75b9db80bfcb6a58775ae712354acab01746570a
1 // Copyright 2014 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.
5 #include <stdarg.h>
7 #include <string>
9 #include "base/base_paths.h"
10 #include "base/command_line.h"
11 #include "base/files/file_path.h"
12 #include "base/logging.h"
13 #include "base/path_service.h"
14 #include "base/process/launch.h"
15 #include "base/strings/string_util.h"
16 #include "testing/gtest/include/gtest/gtest.h"
18 namespace {
20 void TestProcess(const std::string& name,
21 const std::vector<base::CommandLine::StringType>& args) {
22 base::FilePath exe_dir;
23 ASSERT_TRUE(PathService::Get(base::DIR_EXE, &exe_dir));
24 base::FilePath test_binary =
25 exe_dir.AppendASCII("boringssl_" + name);
26 base::CommandLine cmd(test_binary);
28 for (size_t i = 0; i < args.size(); ++i) {
29 cmd.AppendArgNative(args[i]);
32 std::string output;
33 EXPECT_TRUE(base::GetAppOutput(cmd, &output));
34 // Account for Windows line endings.
35 base::ReplaceSubstringsAfterOffset(&output, 0, "\r\n", "\n");
37 const bool ok = output.size() >= 5 &&
38 memcmp("PASS\n", &output[output.size() - 5], 5) == 0 &&
39 (output.size() == 5 || output[output.size() - 6] == '\n');
41 EXPECT_TRUE(ok) << output;
44 void TestSimple(const std::string& name) {
45 std::vector<base::CommandLine::StringType> empty;
46 TestProcess(name, empty);
49 bool BoringSSLPath(base::FilePath* result) {
50 if (!PathService::Get(base::DIR_SOURCE_ROOT, result))
51 return false;
53 *result = result->Append(FILE_PATH_LITERAL("third_party"));
54 *result = result->Append(FILE_PATH_LITERAL("boringssl"));
55 *result = result->Append(FILE_PATH_LITERAL("src"));
56 return true;
59 bool CryptoCipherTestPath(base::FilePath *result) {
60 if (!BoringSSLPath(result))
61 return false;
63 *result = result->Append(FILE_PATH_LITERAL("crypto"));
64 *result = result->Append(FILE_PATH_LITERAL("cipher"));
65 *result = result->Append(FILE_PATH_LITERAL("test"));
66 return true;
69 } // anonymous namespace
71 struct AEADTest {
72 const base::CommandLine::CharType *name;
73 const base::FilePath::CharType *test_vector_filename;
76 static const AEADTest kAEADTests[] = {
77 {FILE_PATH_LITERAL("aes-128-gcm"),
78 FILE_PATH_LITERAL("aes_128_gcm_tests.txt")},
79 {FILE_PATH_LITERAL("aes-128-key-wrap"),
80 FILE_PATH_LITERAL("aes_128_key_wrap_tests.txt")},
81 {FILE_PATH_LITERAL("aes-256-gcm"),
82 FILE_PATH_LITERAL("aes_256_gcm_tests.txt")},
83 {FILE_PATH_LITERAL("aes-256-key-wrap"),
84 FILE_PATH_LITERAL("aes_256_key_wrap_tests.txt")},
85 {FILE_PATH_LITERAL("chacha20-poly1305"),
86 FILE_PATH_LITERAL("chacha20_poly1305_tests.txt")},
87 {FILE_PATH_LITERAL("rc4-md5-tls"),
88 FILE_PATH_LITERAL("rc4_md5_tls_tests.txt")},
89 {FILE_PATH_LITERAL("rc4-sha1-tls"),
90 FILE_PATH_LITERAL("rc4_sha1_tls_tests.txt")},
91 {FILE_PATH_LITERAL("aes-128-cbc-sha1-tls"),
92 FILE_PATH_LITERAL("aes_128_cbc_sha1_tls_tests.txt")},
93 {FILE_PATH_LITERAL("aes-128-cbc-sha1-tls-implicit-iv"),
94 FILE_PATH_LITERAL("aes_128_cbc_sha1_tls_implicit_iv_tests.txt")},
95 {FILE_PATH_LITERAL("aes-128-cbc-sha256-tls"),
96 FILE_PATH_LITERAL("aes_128_cbc_sha256_tls_tests.txt")},
97 {FILE_PATH_LITERAL("aes-256-cbc-sha1-tls"),
98 FILE_PATH_LITERAL("aes_256_cbc_sha1_tls_tests.txt")},
99 {FILE_PATH_LITERAL("aes-256-cbc-sha1-tls-implicit-iv"),
100 FILE_PATH_LITERAL("aes_256_cbc_sha1_tls_implicit_iv_tests.txt")},
101 {FILE_PATH_LITERAL("aes-256-cbc-sha256-tls"),
102 FILE_PATH_LITERAL("aes_256_cbc_sha256_tls_tests.txt")},
103 {FILE_PATH_LITERAL("aes-256-cbc-sha384-tls"),
104 FILE_PATH_LITERAL("aes_256_cbc_sha384_tls_tests.txt")},
105 {FILE_PATH_LITERAL("des-ede3-cbc-sha1-tls"),
106 FILE_PATH_LITERAL("des_ede3_cbc_sha1_tls_tests.txt")},
107 {FILE_PATH_LITERAL("des-ede3-cbc-sha1-tls-implicit-iv"),
108 FILE_PATH_LITERAL("des_ede3_cbc_sha1_tls_implicit_iv_tests.txt")},
109 {FILE_PATH_LITERAL("rc4-md5-ssl3"),
110 FILE_PATH_LITERAL("rc4_md5_ssl3_tests.txt")},
111 {FILE_PATH_LITERAL("rc4-sha1-ssl3"),
112 FILE_PATH_LITERAL("rc4_sha1_ssl3_tests.txt")},
113 {FILE_PATH_LITERAL("aes-128-cbc-sha1-ssl3"),
114 FILE_PATH_LITERAL("aes_128_cbc_sha1_ssl3_tests.txt")},
115 {FILE_PATH_LITERAL("aes-256-cbc-sha1-ssl3"),
116 FILE_PATH_LITERAL("aes_256_cbc_sha1_ssl3_tests.txt")},
117 {FILE_PATH_LITERAL("des-ede3-cbc-sha1-ssl3"),
118 FILE_PATH_LITERAL("des_ede3_cbc_sha1_ssl3_tests.txt")},
119 {FILE_PATH_LITERAL("aes-128-ctr-hmac-sha256"),
120 FILE_PATH_LITERAL("aes_128_ctr_hmac_sha256.txt")},
121 {FILE_PATH_LITERAL("aes-256-ctr-hmac-sha256"),
122 FILE_PATH_LITERAL("aes_256_ctr_hmac_sha256.txt")},
125 TEST(BoringSSL, AEADs) {
126 base::FilePath test_vector_dir;
127 ASSERT_TRUE(CryptoCipherTestPath(&test_vector_dir));
129 for (size_t i = 0; i < arraysize(kAEADTests); i++) {
130 const AEADTest& test = kAEADTests[i];
131 SCOPED_TRACE(test.name);
133 base::FilePath test_vector_file =
134 test_vector_dir.Append(test.test_vector_filename);
136 std::vector<base::CommandLine::StringType> args;
137 args.push_back(test.name);
138 args.push_back(test_vector_file.value());
140 TestProcess("aead_test", args);
144 TEST(BoringSSL, AES) {
145 TestSimple("aes_test");
148 TEST(BoringSSL, Base64) {
149 TestSimple("base64_test");
152 TEST(BoringSSL, BIO) {
153 TestSimple("bio_test");
156 TEST(BoringSSL, BN) {
157 TestSimple("bn_test");
160 TEST(BoringSSL, ByteString) {
161 TestSimple("bytestring_test");
164 TEST(BoringSSL, Cipher) {
165 base::FilePath data_file;
166 ASSERT_TRUE(CryptoCipherTestPath(&data_file));
167 data_file = data_file.Append(FILE_PATH_LITERAL("cipher_test.txt"));
169 std::vector<base::CommandLine::StringType> args;
170 args.push_back(data_file.value());
172 TestProcess("cipher_test", args);
175 TEST(BoringSSL, CMAC) {
176 TestSimple("cmac_test");
179 TEST(BoringSSL, ConstantTime) {
180 TestSimple("constant_time_test");
183 TEST(BoringSSL, DH) {
184 TestSimple("dh_test");
187 TEST(BoringSSL, Digest) {
188 TestSimple("digest_test");
191 TEST(BoringSSL, DSA) {
192 TestSimple("dsa_test");
195 TEST(BoringSSL, EC) {
196 TestSimple("ec_test");
199 TEST(BoringSSL, ECDSA) {
200 TestSimple("ecdsa_test");
203 TEST(BoringSSL, ERR) {
204 TestSimple("err_test");
207 TEST(BoringSSL, EVP) {
208 base::FilePath data_file;
209 ASSERT_TRUE(BoringSSLPath(&data_file));
210 data_file = data_file.Append(FILE_PATH_LITERAL("crypto"));
211 data_file = data_file.Append(FILE_PATH_LITERAL("evp"));
212 data_file = data_file.Append(FILE_PATH_LITERAL("evp_tests.txt"));
214 std::vector<base::CommandLine::StringType> args;
215 args.push_back(data_file.value());
217 TestProcess("evp_test", args);
220 TEST(BoringSSL, EVPExtra) {
221 TestSimple("evp_extra_test");
224 TEST(BoringSSL, ExampleMul) {
225 TestSimple("example_mul");
228 TEST(BoringSSL, GCM) {
229 TestSimple("gcm_test");
232 TEST(BoringSSL, HKDF) {
233 TestSimple("hkdf_test");
236 TEST(BoringSSL, HMAC) {
237 base::FilePath data_file;
238 ASSERT_TRUE(BoringSSLPath(&data_file));
239 data_file = data_file.Append(FILE_PATH_LITERAL("crypto"));
240 data_file = data_file.Append(FILE_PATH_LITERAL("hmac"));
241 data_file = data_file.Append(FILE_PATH_LITERAL("hmac_tests.txt"));
243 std::vector<base::CommandLine::StringType> args;
244 args.push_back(data_file.value());
246 TestProcess("hmac_test", args);
249 TEST(BoringSSL, LH) {
250 TestSimple("lhash_test");
253 TEST(BoringSSL, PBKDF) {
254 TestSimple("pbkdf_test");
257 TEST(BoringSSL, Poly1305) {
258 base::FilePath data_file;
259 ASSERT_TRUE(BoringSSLPath(&data_file));
260 data_file = data_file.Append(FILE_PATH_LITERAL("crypto"));
261 data_file = data_file.Append(FILE_PATH_LITERAL("poly1305"));
262 data_file = data_file.Append(FILE_PATH_LITERAL("poly1305_test.txt"));
264 std::vector<base::CommandLine::StringType> args;
265 args.push_back(data_file.value());
267 TestProcess("poly1305_test", args);
270 TEST(BoringSSL, PKCS7) {
271 TestSimple("pkcs7_test");
274 TEST(BoringSSL, PKCS12) {
275 TestSimple("pkcs12_test");
278 TEST(BoringSSL, PQueue) {
279 TestSimple("pqueue_test");
282 TEST(BoringSSL, RefcountTest) {
283 TestSimple("refcount_test");
286 TEST(BoringSSL, RSA) {
287 TestSimple("rsa_test");
290 TEST(BoringSSL, SSL) {
291 TestSimple("ssl_test");
294 TEST(BoringSSL, TabTest) {
295 TestSimple("tab_test");
298 TEST(BoringSSL, Thread) {
299 TestSimple("thread_test");
302 TEST(BoringSSL, V3NameTest) {
303 TestSimple("v3name_test");