• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2020 Google LLC
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_bloat/bloat.gni")
17import("$dir_pw_build/python.gni")
18import("$dir_pw_build/python_dist.gni")
19import("$dir_pw_build/python_venv.gni")
20import("$dir_pw_build/target_types.gni")
21import("$dir_pw_unit_test/test.gni")
22
23group("default") {
24  deps = [
25    ":fuzzers(//toolchains:host_fuzz)",
26    ":optimized_libs(//toolchains:host_optimized)",
27    ":python.install",
28    ":tests.run(//toolchains:host_debug)",
29  ]
30}
31
32pw_source_set("cbor_writer") {
33  public = [ "include/dice/cbor_writer.h" ]
34  sources = [ "src/cbor_writer.c" ]
35}
36
37pw_source_set("cbor_reader") {
38  public = [ "include/dice/cbor_reader.h" ]
39  sources = [ "src/cbor_reader.c" ]
40}
41
42config("standalone_ops_config") {
43  include_dirs = [ "//include/dice/config/standalone" ]
44}
45
46pw_static_library("dice_standalone") {
47  public = [
48    "include/dice/dice.h",
49    "include/dice/utils.h",
50  ]
51  sources = [
52    "src/clear_memory.c",
53    "src/dice.c",
54  ]
55  all_dependent_configs = [ ":standalone_ops_config" ]
56}
57
58config("boringssl_ed25519_ops_config") {
59  include_dirs = [ "//include/dice/config/boringssl_ed25519" ]
60}
61
62config("boringssl_ecdsa_p384_ops_config") {
63  include_dirs = [ "//include/dice/config/boringssl_ecdsa_p384" ]
64}
65
66pw_static_library("dice_with_boringssl_ed25519_ops") {
67  public = [
68    "include/dice/dice.h",
69    "include/dice/utils.h",
70  ]
71  sources = [
72    "src/boringssl_cert_op.c",
73    "src/boringssl_ed25519_ops.c",
74    "src/boringssl_hash_kdf_ops.c",
75    "src/clear_memory.c",
76    "src/dice.c",
77    "src/utils.c",
78  ]
79  deps = [ "//third_party/boringssl:crypto" ]
80  all_dependent_configs = [ ":boringssl_ed25519_ops_config" ]
81}
82
83pw_static_library("dice_with_boringssl_p384_ops") {
84  public = [
85    "include/dice/dice.h",
86    "include/dice/utils.h",
87  ]
88  sources = [
89    "src/boringssl_cert_op.c",
90    "src/boringssl_hash_kdf_ops.c",
91    "src/boringssl_p384_ops.c",
92    "src/clear_memory.c",
93    "src/dice.c",
94    "src/utils.c",
95  ]
96  deps = [ "//third_party/boringssl:crypto" ]
97  all_dependent_configs = [ ":boringssl_ecdsa_p384_ops_config" ]
98}
99
100config("mbedtls_ops_config") {
101  include_dirs = [ "//include//dice/config/mbedtls_ecdsa_p256" ]
102  defines = [ "MBEDTLS_ALLOW_PRIVATE_ACCESS" ]
103}
104
105pw_static_library("dice_with_mbedtls_ops") {
106  public = [
107    "include/dice/dice.h",
108    "include/dice/utils.h",
109  ]
110  sources = [
111    "src/clear_memory.c",
112    "src/dice.c",
113    "src/mbedtls_ops.c",
114    "src/utils.c",
115  ]
116  deps = [ "//third_party/mbedtls:mbedcrypto" ]
117  all_dependent_configs = [ ":mbedtls_ops_config" ]
118}
119
120pw_static_library("dice_with_cbor_ed25519_cert") {
121  public = [
122    "include/dice/dice.h",
123    "include/dice/utils.h",
124  ]
125  sources = [
126    "src/boringssl_ed25519_ops.c",
127    "src/boringssl_hash_kdf_ops.c",
128    "src/cbor_cert_op.c",
129    "src/cbor_ed25519_cert_op.c",
130    "src/clear_memory.c",
131    "src/dice.c",
132    "src/utils.c",
133  ]
134  deps = [
135    ":cbor_writer",
136    "//third_party/boringssl:crypto",
137  ]
138  all_dependent_configs = [ ":boringssl_ed25519_ops_config" ]
139}
140
141pw_static_library("boringssl_ecdsa_utils") {
142  public = [
143    "include/dice/boringssl_ecdsa_utils.h",
144    "include/dice/dice.h",
145    "include/dice/utils.h",
146  ]
147  sources = [ "src/boringssl_ecdsa_utils.c" ]
148  deps = [ "//third_party/boringssl:crypto" ]
149}
150
151pw_static_library("dice_with_cbor_p384_cert") {
152  public = [
153    "include/dice/dice.h",
154    "include/dice/utils.h",
155  ]
156  sources = [
157    "src/boringssl_hash_kdf_ops.c",
158    "src/boringssl_p384_ops.c",
159    "src/cbor_cert_op.c",
160    "src/cbor_p384_cert_op.c",
161    "src/clear_memory.c",
162    "src/dice.c",
163    "src/utils.c",
164  ]
165  deps = [
166    ":boringssl_ecdsa_utils",
167    ":cbor_writer",
168    "//third_party/boringssl:crypto",
169  ]
170  all_dependent_configs = [ ":boringssl_ecdsa_p384_ops_config" ]
171}
172
173pw_static_library("dice_with_cbor_template_ed25519_cert") {
174  public = [
175    "include/dice/dice.h",
176    "include/dice/utils.h",
177  ]
178  sources = [
179    "src/boringssl_ed25519_ops.c",
180    "src/boringssl_hash_kdf_ops.c",
181    "src/clear_memory.c",
182    "src/dice.c",
183    "src/template_cbor_cert_op.c",
184    "src/utils.c",
185  ]
186  deps = [ "//third_party/boringssl:crypto" ]
187  all_dependent_configs = [ ":boringssl_ed25519_ops_config" ]
188}
189
190pw_static_library("dice_with_x509_template_cert") {
191  public = [
192    "include/dice/dice.h",
193    "include/dice/utils.h",
194  ]
195  sources = [
196    "src/boringssl_ed25519_ops.c",
197    "src/boringssl_hash_kdf_ops.c",
198    "src/clear_memory.c",
199    "src/dice.c",
200    "src/template_cert_op.c",
201    "src/utils.c",
202  ]
203  deps = [ "//third_party/boringssl:crypto" ]
204  all_dependent_configs = [ ":boringssl_ed25519_ops_config" ]
205}
206
207pw_source_set("fuzzer") {
208  public = [
209    "include/dice/dice.h",
210    "include/dice/utils.h",
211  ]
212  sources = [ "src/fuzzer.cc" ]
213}
214
215pw_test("cbor_writer_test") {
216  sources = [ "src/cbor_writer_test.cc" ]
217  deps = [ ":cbor_writer" ]
218}
219
220pw_test("cbor_reader_test") {
221  sources = [ "src/cbor_reader_test.cc" ]
222  deps = [ ":cbor_reader" ]
223}
224
225pw_executable("cbor_writer_fuzzer") {
226  sources = [ "src/cbor_writer_fuzzer.cc" ]
227  deps = [ ":cbor_writer" ]
228}
229
230pw_executable("cbor_reader_fuzzer") {
231  sources = [ "src/cbor_reader_fuzzer.cc" ]
232  deps = [ ":cbor_reader" ]
233}
234
235pw_test("dice_test") {
236  sources = [ "src/dice_test.cc" ]
237  deps = [
238    ":dice_standalone",
239    "//third_party/boringssl:crypto",
240  ]
241}
242
243pw_test("boringssl_ed25519_ops_test") {
244  sources = [
245    "src/boringssl_ed25519_ops_test.cc",
246    "src/test_utils.cc",
247  ]
248  deps = [
249    ":boringssl_ecdsa_utils",
250    ":dice_with_boringssl_ed25519_ops",
251    "$dir_pw_string:pw_string",
252    "//third_party/boringssl:crypto",
253    "//third_party/cose-c:cose-c_ed25519",
254  ]
255}
256
257pw_executable("boringssl_ed25519_ops_fuzzer") {
258  deps = [
259    ":dice_with_boringssl_ed25519_ops",
260    ":fuzzer",
261  ]
262}
263
264pw_executable("boringssl_p384_ops_fuzzer") {
265  deps = [
266    ":dice_with_boringssl_p384_ops",
267    ":fuzzer",
268  ]
269}
270
271pw_test("template_cert_op_test") {
272  sources = [
273    "src/template_cert_op_test.cc",
274    "src/test_utils.cc",
275  ]
276  deps = [
277    ":boringssl_ecdsa_utils",
278    ":dice_with_x509_template_cert",
279    "$dir_pw_string:pw_string",
280    "//third_party/boringssl:crypto",
281    "//third_party/cose-c:cose-c_ed25519",
282  ]
283}
284
285pw_executable("template_cert_op_fuzzer") {
286  deps = [
287    ":dice_with_x509_template_cert",
288    ":fuzzer",
289  ]
290}
291
292pw_test("cbor_ed25519_cert_op_test") {
293  sources = [
294    "src/cbor_cert_op_test.cc",
295    "src/test_utils.cc",
296  ]
297  deps = [
298    ":boringssl_ecdsa_utils",
299    ":dice_with_cbor_ed25519_cert",
300    "$dir_pw_string:pw_string",
301    "//third_party/boringssl:crypto",
302    "//third_party/cose-c:cose-c_ed25519",
303  ]
304}
305
306pw_test("cbor_p384_cert_op_test") {
307  sources = [
308    "src/cbor_p384_cert_op_test.cc",
309    "src/test_utils.cc",
310  ]
311  deps = [
312    ":boringssl_ecdsa_utils",
313    ":dice_with_cbor_p384_cert",
314    "$dir_pw_string:pw_string",
315    "//third_party/boringssl:crypto",
316    "//third_party/cose-c:cose-c_p384",
317  ]
318}
319
320pw_executable("cbor_ed25519_cert_op_fuzzer") {
321  deps = [
322    ":dice_with_cbor_ed25519_cert",
323    ":fuzzer",
324  ]
325}
326
327pw_test("template_cbor_ed25519_cert_op_test") {
328  sources = [
329    "src/template_cbor_cert_op_test.cc",
330    "src/test_utils.cc",
331  ]
332  deps = [
333    ":boringssl_ecdsa_utils",
334    ":dice_with_cbor_template_ed25519_cert",
335    "$dir_pw_string:pw_string",
336    "//third_party/boringssl:crypto",
337    "//third_party/cose-c:cose-c_ed25519",
338  ]
339}
340
341pw_executable("template_cbor_ed25519_cert_op_fuzzer") {
342  deps = [
343    ":dice_with_cbor_template_ed25519_cert",
344    ":fuzzer",
345  ]
346}
347
348pw_test("mbedtls_ops_test") {
349  sources = [
350    "src/mbedtls_ops_test.cc",
351    "src/test_utils.cc",
352  ]
353  deps = [
354    ":boringssl_ecdsa_utils",
355    ":dice_with_mbedtls_ops",
356    "$dir_pw_string:pw_string",
357    "//third_party/boringssl:crypto",
358    "//third_party/cose-c:cose-c_ed25519",
359  ]
360}
361
362pw_executable("mbedtls_ops_fuzzer") {
363  deps = [
364    ":dice_with_mbedtls_ops",
365    ":fuzzer",
366  ]
367}
368
369pw_static_library("dice_android") {
370  public = [
371    "//include/dice/dice.h",
372    "//include/dice/utils.h",
373  ]
374  sources = [ "src/android.c" ]
375  deps = [
376    ":cbor_reader",
377    ":cbor_writer",
378    ":dice_with_cbor_ed25519_cert",
379  ]
380}
381
382pw_test("android_test") {
383  sources = [ "src/android_test.cc" ]
384  deps = [ ":dice_android" ]
385}
386
387pw_executable("android_fuzzer") {
388  sources = [ "src/android_fuzzer.cc" ]
389  deps = [ ":dice_android" ]
390}
391
392pw_test_group("tests") {
393  tests = [
394    ":android_test",
395    ":boringssl_ed25519_ops_test",
396    ":cbor_ed25519_cert_op_test",
397    ":cbor_p384_cert_op_test",
398    ":cbor_reader_test",
399    ":cbor_writer_test",
400    ":dice_test",
401    ":mbedtls_ops_test",
402    ":template_cbor_ed25519_cert_op_test",
403    ":template_cert_op_test",
404  ]
405}
406
407group("fuzzers") {
408  deps = [
409    ":android_fuzzer",
410    ":boringssl_ed25519_ops_fuzzer",
411    ":boringssl_p384_ops_fuzzer",
412    ":cbor_ed25519_cert_op_fuzzer",
413    ":cbor_reader_fuzzer",
414    ":cbor_writer_fuzzer",
415    ":mbedtls_ops_fuzzer",
416    ":template_cbor_ed25519_cert_op_fuzzer",
417    ":template_cert_op_fuzzer",
418  ]
419}
420
421pw_static_library("empty_lib") {
422}
423
424pw_executable("empty_main") {
425  sources = [ "src/empty_main.c" ]
426}
427
428pw_executable("dice_standalone_main") {
429  sources = [ "src/dice_standalone_main.c" ]
430  deps = [ ":dice_standalone" ]
431}
432
433pw_source_set("dice_main") {
434  public = [
435    "include/dice/dice.h",
436    "include/dice/utils.h",
437  ]
438  sources = [ "src/dice_main.c" ]
439}
440
441pw_executable("dice_with_boringssl_ed25519_ops_main") {
442  deps = [
443    ":dice_main",
444    ":dice_with_boringssl_ed25519_ops",
445  ]
446}
447
448pw_executable("dice_with_mbedtls_ops_main") {
449  deps = [
450    ":dice_main",
451    ":dice_with_mbedtls_ops",
452  ]
453}
454
455pw_executable("dice_with_cbor_cert_main") {
456  deps = [
457    ":dice_main",
458    ":dice_with_cbor_ed25519_cert",
459  ]
460}
461
462pw_executable("dice_with_cbor_template_ed25519_cert_main") {
463  deps = [
464    ":dice_main",
465    ":dice_with_cbor_template_ed25519_cert",
466  ]
467}
468
469pw_executable("dice_with_x509_template_cert_main") {
470  deps = [
471    ":dice_main",
472    ":dice_with_x509_template_cert",
473  ]
474}
475
476pw_size_diff("executable_size_report") {
477  title = "Executable sizes (includes thirdparty deps)"
478  base = ":empty_main"
479  binaries = [
480    {
481      target = ":dice_standalone_main"
482      label = "DiceMainFlow only (No Ops)"
483    },
484    {
485      target = ":dice_with_boringssl_ed25519_ops_main"
486      label = "Boringssl Ed25519 Ops"
487      base = ":dice_standalone_main"
488    },
489    {
490      target = ":dice_with_mbedtls_ops_main"
491      label = "MbedTLS Ops"
492      base = ":dice_standalone_main"
493    },
494    {
495      target = ":dice_with_cbor_cert_main"
496      label = "Boringssl with CBOR Cert"
497      base = ":dice_with_boringssl_ed25519_ops_main"
498    },
499    {
500      target = ":dice_with_cbor_template_ed25519_cert_main"
501      label = "Boringssl with CBOR Template Ed25519 Cert"
502      base = ":dice_with_boringssl_ed25519_ops_main"
503    },
504    {
505      target = ":dice_with_x509_template_cert_main"
506      label = "Boringssl with X.509 Template Cert"
507      base = ":dice_with_boringssl_ed25519_ops_main"
508    },
509  ]
510}
511
512pw_size_diff("library_size_report") {
513  title = "Library sizes (excludes thirdparty deps)"
514  base = ":empty_lib"
515  binaries = [
516    {
517      target = ":dice_standalone"
518      label = "DICE Standalone (No Ops)"
519    },
520    {
521      target = ":dice_with_boringssl_ed25519_ops"
522      label = "Boringssl Ops"
523      base = ":dice_standalone"
524    },
525    {
526      target = ":dice_with_mbedtls_ops"
527      label = "MbedTLS Ops"
528      base = ":dice_standalone"
529    },
530    {
531      target = ":dice_with_cbor_ed25519_cert"
532      label = "CBOR Cert"
533      base = ":dice_standalone"
534    },
535    {
536      target = ":dice_with_cbor_p384_cert"
537      label = "CBOR P384 Cert"
538      base = ":dice_standalone"
539    },
540    {
541      target = ":dice_with_cbor_template_ed25519_cert"
542      label = "CBOR Template Cert"
543      base = ":dice_standalone"
544    },
545    {
546      target = ":dice_with_x509_template_cert"
547      label = "X.509 Template Cert"
548      base = ":dice_standalone"
549    },
550  ]
551}
552
553group("optimized_libs") {
554  deps = [
555    ":dice_android",
556    ":dice_standalone",
557    ":dice_with_boringssl_ed25519_ops",
558    ":dice_with_cbor_ed25519_cert",
559    ":dice_with_cbor_p384_cert",
560    ":dice_with_cbor_template_ed25519_cert",
561    ":dice_with_mbedtls_ops",
562    ":dice_with_x509_template_cert",
563    ":executable_size_report",
564    ":library_size_report",
565  ]
566}
567
568# This group is built during bootstrap to setup the interactive Python
569# environment.
570pw_python_group("python") {
571  python_deps = [ ":pip_install_open_dice_tools" ]
572}
573
574# In-tree Python packages
575_open_dice_python_packages = [ "//tools:tools" ]
576
577# Pigweed Python packages to include
578_pigweed_python_packages = [ "$dir_pw_env_setup:core_pigweed_python_packages" ]
579
580_all_python_packages = _open_dice_python_packages + _pigweed_python_packages
581
582# The default venv for Python actions in GN
583# Set this gn arg in a declare_args block in this file 'BUILD.gn' or in '.gn' to
584# use this venv.
585#
586#   pw_build_PYTHON_BUILD_VENV = "//:open_dice_build_venv"
587#
588pw_python_venv("open_dice_build_venv") {
589  path = "$root_build_dir/python-venv"
590  constraints = pw_build_PIP_CONSTRAINTS
591  requirements = pw_build_PIP_REQUIREMENTS
592
593  # Ensure all third party Python dependencies are installed into this venv.
594  # This works by checking the setup.cfg files for all packages listed here and
595  # installing the packages listed in the [options].install_requires field.
596  source_packages = _all_python_packages
597}
598
599# This template collects all python packages and their dependencies into a
600# single super Python package for installation into the bootstrapped virtual
601# environment.
602pw_python_distribution("generate_open_dice_tools_python_distribution") {
603  packages = _all_python_packages
604  generate_setup_cfg = {
605    name = "open-dice-tools"
606    version = "0.0.1"
607    append_date_to_version = true
608    include_default_pyproject_file = true
609  }
610}
611
612# Install the open-dice-tools super Python package into the bootstrapped Python
613# venv.
614pw_internal_pip_install("pip_install_open_dice_tools") {
615  packages = [ ":generate_open_dice_tools_python_distribution" ]
616}
617