James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 1 | # Copyright (c) 2013 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 | import("//build/config/crypto.gni") |
| 6 | |
| 7 | component("crypto") { |
| 8 | output_name = "crcrypto" # Avoid colliding with OpenSSL's libcrypto. |
| 9 | sources = [ |
| 10 | "apple_keychain.h", |
| 11 | "apple_keychain_ios.mm", |
| 12 | "apple_keychain_mac.mm", |
| 13 | "capi_util.cc", |
| 14 | "capi_util.h", |
| 15 | "crypto_export.h", |
| 16 | "cssm_init.cc", |
| 17 | "cssm_init.h", |
| 18 | "curve25519.cc", |
| 19 | "curve25519-donna.c", |
| 20 | "curve25519.h", |
| 21 | "ec_private_key.h", |
| 22 | "ec_private_key_nss.cc", |
| 23 | "ec_private_key_openssl.cc", |
| 24 | "ec_signature_creator.cc", |
| 25 | "ec_signature_creator.h", |
| 26 | "ec_signature_creator_impl.h", |
| 27 | "ec_signature_creator_nss.cc", |
| 28 | "ec_signature_creator_openssl.cc", |
| 29 | "encryptor.cc", |
| 30 | "encryptor.h", |
| 31 | "encryptor_nss.cc", |
| 32 | "encryptor_openssl.cc", |
| 33 | "ghash.cc", |
| 34 | "ghash.h", |
| 35 | "hkdf.cc", |
| 36 | "hkdf.h", |
| 37 | "hmac.cc", |
| 38 | "hmac.h", |
| 39 | "hmac_nss.cc", |
| 40 | "hmac_openssl.cc", |
| 41 | "mac_security_services_lock.cc", |
| 42 | "mac_security_services_lock.h", |
| 43 | # TODO(brettw) these mocks should be moved to a test_support_crypto target |
| 44 | # if possible. |
| 45 | "mock_apple_keychain.cc", |
| 46 | "mock_apple_keychain.h", |
| 47 | "mock_apple_keychain_ios.cc", |
| 48 | "mock_apple_keychain_mac.cc", |
| 49 | "nss_util.cc", |
| 50 | "nss_util.h", |
| 51 | "nss_util_internal.h", |
James Robinson | 53b7758 | 2014-10-28 17:00:48 -0700 | [diff] [blame] | 52 | "openssl_bio_string.cc", |
| 53 | "openssl_bio_string.h", |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 54 | "openssl_util.cc", |
| 55 | "openssl_util.h", |
| 56 | "p224.cc", |
| 57 | "p224.h", |
| 58 | "p224_spake.cc", |
| 59 | "p224_spake.h", |
| 60 | "random.cc", |
| 61 | "random.h", |
| 62 | "rsa_private_key.cc", |
| 63 | "rsa_private_key.h", |
| 64 | "rsa_private_key_nss.cc", |
| 65 | "rsa_private_key_openssl.cc", |
| 66 | "scoped_capi_types.h", |
| 67 | "scoped_nss_types.h", |
| 68 | "secure_hash_default.cc", |
| 69 | "secure_hash.h", |
| 70 | "secure_hash_openssl.cc", |
| 71 | "secure_util.cc", |
| 72 | "secure_util.h", |
| 73 | "sha2.cc", |
| 74 | "sha2.h", |
| 75 | "signature_creator.h", |
| 76 | "signature_creator_nss.cc", |
| 77 | "signature_creator_openssl.cc", |
| 78 | "signature_verifier.h", |
| 79 | "signature_verifier_nss.cc", |
| 80 | "signature_verifier_openssl.cc", |
| 81 | "symmetric_key.h", |
| 82 | "symmetric_key_nss.cc", |
| 83 | "symmetric_key_openssl.cc", |
| 84 | "third_party/nss/chromium-blapi.h", |
| 85 | "third_party/nss/chromium-blapit.h", |
| 86 | "third_party/nss/chromium-nss.h", |
| 87 | "third_party/nss/chromium-sha256.h", |
| 88 | "third_party/nss/pk11akey.cc", |
| 89 | "third_party/nss/rsawrapr.c", |
| 90 | "third_party/nss/secsign.cc", |
| 91 | "third_party/nss/sha512.cc", |
| 92 | ] |
| 93 | |
| 94 | deps = [ |
| 95 | ":platform", |
| 96 | "//base", |
| 97 | "//base/third_party/dynamic_annotations", |
| 98 | ] |
| 99 | |
| 100 | if (!is_mac && !is_ios) { |
| 101 | sources -= [ |
| 102 | "apple_keychain.h", |
| 103 | "mock_apple_keychain.cc", |
| 104 | "mock_apple_keychain.h", |
| 105 | ] |
| 106 | } |
| 107 | |
| 108 | if (!is_mac) { |
| 109 | sources -= [ |
| 110 | "cssm_init.cc", |
| 111 | "cssm_init.h", |
| 112 | "mac_security_services_lock.cc", |
| 113 | "mac_security_services_lock.h", |
| 114 | ] |
| 115 | } |
| 116 | if (!is_win) { |
| 117 | sources -= [ |
| 118 | "capi_util.cc", |
| 119 | "capi_util.h", |
| 120 | ] |
| 121 | } |
| 122 | |
| 123 | if (is_android) { |
| 124 | deps += [ "//third_party/android_tools:cpu_features" ] |
| 125 | } |
| 126 | |
| 127 | if (use_openssl) { |
| 128 | # Remove NSS files when using OpenSSL |
| 129 | sources -= [ |
| 130 | "ec_private_key_nss.cc", |
| 131 | "ec_signature_creator_nss.cc", |
| 132 | "encryptor_nss.cc", |
| 133 | "hmac_nss.cc", |
| 134 | "nss_util.cc", |
| 135 | "nss_util.h", |
| 136 | "nss_util_internal.h", |
| 137 | "rsa_private_key_nss.cc", |
| 138 | "secure_hash_default.cc", |
| 139 | "signature_creator_nss.cc", |
| 140 | "signature_verifier_nss.cc", |
| 141 | "symmetric_key_nss.cc", |
| 142 | "third_party/nss/chromium-blapi.h", |
| 143 | "third_party/nss/chromium-blapit.h", |
| 144 | "third_party/nss/chromium-nss.h", |
| 145 | "third_party/nss/pk11akey.cc", |
| 146 | "third_party/nss/rsawrapr.c", |
| 147 | "third_party/nss/secsign.cc", |
| 148 | ] |
| 149 | } else { |
| 150 | # Remove OpenSSL when using NSS. |
| 151 | sources -= [ |
| 152 | "ec_private_key_openssl.cc", |
| 153 | "ec_signature_creator_openssl.cc", |
| 154 | "encryptor_openssl.cc", |
| 155 | "hmac_openssl.cc", |
James Robinson | 53b7758 | 2014-10-28 17:00:48 -0700 | [diff] [blame] | 156 | "openssl_bio_string.cc", |
| 157 | "openssl_bio_string.h", |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 158 | "openssl_util.cc", |
| 159 | "openssl_util.h", |
| 160 | "rsa_private_key_openssl.cc", |
| 161 | "secure_hash_openssl.cc", |
| 162 | "signature_creator_openssl.cc", |
| 163 | "signature_verifier_openssl.cc", |
| 164 | "symmetric_key_openssl.cc", |
| 165 | ] |
| 166 | } |
| 167 | |
| 168 | defines = [ "CRYPTO_IMPLEMENTATION" ] |
| 169 | } |
| 170 | |
James Robinson | 6e9a1c9 | 2014-11-13 17:05:42 -0800 | [diff] [blame^] | 171 | # TODO(GYP): TODO(dpranke), fix the compile errors for this stuff |
| 172 | # and make it work. |
| 173 | if (false && is_win) { |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 174 | # A minimal crypto subset for hmac-related stuff that small standalone |
| 175 | # targets can use to reduce code size on Windows. This does not depend on |
| 176 | # OpenSSL/NSS but will use Windows APIs for that functionality. |
| 177 | source_set("crypto_minimal_win") { |
| 178 | sources = [ |
| 179 | "crypto_export.h", |
| 180 | "hmac.cc", |
| 181 | "hmac.h", |
| 182 | "hmac_win.cc", |
| 183 | "scoped_capi_types.h", |
| 184 | "scoped_nss_types.h", |
| 185 | "secure_util.cc", |
| 186 | "secure_util.h", |
| 187 | "symmetric_key.h", |
| 188 | "symmetric_key_win.cc", |
| 189 | "third_party/nss/chromium-blapi.h", |
| 190 | "third_party/nss/chromium-sha256.h", |
| 191 | "third_party/nss/sha512.cc", |
| 192 | ] |
| 193 | |
| 194 | deps = [ |
| 195 | "//base", |
| 196 | "//base/third_party/dynamic_annotations", |
| 197 | ] |
| 198 | |
| 199 | defines = [ "CRYPTO_IMPLEMENTATION" ] |
| 200 | } |
| 201 | } |
| 202 | |
James Robinson | 6e9a1c9 | 2014-11-13 17:05:42 -0800 | [diff] [blame^] | 203 | # TODO(GYP): Make this link on win as well. |
| 204 | if (!is_win) { |
| 205 | test("crypto_unittests") { |
| 206 | sources = [ |
| 207 | # Tests. |
| 208 | "curve25519_unittest.cc", |
| 209 | "ec_private_key_unittest.cc", |
| 210 | "ec_signature_creator_unittest.cc", |
| 211 | "encryptor_unittest.cc", |
| 212 | "ghash_unittest.cc", |
| 213 | "hkdf_unittest.cc", |
| 214 | "hmac_unittest.cc", |
| 215 | "nss_util_unittest.cc", |
| 216 | "openssl_bio_string_unittest.cc", |
| 217 | "p224_unittest.cc", |
| 218 | "p224_spake_unittest.cc", |
| 219 | "random_unittest.cc", |
| 220 | "rsa_private_key_unittest.cc", |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 221 | "rsa_private_key_nss_unittest.cc", |
James Robinson | 6e9a1c9 | 2014-11-13 17:05:42 -0800 | [diff] [blame^] | 222 | "secure_hash_unittest.cc", |
| 223 | "sha2_unittest.cc", |
| 224 | "signature_creator_unittest.cc", |
| 225 | "signature_verifier_unittest.cc", |
| 226 | "symmetric_key_unittest.cc", |
| 227 | ] |
| 228 | |
| 229 | if (use_openssl || !is_linux) { |
| 230 | sources -= [ |
| 231 | "rsa_private_key_nss_unittest.cc", |
| 232 | ] |
| 233 | } |
| 234 | |
| 235 | if (use_openssl) { |
| 236 | sources -= [ "nss_util_unittest.cc" ] |
| 237 | } else { |
| 238 | sources -= [ "openssl_bio_string_unittest.cc" ] |
| 239 | } |
| 240 | |
| 241 | deps = [ |
| 242 | ":crypto", |
| 243 | ":platform", |
| 244 | ":test_support", |
| 245 | "//base", |
| 246 | "//base/test:run_all_unittests", |
| 247 | "//base/test:test_support", |
| 248 | "//testing/gmock", |
| 249 | "//testing/gtest", |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 250 | ] |
| 251 | } |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | source_set("test_support") { |
| 255 | sources = [ |
| 256 | "scoped_test_nss_db.cc", |
| 257 | "scoped_test_nss_db.h", |
| 258 | "scoped_test_nss_chromeos_user.cc", |
| 259 | "scoped_test_nss_chromeos_user.h", |
| 260 | "scoped_test_system_nss_key_slot.cc", |
| 261 | "scoped_test_system_nss_key_slot.h", |
| 262 | ] |
| 263 | deps = [ |
| 264 | ":crypto", |
| 265 | ":platform", |
| 266 | "//base", |
| 267 | ] |
| 268 | |
| 269 | if (!use_nss_certs) { |
| 270 | sources -= [ |
| 271 | "scoped_test_nss_db.cc", |
| 272 | "scoped_test_nss_db.h", |
| 273 | ] |
| 274 | } |
| 275 | |
| 276 | if (!is_chromeos) { |
| 277 | sources -= [ |
| 278 | "scoped_test_nss_chromeos_user.cc", |
| 279 | "scoped_test_nss_chromeos_user.h", |
| 280 | "scoped_test_system_nss_key_slot.cc", |
| 281 | "scoped_test_system_nss_key_slot.h", |
| 282 | ] |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | # This is a meta-target that forwards to NSS's SSL library or OpenSSL, |
| 287 | # according to the state of the crypto flags. A target just wanting to depend |
| 288 | # on the current SSL library should just depend on this. |
| 289 | group("platform") { |
| 290 | if (use_openssl) { |
| 291 | deps = [ "//third_party/boringssl" ] |
| 292 | } else { |
| 293 | deps = [ "//net/third_party/nss/ssl:libssl" ] |
| 294 | if (is_linux) { |
| 295 | # On Linux, we use the system NSS (excepting SSL where we always use our |
| 296 | # own). |
| 297 | # |
| 298 | # We always need our SSL header search path to come before the system one |
| 299 | # so our versions are used. The libssl target will add the search path we |
| 300 | # want, but according to GN's ordering rules, public_configs' search path |
| 301 | # will get applied before ones inherited from our dependencies. |
| 302 | # Therefore, we need to explicitly list our custom libssl's config here |
| 303 | # before the system one. |
| 304 | public_configs = [ |
| 305 | "//net/third_party/nss/ssl:ssl_config", |
| 306 | "//third_party/nss:system_nss_no_ssl_config", |
| 307 | ] |
| 308 | } else { |
| 309 | # Non-Linux platforms use the hermetic NSS from the tree. |
| 310 | deps += [ |
| 311 | "//third_party/nss:nspr", |
| 312 | "//third_party/nss:nss", |
| 313 | ] |
| 314 | } |
| 315 | } |
| 316 | } |