xref: /aosp_15_r20/external/cronet/crypto/BUILD.gn (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1# Copyright 2013 The Chromium Authors
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import("//build/buildflag_header.gni")
6import("//build/config/chromeos/ui_mode.gni")
7import("//components/nacl/toolchain.gni")
8import("//crypto/features.gni")
9import("//testing/test.gni")
10
11buildflag_header("buildflags") {
12  header = "crypto_buildflags.h"
13  flags = [ "USE_NSS_CERTS=$use_nss_certs" ]
14}
15
16component("crypto") {
17  output_name = "crcrypto"  # Avoid colliding with OpenSSL's libcrypto.
18  sources = [
19    "aead.cc",
20    "aead.h",
21    "crypto_export.h",
22    "ec_private_key.cc",
23    "ec_private_key.h",
24    "ec_signature_creator.cc",
25    "ec_signature_creator.h",
26    "ec_signature_creator_impl.cc",
27    "ec_signature_creator_impl.h",
28    "encryptor.cc",
29    "encryptor.h",
30    "features.cc",
31    "features.h",
32    "hkdf.cc",
33    "hkdf.h",
34    "hmac.cc",
35    "hmac.h",
36    "openssl_util.cc",
37    "openssl_util.h",
38    "p224_spake.cc",
39    "p224_spake.h",
40    "random.cc",
41    "random.h",
42    "rsa_private_key.cc",
43    "rsa_private_key.h",
44    "scoped_nss_types.h",
45    "secure_hash.cc",
46    "secure_hash.h",
47    "secure_util.cc",
48    "secure_util.h",
49    "sha2.cc",
50    "sha2.h",
51    "signature_creator.cc",
52    "signature_creator.h",
53    "signature_verifier.cc",
54    "signature_verifier.h",
55    "symmetric_key.cc",
56    "symmetric_key.h",
57    "unexportable_key.cc",
58    "unexportable_key.h",
59    "unexportable_key_metrics.cc",
60    "unexportable_key_metrics.h",
61    "unexportable_key_software_unsecure.cc",
62    "user_verifying_key.cc",
63    "user_verifying_key.h",
64  ]
65
66  deps = []
67
68  public_deps = [
69    ":buildflags",
70    "//base",
71    "//third_party/boringssl",
72  ]
73
74  if (is_apple) {
75    sources += [
76      "apple_keychain.h",
77      "apple_keychain_util.h",
78      "apple_keychain_util.mm",
79      "apple_keychain_v2.h",
80      "apple_keychain_v2.mm",
81    ]
82
83    if (is_mac) {
84      sources += [
85        "apple_keychain_mac.cc",
86        "mac_security_services_lock.cc",
87        "mac_security_services_lock.h",
88        "scoped_lacontext.h",
89        "scoped_lacontext.mm",
90        "unexportable_key_mac.h",
91        "unexportable_key_mac.mm",
92        "user_verifying_key_mac.mm",
93      ]
94    } else if (is_ios) {
95      sources += [ "apple_keychain_ios.mm" ]
96    }
97
98    frameworks = [
99      "LocalAuthentication.framework",
100      "CoreFoundation.framework",
101      "CryptoTokenKit.framework",
102      "Foundation.framework",
103      "Security.framework",
104    ]
105  }
106
107  if (is_win) {
108    sources += [
109      "scoped_capi_types.h",
110      "scoped_cng_types.h",
111      "unexportable_key_win.cc",
112      "unexportable_key_win.h",
113      "user_verifying_key_win.cc",
114    ]
115    libs = [ "ncrypt.lib" ]
116  }
117
118  # Some files are built when NSS is used for the platform certificate library.
119  if (use_nss_certs) {
120    sources += [
121      "nss_crypto_module_delegate.h",
122      "nss_key_util.cc",
123      "nss_key_util.h",
124      "nss_util.cc",
125      "nss_util.h",
126      "nss_util_internal.h",
127    ]
128    deps += [
129      "//build:chromeos_buildflags",
130      "//components/nacl/common:buildflags",
131    ]
132    configs += [ "//build/config/linux/nss" ]
133  }
134
135  if (is_chromeos_ash && !is_minimal_toolchain) {
136    sources += [ "nss_util_chromeos.cc" ]
137  }
138
139  if (is_chromeos && !is_minimal_toolchain) {
140    sources += [
141      "chaps_support.cc",
142      "chaps_support.h",
143    ]
144  }
145
146  defines = [ "CRYPTO_IMPLEMENTATION" ]
147}
148
149if (is_apple) {
150  source_set("mock_apple_keychain") {
151    sources = [
152      "mock_apple_keychain.cc",
153      "mock_apple_keychain.h",
154    ]
155
156    if (is_mac) {
157      sources += [ "mock_apple_keychain_mac.cc" ]
158    } else if (is_ios) {
159      sources += [ "mock_apple_keychain_ios.cc" ]
160    }
161
162    deps = [
163      ":crypto",
164      "//base",
165    ]
166  }
167}
168
169test("crypto_unittests") {
170  sources = [
171    "aead_unittest.cc",
172    "ec_private_key_unittest.cc",
173    "ec_signature_creator_unittest.cc",
174    "encryptor_unittest.cc",
175    "hmac_unittest.cc",
176    "p224_spake_unittest.cc",
177    "random_unittest.cc",
178    "rsa_private_key_unittest.cc",
179    "secure_hash_unittest.cc",
180    "sha2_unittest.cc",
181    "signature_creator_unittest.cc",
182    "signature_verifier_unittest.cc",
183    "symmetric_key_unittest.cc",
184    "unexportable_key_unittest.cc",
185  ]
186
187  if (is_win || is_mac) {
188    sources += [ "unexportable_key_metrics_unittest.cc" ]
189  }
190
191  if (is_mac) {
192    sources += [
193      "apple_keychain_util_unittest.mm",
194      "unexportable_key_mac_unittest.mm",
195      "user_verifying_key_mac_unittest.mm",
196    ]
197  }
198
199  # Some files are built when NSS is used for the platform certificate library.
200  if (use_nss_certs) {
201    sources += [
202      "nss_key_util_unittest.cc",
203      "nss_util_unittest.cc",
204    ]
205    configs += [ "//build/config/linux/nss" ]
206  }
207
208  deps = [
209    ":crypto",
210    ":test_support",
211    "//base",
212    "//base/test:run_all_unittests",
213    "//base/test:test_support",
214    "//testing/gmock",
215    "//testing/gtest",
216  ]
217}
218
219static_library("test_support") {
220  testonly = true
221  sources = [
222    "scoped_fake_user_verifying_key_provider.cc",
223    "scoped_fake_user_verifying_key_provider.h",
224    "scoped_mock_unexportable_key_provider.cc",
225    "scoped_mock_unexportable_key_provider.h",
226  ]
227
228  if (use_nss_certs) {
229    sources += [
230      "scoped_test_nss_db.cc",
231      "scoped_test_nss_db.h",
232    ]
233    configs += [ "//build/config/linux/nss" ]
234  }
235
236  if (is_chromeos_ash) {
237    sources += [
238      "scoped_test_nss_chromeos_user.cc",
239      "scoped_test_nss_chromeos_user.h",
240      "scoped_test_system_nss_key_slot.cc",
241      "scoped_test_system_nss_key_slot.h",
242    ]
243  }
244
245  if (is_mac) {
246    sources += [
247      "fake_apple_keychain_v2.h",
248      "fake_apple_keychain_v2.mm",
249      "scoped_fake_apple_keychain_v2.h",
250      "scoped_fake_apple_keychain_v2.mm",
251    ]
252    frameworks = [
253      "CoreFoundation.framework",
254      "Foundation.framework",
255      "LocalAuthentication.framework",
256      "Security.framework",
257    ]
258  }
259
260  deps = [
261    ":crypto",
262    "//base",
263  ]
264}
265