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 "testing/gtest/include/gtest/gtest.h"
19 void TestProcess(const std::string
& name
,
20 const std::vector
<base::CommandLine::StringType
>& args
) {
21 base::FilePath exe_dir
;
22 ASSERT_TRUE(PathService::Get(base::DIR_EXE
, &exe_dir
));
23 base::FilePath test_binary
=
24 exe_dir
.AppendASCII("boringssl_" + name
);
25 base::CommandLine
cmd(test_binary
);
27 for (size_t i
= 0; i
< args
.size(); ++i
) {
28 cmd
.AppendArgNative(args
[i
]);
32 EXPECT_TRUE(base::GetAppOutput(cmd
, &output
));
34 const bool ok
= output
.size() >= 5 &&
35 memcmp("PASS\n", &output
[output
.size() - 5], 5) == 0 &&
36 (output
.size() == 5 || output
[output
.size() - 6] == '\n');
38 EXPECT_TRUE(ok
) << output
;
41 void TestSimple(const std::string
& name
) {
42 std::vector
<base::CommandLine::StringType
> empty
;
43 TestProcess(name
, empty
);
46 bool BoringSSLPath(base::FilePath
* result
) {
47 if (!PathService::Get(base::DIR_SOURCE_ROOT
, result
))
50 *result
= result
->Append(FILE_PATH_LITERAL("third_party"));
51 *result
= result
->Append(FILE_PATH_LITERAL("boringssl"));
52 *result
= result
->Append(FILE_PATH_LITERAL("src"));
56 bool CryptoCipherPath(base::FilePath
*result
) {
57 if (!BoringSSLPath(result
))
60 *result
= result
->Append(FILE_PATH_LITERAL("crypto"));
61 *result
= result
->Append(FILE_PATH_LITERAL("cipher"));
65 } // anonymous namespace
67 TEST(BoringSSL
, AES128GCM
) {
68 base::FilePath data_file
;
69 ASSERT_TRUE(CryptoCipherPath(&data_file
));
70 data_file
= data_file
.Append(FILE_PATH_LITERAL("aes_128_gcm_tests.txt"));
72 std::vector
<base::CommandLine::StringType
> args
;
73 args
.push_back(FILE_PATH_LITERAL("aes-128-gcm"));
74 args
.push_back(data_file
.value());
76 TestProcess("aead_test", args
);
79 TEST(BoringSSL
, AES256GCM
) {
80 base::FilePath data_file
;
81 ASSERT_TRUE(CryptoCipherPath(&data_file
));
82 data_file
= data_file
.Append(FILE_PATH_LITERAL("aes_256_gcm_tests.txt"));
84 std::vector
<base::CommandLine::StringType
> args
;
85 args
.push_back(FILE_PATH_LITERAL("aes-256-gcm"));
86 args
.push_back(data_file
.value());
88 TestProcess("aead_test", args
);
91 TEST(BoringSSL
, ChaCha20Poly1305
) {
92 base::FilePath data_file
;
93 ASSERT_TRUE(CryptoCipherPath(&data_file
));
95 data_file
.Append(FILE_PATH_LITERAL("chacha20_poly1305_tests.txt"));
97 std::vector
<base::CommandLine::StringType
> args
;
98 args
.push_back(FILE_PATH_LITERAL("chacha20-poly1305"));
99 args
.push_back(data_file
.value());
101 TestProcess("aead_test", args
);
104 TEST(BoringSSL
, RC4MD5
) {
105 base::FilePath data_file
;
106 ASSERT_TRUE(CryptoCipherPath(&data_file
));
107 data_file
= data_file
.Append(FILE_PATH_LITERAL("rc4_md5_tests.txt"));
109 std::vector
<base::CommandLine::StringType
> args
;
110 args
.push_back(FILE_PATH_LITERAL("rc4-md5"));
111 args
.push_back(data_file
.value());
113 TestProcess("aead_test", args
);
116 TEST(BoringSSL
, AESKW128
) {
117 base::FilePath data_file
;
118 ASSERT_TRUE(CryptoCipherPath(&data_file
));
119 data_file
= data_file
.Append(FILE_PATH_LITERAL("aes_128_key_wrap_tests.txt"));
121 std::vector
<base::CommandLine::StringType
> args
;
122 args
.push_back(FILE_PATH_LITERAL("aes-128-key-wrap"));
123 args
.push_back(data_file
.value());
125 TestProcess("aead_test", args
);
128 TEST(BoringSSL
, AESKW256
) {
129 base::FilePath data_file
;
130 ASSERT_TRUE(CryptoCipherPath(&data_file
));
131 data_file
= data_file
.Append(FILE_PATH_LITERAL("aes_256_key_wrap_tests.txt"));
133 std::vector
<base::CommandLine::StringType
> args
;
134 args
.push_back(FILE_PATH_LITERAL("aes-256-key-wrap"));
135 args
.push_back(data_file
.value());
137 TestProcess("aead_test", args
);
140 TEST(BoringSSL
, Base64
) {
141 TestSimple("base64_test");
144 TEST(BoringSSL
, BIO
) {
145 TestSimple("bio_test");
148 TEST(BoringSSL
, BN
) {
149 TestSimple("bn_test");
152 TEST(BoringSSL
, ByteString
) {
153 TestSimple("bytestring_test");
156 TEST(BoringSSL
, Cipher
) {
157 base::FilePath data_file
;
158 ASSERT_TRUE(CryptoCipherPath(&data_file
));
159 data_file
= data_file
.Append(FILE_PATH_LITERAL("cipher_test.txt"));
161 std::vector
<base::CommandLine::StringType
> args
;
162 args
.push_back(data_file
.value());
164 TestProcess("cipher_test", args
);
167 TEST(BoringSSL
, DH
) {
168 TestSimple("dh_test");
171 TEST(BoringSSL
, DSA
) {
172 TestSimple("dsa_test");
175 TEST(BoringSSL
, ECDSA
) {
176 TestSimple("ecdsa_test");
179 TEST(BoringSSL
, ERR
) {
180 TestSimple("err_test");
183 TEST(BoringSSL
, GCM
) {
184 TestSimple("gcm_test");
187 TEST(BoringSSL
, HMAC
) {
188 TestSimple("hmac_test");
191 TEST(BoringSSL
, LH
) {
192 TestSimple("lhash_test");
195 TEST(BoringSSL
, MD5
) {
196 TestSimple("md5_test");
199 TEST(BoringSSL
, RSA
) {
200 TestSimple("rsa_test");
203 TEST(BoringSSL
, SHA1
) {
204 TestSimple("sha1_test");
207 TEST(BoringSSL
, PKCS7
) {
208 TestSimple("pkcs7_test");
211 TEST(BoringSSL
, PKCS12
) {
212 TestSimple("pkcs12_test");
215 TEST(BoringSSL
, ExampleMul
) {
216 TestSimple("example_mul");
219 TEST(BoringSSL
, ExampleSign
) {
220 TestSimple("example_sign");
223 TEST(BoringSSL
, SSL
) {
224 TestSimple("ssl_test");
227 TEST(BoringSSL
, PQueue
) {
228 TestSimple("pqueue_test");