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