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("android_profile") { 59 include_dirs = [ "//include/dice/config/android" ] 60} 61 62config("example_profile") { 63 include_dirs = [ "//include/dice/config/example" ] 64} 65 66config("default_profile") { 67 include_dirs = [ "//include/dice/config/default" ] 68} 69 70config("boringssl_ed25519_ops_config") { 71 include_dirs = [ "//include/dice/config/boringssl_ed25519" ] 72} 73 74config("boringssl_ecdsa_p256_ops_config") { 75 include_dirs = [ "//include/dice/config/boringssl_ecdsa_p256" ] 76} 77 78config("boringssl_ecdsa_p384_ops_config") { 79 include_dirs = [ "//include/dice/config/boringssl_ecdsa_p384" ] 80} 81 82config("boringssl_multialg_ops_config") { 83 include_dirs = [ "//include/dice/config/boringssl_multialg" ] 84} 85 86pw_static_library("dice_with_boringssl_ed25519_ops") { 87 public = [ 88 "include/dice/dice.h", 89 "include/dice/utils.h", 90 ] 91 sources = [ 92 "src/boringssl_cert_op.c", 93 "src/boringssl_ed25519_ops.c", 94 "src/boringssl_hash_kdf_ops.c", 95 "src/clear_memory.c", 96 "src/dice.c", 97 "src/utils.c", 98 ] 99 deps = [ "//third_party/boringssl:crypto" ] 100 all_dependent_configs = [ 101 ":boringssl_ed25519_ops_config", 102 ":default_profile", 103 ] 104} 105 106pw_static_library("dice_with_boringssl_p256_ops") { 107 public = [ 108 "include/dice/dice.h", 109 "include/dice/utils.h", 110 ] 111 sources = [ 112 "src/boringssl_cert_op.c", 113 "src/boringssl_hash_kdf_ops.c", 114 "src/boringssl_p256_ops.c", 115 "src/clear_memory.c", 116 "src/dice.c", 117 "src/utils.c", 118 ] 119 deps = [ "//third_party/boringssl:crypto" ] 120 all_dependent_configs = [ 121 ":boringssl_ecdsa_p256_ops_config", 122 ":example_profile", 123 ] 124} 125 126pw_static_library("dice_with_boringssl_p384_ops") { 127 public = [ 128 "include/dice/dice.h", 129 "include/dice/utils.h", 130 ] 131 sources = [ 132 "src/boringssl_cert_op.c", 133 "src/boringssl_hash_kdf_ops.c", 134 "src/boringssl_p384_ops.c", 135 "src/clear_memory.c", 136 "src/dice.c", 137 "src/utils.c", 138 ] 139 deps = [ "//third_party/boringssl:crypto" ] 140 all_dependent_configs = [ 141 ":boringssl_ecdsa_p384_ops_config", 142 ":example_profile", 143 ] 144} 145 146config("mbedtls_ops_config") { 147 include_dirs = [ "//include//dice/config/mbedtls_ecdsa_p256" ] 148 defines = [ "MBEDTLS_ALLOW_PRIVATE_ACCESS" ] 149} 150 151pw_static_library("dice_with_mbedtls_ops") { 152 public = [ 153 "include/dice/dice.h", 154 "include/dice/utils.h", 155 ] 156 sources = [ 157 "src/clear_memory.c", 158 "src/dice.c", 159 "src/mbedtls_ops.c", 160 "src/utils.c", 161 ] 162 deps = [ "//third_party/mbedtls:mbedcrypto" ] 163 all_dependent_configs = [ ":mbedtls_ops_config" ] 164} 165 166pw_static_library("dice_with_cbor_ed25519_cert") { 167 public = [ 168 "include/dice/dice.h", 169 "include/dice/utils.h", 170 ] 171 sources = [ 172 "src/boringssl_ed25519_ops.c", 173 "src/boringssl_hash_kdf_ops.c", 174 "src/cbor_cert_op.c", 175 "src/clear_memory.c", 176 "src/dice.c", 177 "src/utils.c", 178 ] 179 deps = [ 180 ":cbor_writer", 181 "//third_party/boringssl:crypto", 182 ] 183 all_dependent_configs = [ 184 ":boringssl_ed25519_ops_config", 185 ":android_profile", 186 ] 187} 188 189pw_static_library("boringssl_ecdsa_utils") { 190 public = [ 191 "include/dice/boringssl_ecdsa_utils.h", 192 "include/dice/dice.h", 193 "include/dice/utils.h", 194 ] 195 sources = [ "src/boringssl_ecdsa_utils.c" ] 196 deps = [ "//third_party/boringssl:crypto" ] 197} 198 199pw_static_library("dice_with_cbor_p256_cert") { 200 public = [ 201 "include/dice/dice.h", 202 "include/dice/utils.h", 203 ] 204 sources = [ 205 "src/boringssl_hash_kdf_ops.c", 206 "src/boringssl_p256_ops.c", 207 "src/cbor_cert_op.c", 208 "src/clear_memory.c", 209 "src/dice.c", 210 "src/utils.c", 211 ] 212 deps = [ 213 ":boringssl_ecdsa_utils", 214 ":cbor_writer", 215 "//third_party/boringssl:crypto", 216 ] 217 all_dependent_configs = [ 218 ":boringssl_ecdsa_p256_ops_config", 219 ":example_profile", 220 ] 221} 222 223pw_static_library("dice_with_cbor_p384_cert") { 224 public = [ 225 "include/dice/dice.h", 226 "include/dice/utils.h", 227 ] 228 sources = [ 229 "src/boringssl_hash_kdf_ops.c", 230 "src/boringssl_p384_ops.c", 231 "src/cbor_cert_op.c", 232 "src/clear_memory.c", 233 "src/dice.c", 234 "src/utils.c", 235 ] 236 deps = [ 237 ":boringssl_ecdsa_utils", 238 ":cbor_writer", 239 "//third_party/boringssl:crypto", 240 ] 241 all_dependent_configs = [ 242 ":boringssl_ecdsa_p384_ops_config", 243 ":example_profile", 244 ] 245} 246 247pw_static_library("dice_with_cbor_multialg") { 248 public = [ 249 "include/dice/dice.h", 250 "include/dice/utils.h", 251 ] 252 sources = [ 253 "src/boringssl_hash_kdf_ops.c", 254 "src/boringssl_multialg_ops.c", 255 "src/cbor_cert_op.c", 256 "src/clear_memory.c", 257 "src/dice.c", 258 "src/utils.c", 259 ] 260 deps = [ 261 ":boringssl_ecdsa_utils", 262 ":cbor_writer", 263 "//third_party/boringssl:crypto", 264 ] 265 all_dependent_configs = [ 266 ":boringssl_multialg_ops_config", 267 ":android_profile", 268 ] 269} 270 271pw_static_library("dice_with_cbor_template_ed25519_cert") { 272 public = [ 273 "include/dice/dice.h", 274 "include/dice/utils.h", 275 ] 276 sources = [ 277 "src/boringssl_ed25519_ops.c", 278 "src/boringssl_hash_kdf_ops.c", 279 "src/clear_memory.c", 280 "src/dice.c", 281 "src/template_cbor_cert_op.c", 282 "src/utils.c", 283 ] 284 deps = [ "//third_party/boringssl:crypto" ] 285 all_dependent_configs = [ 286 ":boringssl_ed25519_ops_config", 287 ":default_profile", 288 ] 289} 290 291pw_static_library("dice_with_x509_template_cert") { 292 public = [ 293 "include/dice/dice.h", 294 "include/dice/utils.h", 295 ] 296 sources = [ 297 "src/boringssl_ed25519_ops.c", 298 "src/boringssl_hash_kdf_ops.c", 299 "src/clear_memory.c", 300 "src/dice.c", 301 "src/template_cert_op.c", 302 "src/utils.c", 303 ] 304 deps = [ "//third_party/boringssl:crypto" ] 305 all_dependent_configs = [ 306 ":boringssl_ed25519_ops_config", 307 ":default_profile", 308 ] 309} 310 311pw_source_set("fuzzer") { 312 public = [ 313 "include/dice/dice.h", 314 "include/dice/utils.h", 315 ] 316 sources = [ "src/fuzzer.cc" ] 317} 318 319pw_test("cbor_writer_test") { 320 sources = [ "src/cbor_writer_test.cc" ] 321 deps = [ ":cbor_writer" ] 322} 323 324pw_test("cbor_reader_test") { 325 sources = [ "src/cbor_reader_test.cc" ] 326 deps = [ ":cbor_reader" ] 327} 328 329pw_executable("cbor_writer_fuzzer") { 330 sources = [ "src/cbor_writer_fuzzer.cc" ] 331 deps = [ ":cbor_writer" ] 332} 333 334pw_executable("cbor_reader_fuzzer") { 335 sources = [ "src/cbor_reader_fuzzer.cc" ] 336 deps = [ ":cbor_reader" ] 337} 338 339pw_test("dice_test") { 340 sources = [ "src/dice_test.cc" ] 341 deps = [ 342 ":dice_standalone", 343 "//third_party/boringssl:crypto", 344 ] 345} 346 347pw_test("boringssl_ed25519_ops_test") { 348 sources = [ 349 "src/boringssl_ed25519_ops_test.cc", 350 "src/test_utils.cc", 351 ] 352 deps = [ 353 ":boringssl_ecdsa_utils", 354 ":dice_with_boringssl_ed25519_ops", 355 "$dir_pw_string:pw_string", 356 "//third_party/boringssl:crypto", 357 "//third_party/cose-c:cose-c_ed25519", 358 ] 359} 360 361pw_executable("boringssl_ed25519_ops_fuzzer") { 362 deps = [ 363 ":dice_with_boringssl_ed25519_ops", 364 ":fuzzer", 365 ] 366} 367 368pw_executable("boringssl_p256_ops_fuzzer") { 369 deps = [ 370 ":dice_with_boringssl_p256_ops", 371 ":fuzzer", 372 ] 373} 374 375pw_executable("boringssl_p384_ops_fuzzer") { 376 deps = [ 377 ":dice_with_boringssl_p384_ops", 378 ":fuzzer", 379 ] 380} 381 382pw_test("template_cert_op_test") { 383 sources = [ 384 "src/template_cert_op_test.cc", 385 "src/test_utils.cc", 386 ] 387 deps = [ 388 ":boringssl_ecdsa_utils", 389 ":dice_with_x509_template_cert", 390 "$dir_pw_string:pw_string", 391 "//third_party/boringssl:crypto", 392 "//third_party/cose-c:cose-c_ed25519", 393 ] 394} 395 396pw_executable("template_cert_op_fuzzer") { 397 deps = [ 398 ":dice_with_x509_template_cert", 399 ":fuzzer", 400 ] 401} 402 403pw_test("cbor_ed25519_cert_op_test") { 404 sources = [ 405 "src/cbor_cert_op_test.cc", 406 "src/test_utils.cc", 407 ] 408 deps = [ 409 ":boringssl_ecdsa_utils", 410 ":dice_with_cbor_ed25519_cert", 411 "$dir_pw_string:pw_string", 412 "//third_party/boringssl:crypto", 413 "//third_party/cose-c:cose-c_ed25519", 414 ] 415} 416 417pw_test("cbor_p256_cert_op_test") { 418 sources = [ 419 "src/cbor_p256_cert_op_test.cc", 420 "src/test_utils.cc", 421 ] 422 deps = [ 423 ":boringssl_ecdsa_utils", 424 ":dice_with_cbor_p256_cert", 425 "$dir_pw_string:pw_string", 426 "//third_party/boringssl:crypto", 427 "//third_party/cose-c:cose-c_p256", 428 ] 429} 430 431pw_test("cbor_p384_cert_op_test") { 432 sources = [ 433 "src/cbor_p384_cert_op_test.cc", 434 "src/test_utils.cc", 435 ] 436 deps = [ 437 ":boringssl_ecdsa_utils", 438 ":dice_with_cbor_p384_cert", 439 "$dir_pw_string:pw_string", 440 "//third_party/boringssl:crypto", 441 "//third_party/cose-c:cose-c_p384", 442 ] 443} 444 445pw_test("cbor_multialg_op_test") { 446 sources = [ 447 "src/cbor_multialg_op_test.cc", 448 "src/test_utils.cc", 449 ] 450 deps = [ 451 ":boringssl_ecdsa_utils", 452 ":dice_with_cbor_multialg", 453 "$dir_pw_string:pw_string", 454 "//third_party/boringssl:crypto", 455 "//third_party/cose-c:cose-c_multialg", 456 ] 457} 458 459pw_executable("cbor_ed25519_cert_op_fuzzer") { 460 deps = [ 461 ":dice_with_cbor_ed25519_cert", 462 ":fuzzer", 463 ] 464} 465 466pw_test("template_cbor_ed25519_cert_op_test") { 467 sources = [ 468 "src/template_cbor_cert_op_test.cc", 469 "src/test_utils.cc", 470 ] 471 deps = [ 472 ":boringssl_ecdsa_utils", 473 ":dice_with_cbor_template_ed25519_cert", 474 "$dir_pw_string:pw_string", 475 "//third_party/boringssl:crypto", 476 "//third_party/cose-c:cose-c_ed25519", 477 ] 478} 479 480pw_executable("template_cbor_ed25519_cert_op_fuzzer") { 481 deps = [ 482 ":dice_with_cbor_template_ed25519_cert", 483 ":fuzzer", 484 ] 485} 486 487pw_test("mbedtls_ops_test") { 488 sources = [ 489 "src/mbedtls_ops_test.cc", 490 "src/test_utils.cc", 491 ] 492 deps = [ 493 ":boringssl_ecdsa_utils", 494 ":dice_with_mbedtls_ops", 495 "$dir_pw_string:pw_string", 496 "//third_party/boringssl:crypto", 497 "//third_party/cose-c:cose-c_ed25519", 498 ] 499} 500 501pw_executable("mbedtls_ops_fuzzer") { 502 deps = [ 503 ":dice_with_mbedtls_ops", 504 ":fuzzer", 505 ] 506} 507 508pw_static_library("dice_android") { 509 public = [ 510 "//include/dice/dice.h", 511 "//include/dice/utils.h", 512 ] 513 sources = [ "src/android.c" ] 514 deps = [ 515 ":cbor_reader", 516 ":cbor_writer", 517 ":dice_with_cbor_ed25519_cert", 518 ] 519} 520 521pw_test("android_test") { 522 sources = [ "src/android_test.cc" ] 523 deps = [ ":dice_android" ] 524} 525 526pw_executable("android_fuzzer") { 527 sources = [ "src/android_fuzzer.cc" ] 528 deps = [ ":dice_android" ] 529} 530 531pw_test_group("tests") { 532 tests = [ 533 ":android_test", 534 ":boringssl_ed25519_ops_test", 535 ":cbor_ed25519_cert_op_test", 536 ":cbor_p256_cert_op_test", 537 ":cbor_p384_cert_op_test", 538 ":cbor_multialg_op_test", 539 ":cbor_reader_test", 540 ":cbor_writer_test", 541 ":dice_test", 542 ":mbedtls_ops_test", 543 ":template_cbor_ed25519_cert_op_test", 544 ":template_cert_op_test", 545 ] 546} 547 548group("fuzzers") { 549 deps = [ 550 ":android_fuzzer", 551 ":boringssl_ed25519_ops_fuzzer", 552 ":boringssl_p256_ops_fuzzer", 553 ":boringssl_p384_ops_fuzzer", 554 ":cbor_ed25519_cert_op_fuzzer", 555 ":cbor_reader_fuzzer", 556 ":cbor_writer_fuzzer", 557 ":mbedtls_ops_fuzzer", 558 ":template_cbor_ed25519_cert_op_fuzzer", 559 ":template_cert_op_fuzzer", 560 ] 561} 562 563pw_static_library("empty_lib") { 564} 565 566pw_executable("empty_main") { 567 sources = [ "src/empty_main.c" ] 568} 569 570pw_executable("dice_standalone_main") { 571 sources = [ "src/dice_standalone_main.c" ] 572 deps = [ ":dice_standalone" ] 573} 574 575pw_source_set("dice_main") { 576 public = [ 577 "include/dice/dice.h", 578 "include/dice/utils.h", 579 ] 580 sources = [ "src/dice_main.c" ] 581} 582 583pw_executable("dice_with_boringssl_ed25519_ops_main") { 584 deps = [ 585 ":dice_main", 586 ":dice_with_boringssl_ed25519_ops", 587 ] 588} 589 590pw_executable("dice_with_mbedtls_ops_main") { 591 deps = [ 592 ":dice_main", 593 ":dice_with_mbedtls_ops", 594 ] 595} 596 597pw_executable("dice_with_cbor_cert_main") { 598 deps = [ 599 ":dice_main", 600 ":dice_with_cbor_ed25519_cert", 601 ] 602} 603 604pw_executable("dice_with_cbor_template_ed25519_cert_main") { 605 deps = [ 606 ":dice_main", 607 ":dice_with_cbor_template_ed25519_cert", 608 ] 609} 610 611pw_executable("dice_with_x509_template_cert_main") { 612 deps = [ 613 ":dice_main", 614 ":dice_with_x509_template_cert", 615 ] 616} 617 618pw_size_diff("executable_size_report") { 619 title = "Executable sizes (includes thirdparty deps)" 620 base = ":empty_main" 621 binaries = [ 622 { 623 target = ":dice_standalone_main" 624 label = "DiceMainFlow only (No Ops)" 625 }, 626 { 627 target = ":dice_with_boringssl_ed25519_ops_main" 628 label = "Boringssl Ed25519 Ops" 629 base = ":dice_standalone_main" 630 }, 631 { 632 target = ":dice_with_mbedtls_ops_main" 633 label = "MbedTLS Ops" 634 base = ":dice_standalone_main" 635 }, 636 { 637 target = ":dice_with_cbor_cert_main" 638 label = "Boringssl with CBOR Cert" 639 base = ":dice_with_boringssl_ed25519_ops_main" 640 }, 641 { 642 target = ":dice_with_cbor_template_ed25519_cert_main" 643 label = "Boringssl with CBOR Template Ed25519 Cert" 644 base = ":dice_with_boringssl_ed25519_ops_main" 645 }, 646 { 647 target = ":dice_with_x509_template_cert_main" 648 label = "Boringssl with X.509 Template Cert" 649 base = ":dice_with_boringssl_ed25519_ops_main" 650 }, 651 ] 652} 653 654pw_size_diff("library_size_report") { 655 title = "Library sizes (excludes thirdparty deps)" 656 base = ":empty_lib" 657 binaries = [ 658 { 659 target = ":dice_standalone" 660 label = "DICE Standalone (No Ops)" 661 }, 662 { 663 target = ":dice_with_boringssl_ed25519_ops" 664 label = "Boringssl Ops" 665 base = ":dice_standalone" 666 }, 667 { 668 target = ":dice_with_mbedtls_ops" 669 label = "MbedTLS Ops" 670 base = ":dice_standalone" 671 }, 672 { 673 target = ":dice_with_cbor_ed25519_cert" 674 label = "CBOR Cert" 675 base = ":dice_standalone" 676 }, 677 { 678 target = ":dice_with_cbor_p256_cert" 679 label = "CBOR P256 Cert" 680 base = ":dice_standalone" 681 }, 682 { 683 target = ":dice_with_cbor_p384_cert" 684 label = "CBOR P384 Cert" 685 base = ":dice_standalone" 686 }, 687 { 688 target = ":dice_with_cbor_multialg" 689 label = "CBOR Multi-Alg" 690 base = ":dice_standalone" 691 }, 692 { 693 target = ":dice_with_cbor_template_ed25519_cert" 694 label = "CBOR Template Cert" 695 base = ":dice_standalone" 696 }, 697 { 698 target = ":dice_with_x509_template_cert" 699 label = "X.509 Template Cert" 700 base = ":dice_standalone" 701 }, 702 ] 703} 704 705group("optimized_libs") { 706 deps = [ 707 ":dice_android", 708 ":dice_standalone", 709 ":dice_with_boringssl_ed25519_ops", 710 ":dice_with_cbor_ed25519_cert", 711 ":dice_with_cbor_multialg", 712 ":dice_with_cbor_p256_cert", 713 ":dice_with_cbor_p384_cert", 714 ":dice_with_cbor_template_ed25519_cert", 715 ":dice_with_mbedtls_ops", 716 ":dice_with_x509_template_cert", 717 ":executable_size_report", 718 ":library_size_report", 719 ] 720} 721 722# This group is built during bootstrap to setup the interactive Python 723# environment. 724pw_python_group("python") { 725 python_deps = [ ":pip_install_open_dice_tools" ] 726} 727 728# In-tree Python packages 729_open_dice_python_packages = [ "//tools:tools" ] 730 731# Pigweed Python packages to include 732_pigweed_python_packages = [ "$dir_pw_env_setup:core_pigweed_python_packages" ] 733 734_all_python_packages = _open_dice_python_packages + _pigweed_python_packages 735 736# The default venv for Python actions in GN 737# Set this gn arg in a declare_args block in this file 'BUILD.gn' or in '.gn' to 738# use this venv. 739# 740# pw_build_PYTHON_BUILD_VENV = "//:open_dice_build_venv" 741# 742pw_python_venv("open_dice_build_venv") { 743 path = "$root_build_dir/python-venv" 744 constraints = pw_build_PIP_CONSTRAINTS 745 requirements = pw_build_PIP_REQUIREMENTS 746 747 # Ensure all third party Python dependencies are installed into this venv. 748 # This works by checking the setup.cfg files for all packages listed here and 749 # installing the packages listed in the [options].install_requires field. 750 source_packages = _all_python_packages 751} 752 753# This template collects all python packages and their dependencies into a 754# single super Python package for installation into the bootstrapped virtual 755# environment. 756pw_python_distribution("generate_open_dice_tools_python_distribution") { 757 packages = _all_python_packages 758 generate_setup_cfg = { 759 name = "open-dice-tools" 760 version = "0.0.1" 761 append_date_to_version = true 762 include_default_pyproject_file = true 763 } 764} 765 766# Install the open-dice-tools super Python package into the bootstrapped Python 767# venv. 768pw_internal_pip_install("pip_install_open_dice_tools") { 769 packages = [ ":generate_open_dice_tools_python_distribution" ] 770} 771