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. 4 5 #include <stdarg.h> 6 7 #include <string> 8 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" 16 17 namespace { 18 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); 26 27 for (size_t i = 0; i < args.size(); ++i) { 28 cmd.AppendArgNative(args[i]); 29 } 30 31 std::string output; 32 EXPECT_TRUE(base::GetAppOutput(cmd, &output)); 33 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'); 37 38 EXPECT_TRUE(ok) << output; 39 } 40 41 void TestSimple(const std::string& name) { 42 std::vector<base::CommandLine::StringType> empty; 43 TestProcess(name, empty); 44 } 45 46 bool BoringSSLPath(base::FilePath* result) { 47 if (!PathService::Get(base::DIR_SOURCE_ROOT, result)) 48 return false; 49 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")); 53 return true; 54 } 55 56 bool CryptoCipherPath(base::FilePath *result) { 57 if (!BoringSSLPath(result)) 58 return false; 59 60 *result = result->Append(FILE_PATH_LITERAL("crypto")); 61 *result = result->Append(FILE_PATH_LITERAL("cipher")); 62 return true; 63 } 64 65 } // anonymous namespace 66 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")); 71 72 std::vector<base::CommandLine::StringType> args; 73 args.push_back(FILE_PATH_LITERAL("aes-128-gcm")); 74 args.push_back(data_file.value()); 75 76 TestProcess("aead_test", args); 77 } 78 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")); 83 84 std::vector<base::CommandLine::StringType> args; 85 args.push_back(FILE_PATH_LITERAL("aes-256-gcm")); 86 args.push_back(data_file.value()); 87 88 TestProcess("aead_test", args); 89 } 90 91 TEST(BoringSSL, ChaCha20Poly1305) { 92 base::FilePath data_file; 93 ASSERT_TRUE(CryptoCipherPath(&data_file)); 94 data_file = 95 data_file.Append(FILE_PATH_LITERAL("chacha20_poly1305_tests.txt")); 96 97 std::vector<base::CommandLine::StringType> args; 98 args.push_back(FILE_PATH_LITERAL("chacha20-poly1305")); 99 args.push_back(data_file.value()); 100 101 TestProcess("aead_test", args); 102 } 103 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")); 108 109 std::vector<base::CommandLine::StringType> args; 110 args.push_back(FILE_PATH_LITERAL("rc4-md5")); 111 args.push_back(data_file.value()); 112 113 TestProcess("aead_test", args); 114 } 115 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")); 120 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()); 124 125 TestProcess("aead_test", args); 126 } 127 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")); 132 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()); 136 137 TestProcess("aead_test", args); 138 } 139 140 TEST(BoringSSL, Base64) { 141 TestSimple("base64_test"); 142 } 143 144 TEST(BoringSSL, BIO) { 145 TestSimple("bio_test"); 146 } 147 148 TEST(BoringSSL, BN) { 149 TestSimple("bn_test"); 150 } 151 152 TEST(BoringSSL, ByteString) { 153 TestSimple("bytestring_test"); 154 } 155 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")); 160 161 std::vector<base::CommandLine::StringType> args; 162 args.push_back(data_file.value()); 163 164 TestProcess("cipher_test", args); 165 } 166 167 TEST(BoringSSL, DH) { 168 TestSimple("dh_test"); 169 } 170 171 TEST(BoringSSL, DSA) { 172 TestSimple("dsa_test"); 173 } 174 175 TEST(BoringSSL, ECDSA) { 176 TestSimple("ecdsa_test"); 177 } 178 179 TEST(BoringSSL, ERR) { 180 TestSimple("err_test"); 181 } 182 183 TEST(BoringSSL, GCM) { 184 TestSimple("gcm_test"); 185 } 186 187 TEST(BoringSSL, HMAC) { 188 TestSimple("hmac_test"); 189 } 190 191 TEST(BoringSSL, LH) { 192 TestSimple("lhash_test"); 193 } 194 195 TEST(BoringSSL, MD5) { 196 TestSimple("md5_test"); 197 } 198 199 TEST(BoringSSL, RSA) { 200 TestSimple("rsa_test"); 201 } 202 203 TEST(BoringSSL, SHA1) { 204 TestSimple("sha1_test"); 205 } 206 207 TEST(BoringSSL, PKCS7) { 208 TestSimple("pkcs7_test"); 209 } 210 211 TEST(BoringSSL, PKCS12) { 212 TestSimple("pkcs12_test"); 213 } 214 215 TEST(BoringSSL, ExampleMul) { 216 TestSimple("example_mul"); 217 } 218 219 TEST(BoringSSL, ExampleSign) { 220 TestSimple("example_sign"); 221 } 222 223 TEST(BoringSSL, SSL) { 224 TestSimple("ssl_test"); 225 } 226 227 TEST(BoringSSL, PQueue) { 228 TestSimple("pqueue_test"); 229 } 230