xref: /aosp_15_r20/external/pigweed/third_party/mbedtls/BUILD.gn (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1# Copyright 2021 The Pigweed Authors
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may not
4# use this file except in compliance with the License. You may obtain a copy of
5# the License at
6#
7#     https://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations under
13# the License.
14
15import("//build_overrides/pigweed.gni")
16import("$dir_pw_build/target_types.gni")
17import("$dir_pw_toolchain/generate_toolchain.gni")
18import("mbedtls.gni")
19
20if (dir_pw_third_party_mbedtls != "") {
21  # All source files for mbedtls-2.26.0 released on 2021-03-12
22  mbedtls_v2_sources = [
23    "library/aes.c",
24    "library/aesni.c",
25    "library/arc4.c",
26    "library/aria.c",
27    "library/asn1parse.c",
28    "library/asn1write.c",
29    "library/base64.c",
30    "library/bignum.c",
31    "library/blowfish.c",
32    "library/camellia.c",
33    "library/ccm.c",
34    "library/certs.c",
35    "library/chacha20.c",
36    "library/chachapoly.c",
37    "library/cipher.c",
38    "library/cipher_wrap.c",
39    "library/cmac.c",
40    "library/ctr_drbg.c",
41    "library/debug.c",
42    "library/des.c",
43    "library/dhm.c",
44    "library/ecdh.c",
45    "library/ecdsa.c",
46    "library/ecjpake.c",
47    "library/ecp.c",
48    "library/ecp_curves.c",
49    "library/entropy.c",
50    "library/entropy_poll.c",
51    "library/error.c",
52    "library/gcm.c",
53    "library/havege.c",
54    "library/hkdf.c",
55    "library/hmac_drbg.c",
56    "library/md.c",
57    "library/md2.c",
58    "library/md4.c",
59    "library/md5.c",
60    "library/memory_buffer_alloc.c",
61    "library/net_sockets.c",
62    "library/nist_kw.c",
63    "library/oid.c",
64    "library/padlock.c",
65    "library/pem.c",
66    "library/pk.c",
67    "library/pk_wrap.c",
68    "library/pkcs11.c",
69    "library/pkcs12.c",
70    "library/pkcs5.c",
71    "library/pkparse.c",
72    "library/pkwrite.c",
73    "library/platform.c",
74    "library/platform_util.c",
75    "library/poly1305.c",
76    "library/psa_crypto.c",
77    "library/psa_crypto_driver_wrappers.c",
78    "library/psa_crypto_se.c",
79    "library/psa_crypto_slot_management.c",
80    "library/psa_crypto_storage.c",
81    "library/psa_its_file.c",
82    "library/ripemd160.c",
83    "library/rsa.c",
84    "library/rsa_internal.c",
85    "library/sha1.c",
86    "library/sha256.c",
87    "library/sha512.c",
88    "library/ssl_cache.c",
89    "library/ssl_ciphersuites.c",
90    "library/ssl_cli.c",
91    "library/ssl_cookie.c",
92    "library/ssl_msg.c",
93    "library/ssl_srv.c",
94    "library/ssl_ticket.c",
95    "library/ssl_tls.c",
96    "library/ssl_tls13_keys.c",
97    "library/threading.c",
98    "library/timing.c",
99    "library/version.c",
100    "library/version_features.c",
101    "library/x509.c",
102    "library/x509_create.c",
103    "library/x509_crl.c",
104    "library/x509_crt.c",
105    "library/x509_csr.c",
106    "library/x509write_crt.c",
107    "library/x509write_csr.c",
108    "library/xtea.c",
109  ]
110
111  # All source files for mbedtls-3.2.1 released on 2022-07-12
112  mbedtls_v3_sources = [
113    "library/aes.c",
114    "library/aesce.c",
115    "library/aesni.c",
116    "library/aria.c",
117    "library/asn1parse.c",
118    "library/asn1write.c",
119    "library/base64.c",
120    "library/bignum.c",
121    "library/bignum_core.c",
122    "library/bignum_mod.c",
123    "library/bignum_mod_raw.c",
124    "library/camellia.c",
125    "library/ccm.c",
126    "library/chacha20.c",
127    "library/chachapoly.c",
128    "library/cipher.c",
129    "library/cipher_wrap.c",
130    "library/cmac.c",
131    "library/constant_time.c",
132    "library/ctr_drbg.c",
133    "library/debug.c",
134    "library/des.c",
135    "library/dhm.c",
136    "library/ecdh.c",
137    "library/ecdsa.c",
138    "library/ecjpake.c",
139    "library/ecp.c",
140    "library/ecp_curves.c",
141    "library/ecp_curves_new.c",
142    "library/entropy.c",
143    "library/entropy_poll.c",
144    "library/error.c",
145    "library/gcm.c",
146    "library/hkdf.c",
147    "library/hmac_drbg.c",
148    "library/lmots.c",
149    "library/lms.c",
150    "library/md.c",
151    "library/md5.c",
152    "library/memory_buffer_alloc.c",
153    "library/mps_reader.c",
154    "library/mps_trace.c",
155    "library/net_sockets.c",
156    "library/nist_kw.c",
157    "library/oid.c",
158    "library/padlock.c",
159    "library/pem.c",
160    "library/pk.c",
161    "library/pk_wrap.c",
162    "library/pkcs12.c",
163    "library/pkcs5.c",
164    "library/pkcs7.c",
165    "library/pkparse.c",
166    "library/pkwrite.c",
167    "library/platform.c",
168    "library/platform_util.c",
169    "library/poly1305.c",
170    "library/psa_crypto.c",
171    "library/psa_crypto_aead.c",
172    "library/psa_crypto_cipher.c",
173    "library/psa_crypto_client.c",
174    "library/psa_crypto_driver_wrappers_no_static.c",
175    "library/psa_crypto_ecp.c",
176    "library/psa_crypto_ffdh.c",
177    "library/psa_crypto_hash.c",
178    "library/psa_crypto_mac.c",
179    "library/psa_crypto_pake.c",
180    "library/psa_crypto_rsa.c",
181    "library/psa_crypto_se.c",
182    "library/psa_crypto_slot_management.c",
183    "library/psa_crypto_storage.c",
184    "library/psa_its_file.c",
185    "library/psa_util.c",
186    "library/ripemd160.c",
187    "library/rsa.c",
188    "library/rsa_alt_helpers.c",
189    "library/sha1.c",
190    "library/sha256.c",
191    "library/sha3.c",
192    "library/sha512.c",
193    "library/ssl_cache.c",
194    "library/ssl_ciphersuites.c",
195    "library/ssl_client.c",
196    "library/ssl_cookie.c",
197    "library/ssl_debug_helpers_generated.c",
198    "library/ssl_msg.c",
199    "library/ssl_ticket.c",
200    "library/ssl_tls.c",
201    "library/ssl_tls12_client.c",
202    "library/ssl_tls12_server.c",
203    "library/ssl_tls13_client.c",
204    "library/ssl_tls13_generic.c",
205    "library/ssl_tls13_keys.c",
206    "library/ssl_tls13_server.c",
207    "library/threading.c",
208    "library/timing.c",
209    "library/version.c",
210    "library/version_features.c",
211    "library/x509.c",
212    "library/x509_create.c",
213    "library/x509_crl.c",
214    "library/x509_crt.c",
215    "library/x509_csr.c",
216    "library/x509write.c",
217    "library/x509write_crt.c",
218    "library/x509write_csr.c",
219  ]
220
221  config("public_config") {
222    include_dirs = [ "$dir_pw_third_party_mbedtls/include" ]
223  }
224
225  config("internal_config") {
226    include_dirs = [
227      "$dir_pw_third_party_mbedtls",
228      "$dir_pw_third_party_mbedtls/include",
229      "$dir_pw_third_party/mbedtls",
230    ]
231    cflags = [
232      "-Wno-error=cast-qual",
233      "-Wno-error=redundant-decls",
234      "-Wno-error=implicit-function-declaration",
235      "-w",
236    ]
237    config_header_file = rebase_path(pw_third_party_mbedtls_CONFIG_HEADER,
238                                     get_label_info(":mbedtls", "dir"))
239    defines = [ "MBEDTLS_CONFIG_FILE=\"$config_header_file\"" ]
240    if (defined(pw_toolchain_SCOPE.is_host_toolchain) &&
241        pw_toolchain_SCOPE.is_host_toolchain) {
242      defines += [ "_PW_MBEDTLS_IS_HOST=1" ]
243    } else {
244      defines += [ "_PW_MBEDTLS_IS_HOST=0" ]
245    }
246  }
247
248  pw_source_set("mbedtls") {
249    # Skip gn check because downstream users may choose either but not
250    # both ":mbedtls" and ":mbedtls_v3" depending on if the underlying
251    # mbedtls git is 2.x or 3.x.
252    check_includes = false
253    sources = []
254    foreach(source, mbedtls_v2_sources) {
255      sources += [ "$dir_pw_third_party_mbedtls/" + source ]
256    }
257
258    public = [
259      "configs/config_default.h",
260      "configs/config_pigweed_common.h",
261    ]
262
263    public_deps = [ "$dir_pw_tls_client:time" ]
264    public_configs = [ ":public_config" ]
265    configs = [ ":internal_config" ]
266  }
267
268  pw_source_set("mbedtls_v3") {
269    # Skip gn check because downstream users may choose either but not
270    # both ":mbedtls" and ":mbedtls_v3" depending on if the underlying
271    # mbedtls git is 2.x or 3.x.
272    check_includes = false
273    sources = []
274    foreach(source, mbedtls_v3_sources) {
275      sources += [ "$dir_pw_third_party_mbedtls/" + source ]
276    }
277
278    public = [
279      "configs/config_default.h",
280      "configs/config_pigweed_common.h",
281    ]
282
283    public_deps = [ "$dir_pw_tls_client:time" ]
284    public_configs = [ ":public_config" ]
285    configs = [ ":internal_config" ]
286  }
287} else {
288  group("mbedtls") {
289  }
290
291  group("mbedtls_v3") {
292  }
293}
294