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.
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"
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
]);
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
))
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"));
59 bool CryptoCipherTestPath(base::FilePath
*result
) {
60 if (!BoringSSLPath(result
))
63 *result
= result
->Append(FILE_PATH_LITERAL("crypto"));
64 *result
= result
->Append(FILE_PATH_LITERAL("cipher"));
65 *result
= result
->Append(FILE_PATH_LITERAL("test"));
69 } // anonymous namespace
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
, Base64
) {
145 TestSimple("base64_test");
148 TEST(BoringSSL
, BIO
) {
149 TestSimple("bio_test");
152 TEST(BoringSSL
, BN
) {
153 TestSimple("bn_test");
156 TEST(BoringSSL
, ByteString
) {
157 TestSimple("bytestring_test");
160 TEST(BoringSSL
, Cipher
) {
161 base::FilePath data_file
;
162 ASSERT_TRUE(CryptoCipherTestPath(&data_file
));
163 data_file
= data_file
.Append(FILE_PATH_LITERAL("cipher_test.txt"));
165 std::vector
<base::CommandLine::StringType
> args
;
166 args
.push_back(data_file
.value());
168 TestProcess("cipher_test", args
);
171 TEST(BoringSSL
, CMAC
) {
172 TestSimple("cmac_test");
175 TEST(BoringSSL
, ConstantTime
) {
176 TestSimple("constant_time_test");
179 TEST(BoringSSL
, DH
) {
180 TestSimple("dh_test");
183 TEST(BoringSSL
, Digest
) {
184 TestSimple("digest_test");
187 TEST(BoringSSL
, DSA
) {
188 TestSimple("dsa_test");
191 TEST(BoringSSL
, EC
) {
192 TestSimple("ec_test");
195 TEST(BoringSSL
, ECDSA
) {
196 TestSimple("ecdsa_test");
199 TEST(BoringSSL
, ERR
) {
200 TestSimple("err_test");
203 TEST(BoringSSL
, EVP
) {
204 base::FilePath data_file
;
205 ASSERT_TRUE(BoringSSLPath(&data_file
));
206 data_file
= data_file
.Append(FILE_PATH_LITERAL("crypto"));
207 data_file
= data_file
.Append(FILE_PATH_LITERAL("evp"));
208 data_file
= data_file
.Append(FILE_PATH_LITERAL("evp_tests.txt"));
210 std::vector
<base::CommandLine::StringType
> args
;
211 args
.push_back(data_file
.value());
213 TestProcess("evp_test", args
);
216 // evp_test is also run on hmac_test's input.
217 TEST(BoringSSL
, EVPHMAC
) {
218 base::FilePath data_file
;
219 ASSERT_TRUE(BoringSSLPath(&data_file
));
220 data_file
= data_file
.Append(FILE_PATH_LITERAL("crypto"));
221 data_file
= data_file
.Append(FILE_PATH_LITERAL("hmac"));
222 data_file
= data_file
.Append(FILE_PATH_LITERAL("hmac_tests.txt"));
224 std::vector
<base::CommandLine::StringType
> args
;
225 args
.push_back(data_file
.value());
227 TestProcess("evp_test", args
);
230 TEST(BoringSSL
, EVPExtra
) {
231 TestSimple("evp_extra_test");
234 TEST(BoringSSL
, ExampleMul
) {
235 TestSimple("example_mul");
238 TEST(BoringSSL
, GCM
) {
239 TestSimple("gcm_test");
242 TEST(BoringSSL
, HKDF
) {
243 TestSimple("hkdf_test");
246 TEST(BoringSSL
, HMAC
) {
247 base::FilePath data_file
;
248 ASSERT_TRUE(BoringSSLPath(&data_file
));
249 data_file
= data_file
.Append(FILE_PATH_LITERAL("crypto"));
250 data_file
= data_file
.Append(FILE_PATH_LITERAL("hmac"));
251 data_file
= data_file
.Append(FILE_PATH_LITERAL("hmac_tests.txt"));
253 std::vector
<base::CommandLine::StringType
> args
;
254 args
.push_back(data_file
.value());
256 TestProcess("hmac_test", args
);
259 TEST(BoringSSL
, LH
) {
260 TestSimple("lhash_test");
263 TEST(BoringSSL
, PBKDF
) {
264 TestSimple("pbkdf_test");
267 TEST(BoringSSL
, PKCS7
) {
268 TestSimple("pkcs7_test");
271 TEST(BoringSSL
, PKCS12
) {
272 TestSimple("pkcs12_test");
275 TEST(BoringSSL
, PQueue
) {
276 TestSimple("pqueue_test");
279 TEST(BoringSSL
, RefcountTest
) {
280 TestSimple("refcount_test");
283 TEST(BoringSSL
, RSA
) {
284 TestSimple("rsa_test");
287 TEST(BoringSSL
, SSL
) {
288 TestSimple("ssl_test");
291 TEST(BoringSSL
, TabTest
) {
292 TestSimple("tab_test");
295 TEST(BoringSSL
, Thread
) {
296 TestSimple("thread_test");
299 TEST(BoringSSL
, V3NameTest
) {
300 TestSimple("v3name_test");