|
| 1 | +# Copyright lowRISC contributors (OpenTitan project). |
| 2 | +# Licensed under the Apache License, Version 2.0, see LICENSE for details. |
| 3 | +# SPDX-License-Identifier: Apache-2.0 |
| 4 | + |
| 5 | +package(default_visibility = ["//visibility:public"]) |
| 6 | + |
| 7 | +load("@//rules:signing.bzl", "offline_presigning_artifacts", "offline_signature_attach") |
| 8 | +load("//rules:const.bzl", "CONST", "hex") |
| 9 | +load("//rules:manifest.bzl", "manifest") |
| 10 | +load( |
| 11 | + "//rules/opentitan:defs.bzl", |
| 12 | + "opentitan_binary", |
| 13 | + "opentitan_test", |
| 14 | + "silicon_params", |
| 15 | +) |
| 16 | +load( |
| 17 | + "//rules:otp.bzl", |
| 18 | + "STD_OTP_OVERLAYS", |
| 19 | + "otp_hex", |
| 20 | + "otp_image", |
| 21 | + "otp_json", |
| 22 | + "otp_partition", |
| 23 | +) |
| 24 | + |
| 25 | +# Building a wrongly signed BL0 binary for testing the secure boot |
| 26 | +opentitan_binary( |
| 27 | + name = "bl0_firmware", |
| 28 | + testonly = True, |
| 29 | + # This can be any other source of the pentest framework |
| 30 | + srcs = ["//sw/device/tests/penetrationtests/firmware:firmware_cryptolib_fi_sym.c"], |
| 31 | + exec_env = { |
| 32 | + "//hw/top_earlgrey:fpga_cw340_rom_ext": None, |
| 33 | + }, |
| 34 | + deps = [ |
| 35 | + "//sw/device/tests/penetrationtests/firmware/sca:trigger_sca", |
| 36 | + "//sw/device/tests/penetrationtests/firmware/fi:cryptolib_fi_sym", |
| 37 | + "//sw/device/tests/penetrationtests/firmware/lib:extclk_sca_fi", |
| 38 | + "//sw/device/tests/penetrationtests/firmware/lib:pentest_lib", |
| 39 | + "//sw/device/lib/base:csr", |
| 40 | + "//sw/device/lib/base:status", |
| 41 | + "//sw/device/lib/crypto/drivers:entropy", |
| 42 | + "//sw/device/lib/testing/test_framework:check", |
| 43 | + "//sw/device/lib/testing/test_framework:ottf_main", |
| 44 | + "//sw/device/lib/testing/test_framework:ujson_ottf", |
| 45 | + "//sw/device/lib/ujson", |
| 46 | + |
| 47 | + # Include all JSON commands. |
| 48 | + "//sw/device/tests/penetrationtests/json:commands", |
| 49 | + ], |
| 50 | +) |
| 51 | + |
| 52 | +offline_presigning_artifacts( |
| 53 | + name = "non_signed_firmware", |
| 54 | + testonly = True, |
| 55 | + srcs = [":bl0_firmware"], |
| 56 | + ecdsa_key = {"//sw/device/silicon_creator/lib/ownership/keys/fake:app_prod_ecdsa": "prod_key_0"}, |
| 57 | + manifest = "//sw/device/silicon_owner:manifest", |
| 58 | + spx_key = {}, |
| 59 | + tags = ["manual"], |
| 60 | +) |
| 61 | + |
| 62 | +offline_signature_attach( |
| 63 | + name = "wrong_signed_firmware", |
| 64 | + testonly = True, |
| 65 | + srcs = [":non_signed_firmware"], |
| 66 | + # We provide a wrong signature |
| 67 | + ecdsa_signatures = ["bl0_firmware_fpga_cw340_rom_ext.ecdsa_sig"], |
| 68 | + spx_signatures = [], |
| 69 | + tags = ["manual"], |
| 70 | +) |
| 71 | + |
| 72 | +# For when building specialized manifests for security testing. |
| 73 | +manifest(d = { |
| 74 | + "name": "rom_ext_rollback_manifest", |
| 75 | + "identifier": hex(CONST.OWNER), |
| 76 | + "security_version": "0", |
| 77 | + "visibility": ["//visibility:public"], |
| 78 | +}) |
| 79 | + |
| 80 | +otp_json( |
| 81 | + name = "otp_json_rom_ext_fi", |
| 82 | + partitions = [ |
| 83 | + otp_partition( |
| 84 | + name = "CREATOR_SW_CFG", |
| 85 | + items = { |
| 86 | + "CREATOR_SW_CFG_RMA_SPIN_EN": otp_hex(CONST.HARDENED_TRUE), |
| 87 | + # Number of Ibex cycles to spin: we set this to the highest value |
| 88 | + "CREATOR_SW_CFG_RMA_SPIN_CYCLES": "0xffffffff", |
| 89 | + # Enable SPX+ signature verification. |
| 90 | + # TODO: ROM_EXT is not signed with this yet |
| 91 | + # "CREATOR_SW_CFG_SIGVERIFY_SPX_EN": otp_hex(0x0), |
| 92 | + # Turn off the ROM_EXT_IMM |
| 93 | + "CREATOR_SW_CFG_IMMUTABLE_ROM_EXT_EN": otp_hex(0x0), |
| 94 | + # We disable randomness since that messes with GDB |
| 95 | + "CREATOR_SW_CFG_RNG_EN": otp_hex(0x0), |
| 96 | + }, |
| 97 | + ), |
| 98 | + otp_partition( |
| 99 | + name = "SECRET2", |
| 100 | + items = { |
| 101 | + # We set reproducible bitstreams for the tests |
| 102 | + "RMA_TOKEN": "0000000000000005", |
| 103 | + "CREATOR_ROOT_KEY_SHARE0": "1111111111111111111111111111111111111111111111111111111111111111", |
| 104 | + "CREATOR_ROOT_KEY_SHARE1": "2222222222222222222222222222222222222222222222222222222222222222", |
| 105 | + }, |
| 106 | + lock = True, |
| 107 | + ), |
| 108 | + ], |
| 109 | + visibility = ["//visibility:private"], |
| 110 | +) |
| 111 | + |
| 112 | +otp_image( |
| 113 | + name = "otp_img_rom_ext_fi", |
| 114 | + src = "//hw/ip/otp_ctrl/data:otp_json_rma", |
| 115 | + overlays = STD_OTP_OVERLAYS + [ |
| 116 | + ":otp_json_rom_ext_fi", |
| 117 | + ], |
| 118 | +) |
| 119 | + |
| 120 | +otp_json( |
| 121 | + name = "otp_json_rom_rollback_fi", |
| 122 | + partitions = [ |
| 123 | + otp_partition( |
| 124 | + name = "CREATOR_SW_CFG", |
| 125 | + items = { |
| 126 | + "CREATOR_SW_CFG_RMA_SPIN_EN": otp_hex(CONST.HARDENED_TRUE), |
| 127 | + # Number of Ibex cycles to spin: we set this to the highest value |
| 128 | + "CREATOR_SW_CFG_RMA_SPIN_CYCLES": "0xffffffff", |
| 129 | + # We set the version to a higher number to check rollback protection |
| 130 | + "CREATOR_SW_CFG_MIN_SEC_VER_ROM_EXT": "0x1", |
| 131 | + # Enable SPX+ signature verification. |
| 132 | + # TODO: ROM_EXT is not signed with this yet |
| 133 | + # "CREATOR_SW_CFG_SIGVERIFY_SPX_EN": otp_hex(0x0), |
| 134 | + }, |
| 135 | + ), |
| 136 | + otp_partition( |
| 137 | + name = "SECRET2", |
| 138 | + items = { |
| 139 | + # We set reproducible bitstreams for the tests |
| 140 | + "RMA_TOKEN": "0000000000000005", |
| 141 | + "CREATOR_ROOT_KEY_SHARE0": "1111111111111111111111111111111111111111111111111111111111111111", |
| 142 | + "CREATOR_ROOT_KEY_SHARE1": "2222222222222222222222222222222222222222222222222222222222222222", |
| 143 | + }, |
| 144 | + lock = True, |
| 145 | + ), |
| 146 | + ], |
| 147 | + visibility = ["//visibility:private"], |
| 148 | +) |
| 149 | + |
| 150 | +otp_image( |
| 151 | + name = "otp_img_rom_rollback_fi", |
| 152 | + src = "//hw/ip/otp_ctrl/data:otp_json_rma", |
| 153 | + overlays = STD_OTP_OVERLAYS + [ |
| 154 | + ":otp_json_rom_rollback_fi", |
| 155 | + ], |
| 156 | +) |
| 157 | + |
| 158 | +otp_json( |
| 159 | + name = "otp_json_rom_ext_rollback_fi", |
| 160 | + partitions = [ |
| 161 | + otp_partition( |
| 162 | + name = "CREATOR_SW_CFG", |
| 163 | + items = { |
| 164 | + "CREATOR_SW_CFG_RMA_SPIN_EN": otp_hex(CONST.HARDENED_TRUE), |
| 165 | + # Number of Ibex cycles to spin: we set this to the highest value |
| 166 | + "CREATOR_SW_CFG_RMA_SPIN_CYCLES": "0xffffffff", |
| 167 | + # We set the version to a higher number to check rollback protection |
| 168 | + "CREATOR_SW_CFG_MIN_SEC_VER_BL0": "0x2", |
| 169 | + # Enable SPX+ signature verification. |
| 170 | + # TODO: ROM_EXT is not signed with this yet |
| 171 | + # "CREATOR_SW_CFG_SIGVERIFY_SPX_EN": otp_hex(0x0), |
| 172 | + }, |
| 173 | + ), |
| 174 | + otp_partition( |
| 175 | + name = "SECRET2", |
| 176 | + items = { |
| 177 | + # We set reproducible bitstreams for the tests |
| 178 | + "RMA_TOKEN": "0000000000000005", |
| 179 | + "CREATOR_ROOT_KEY_SHARE0": "1111111111111111111111111111111111111111111111111111111111111111", |
| 180 | + "CREATOR_ROOT_KEY_SHARE1": "2222222222222222222222222222222222222222222222222222222222222222", |
| 181 | + }, |
| 182 | + lock = True, |
| 183 | + ), |
| 184 | + ], |
| 185 | + visibility = ["//visibility:private"], |
| 186 | +) |
| 187 | + |
| 188 | +otp_image( |
| 189 | + name = "otp_img_rom_ext_rollback_fi", |
| 190 | + src = "//hw/ip/otp_ctrl/data:otp_json_rma", |
| 191 | + overlays = STD_OTP_OVERLAYS + [ |
| 192 | + ":otp_json_rom_ext_rollback_fi", |
| 193 | + ], |
| 194 | +) |
| 195 | + |
| 196 | +exports_files(["bl0_owner_upgrade.c"]) |
0 commit comments