Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sw, otbn, crypto] Sync with the master branch #23492

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
b0fad20
[otbn, sca] Keep shares in distant registers
Apr 27, 2023
bf7f4d0
[otbn, sca] Modify boolean_to_arithmetic routine against SCA
Apr 25, 2023
a1b43ef
[sca, sha3, kmac] Fix SHA3 captures by properly initializing KMAC config
vogelpi Jul 14, 2023
aefe0f9
[sca] Add batch capture for ECC256 keygen
vrozic Jun 2, 2023
96e6a49
[sw/otbn/crypto] Add arithmetic to boolean masking for P256 ECDH
wettermo Jun 19, 2023
702d67d
[sw/otbn/crypto] Restructure P256 code to prevent IMEM overflow
wettermo Aug 7, 2023
276e325
[sw/crypto] Hardening of P-384 implementation
wettermo Jul 19, 2023
37d4677
[sca] Update the ecdsa384_sca code
bilgiday Aug 4, 2023
4924b55
[sw/crypto] Fix format/comment + remove redundant instr. in P384 sign
wettermo Aug 10, 2023
982594f
[sw/crypto] Add keygen to P-384 implementation
wettermo Aug 10, 2023
f287da0
[sw/crypto] Fix P-256 Random Scalar Generation
wettermo Aug 10, 2023
26d8a24
[sw/crypto] Fix a few comments in P-256 implementation
wettermo Aug 21, 2023
98f4802
[sw/crypto] Add function to reduce numbers by field order p (mod p)
wettermo Aug 21, 2023
42d1205
[sw/crypto] Add arithmetic-to-boolean masking conversion to P-384
wettermo Aug 21, 2023
60828d8
[crypto] Separate large RSA keygen test into multiple targets.
jadephilipoom Sep 20, 2023
dc32044
[crypto] Move verify-only ECDSA-P256 subroutines to p256_verify.
jadephilipoom Oct 6, 2023
8002441
[rom_ext] Add a boot-time OTBN program.
jadephilipoom Oct 6, 2023
a62ea53
[rom_ext] Add Ibex-side code to handle OTBN boot program.
jadephilipoom Oct 11, 2023
3ba4674
[crypto] Add checks to ECDH that ensure the public key is valid.
jadephilipoom Oct 16, 2023
4522e1d
[crypto] Separate X25519 tests into two targets.
jadephilipoom Oct 13, 2023
6fbe2e4
[ci] Move slowest OTBN-simulator tests to nightly.
jadephilipoom Oct 20, 2023
f2deb42
[crypto] Add OTBN-simulator test for RSA-2048 encryption/verification.
jadephilipoom Sep 26, 2023
6568144
[crypto] Add OTBN-simulator test for RSA-2048 decryption/signing.
jadephilipoom Sep 26, 2023
29fe47f
[crypto] Add OTBN-simulator test for RSA-3072 encryption/verification.
jadephilipoom Sep 26, 2023
ff5cf94
[crypto] Add OTBN-simulator test for RSA-3072 decryption/signing.
jadephilipoom Sep 26, 2023
170c24e
[crypto] Add OTBN-simulator test for RSA-4096 encryption/verification.
jadephilipoom Sep 26, 2023
07c9216
[crypto] Fix trailing whitespace in new RSA tests.
jadephilipoom Sep 26, 2023
cafa539
[sw/crypto] Add arithmetic masking to P-384 scalar multiplication
wettermo Oct 16, 2023
059a060
[sw/crypto] Add P-384 ECDH binary entrypoint
wettermo Oct 23, 2023
69b1aec
[sca] Change simple serial command identifiers
vogelpi Nov 3, 2023
c24e36b
[top, fpga] Rework SCA/FI trigger signal selection and generation
vogelpi Oct 30, 2023
ba2ade0
[sca, aes] Increase max number of segments per batch for fvsr captures
vogelpi Nov 3, 2023
add6cae
[sca, aes] Add commands for alternative batch capture
Nov 9, 2023
13a1973
[crypto] Remove a redundant load.
jadephilipoom Nov 10, 2023
bd90827
[sca] Add AES PRNG for AES batch capture
vrozic Nov 1, 2023
14c4bf5
[otbn,sw] Tweak assembly to use named OTBN CSRs
rswarbrick Nov 21, 2023
038db23
[otbn,sw] Tweak assembly to use named WSRs
rswarbrick Nov 21, 2023
06e4096
[sw/crypto] Add entrypoints for P-384 ECDSA on OTBN
wettermo Nov 17, 2023
eff5d1f
[crypto] Rearrange P-256 code to save code size.
jadephilipoom Nov 6, 2023
5d70bb6
[crypto] Implement a faster, specialized modular multiply for P256.
jadephilipoom Oct 19, 2023
92f3bec
[crypto] Add a test for multiplication modulo p.
jadephilipoom Oct 20, 2023
1ed4e3b
[crypto] Simplify the Miller-Rabin primality test.
jadephilipoom Sep 21, 2023
ef1dcfb
[crypto] Set two highest bits of p and q in RSA keygen.
jadephilipoom Sep 26, 2023
aea48ef
[crypto] Re-set bottom 2 bits in candidate RSA primes.
jadephilipoom Oct 6, 2023
5c43186
[crypto] Update RSA test data to use values that are 3 mod 4.
jadephilipoom Oct 20, 2023
ed4c1e7
[crypto] Add OTBN code for RSA key-from-cofactor.
jadephilipoom Dec 29, 2023
a6b37ac
[crypto] Speed up computation of R^2 in RSA.
jadephilipoom Sep 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,29 @@ jobs:
make -C hw/ip/otbn/util asm-check
displayName: Assemble & link code snippets

- job: otbn_crypto_tests
displayName: Run OTBN crypto tests
dependsOn: lint
condition: and(succeeded(), eq(dependencies.lint.outputs['DetermineBuildType.onlyCdcChanges'], '0'))
pool:
vmImage: ubuntu-20.04
timeoutInMinutes: 60
steps:
- template: ci/checkout-template.yml
- template: ci/install-package-dependencies.yml
- task: DownloadSecureFile@1
condition: eq(variables['Build.SourceBranchName'], 'master')
name: bazelCacheGcpKey
inputs:
secureFile: "bazel_cache_gcp_key.json"
- bash: echo "##vso[task.setvariable variable=bazelCacheGcpKeyPath]$(bazelCacheGcpKey.secureFilePath)"
condition: eq(variables['Build.SourceBranchName'], 'master')
displayName: GCP key path
# Set the remote cache GCP key path
- bash: |
ci/bazelisk.sh test --test_tag_filters=-nightly //sw/otbn/crypto/...
displayName: Execute tests

- job: chip_darjeeling_cw310
displayName: CW310's Darjeeling Bitstream
# Build CW310 variant of the Darjeeling toplevel design using Vivado
Expand Down
23 changes: 23 additions & 0 deletions ci/azure-pipelines-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,29 @@ jobs:
//sw/device/silicon_creator/rom/e2e/...
displayName: "Run all ROM E2E tests"

- job: slow_otbn_crypto_tests
displayName: Run slow OTBN crypto tests
dependsOn: lint
condition: and(succeeded(), eq(dependencies.lint.outputs['DetermineBuildType.onlyCdcChanges'], '0'))
pool:
vmImage: ubuntu-20.04
timeoutInMinutes: 120
steps:
- template: ci/checkout-template.yml
- template: ci/install-package-dependencies.yml
- task: DownloadSecureFile@1
condition: eq(variables['Build.SourceBranchName'], 'master')
name: bazelCacheGcpKey
inputs:
secureFile: "bazel_cache_gcp_key.json"
- bash: echo "##vso[task.setvariable variable=bazelCacheGcpKeyPath]$(bazelCacheGcpKey.secureFilePath)"
condition: eq(variables['Build.SourceBranchName'], 'master')
displayName: GCP key path
# Set the remote cache GCP key path
- bash: |
ci/bazelisk.sh test --test_tag_filters=nightly //sw/otbn/crypto/...
displayName: Execute tests

- job: bob_spi_i2c
displayName: "BoB: SPI and I2C Tests"
timeoutInMinutes: 30
Expand Down
22 changes: 11 additions & 11 deletions hw/ip/otbn/dv/smoke/smoke_test.s
Original file line number Diff line number Diff line change
Expand Up @@ -98,24 +98,24 @@ test_label_3:
# use mod WSR to load bignum registers with base li psuedo-instruction
# mod = 0x78fccc06_2228e9d6_89c9b54f_887cf14e_c79af825_69be586e_9866bb3b_53769ada
li x23, 0x78fccc06
csrrw x0, 0x7d7, x23
csrrw x0, mod7, x23
li x23, 0x2228e9d6
csrrw x0, 0x7d6, x23
csrrw x0, mod6, x23
li x23, 0x89c9b54f
csrrw x0, 0x7d5, x23
csrrw x0, mod5, x23
li x23, 0x887cf14e
csrrw x0, 0x7d4, x23
csrrw x0, mod4, x23
li x23, 0xc79af825
csrrw x0, 0x7d3, x23
csrrw x0, mod3, x23
li x23, 0x69be586e
csrrw x0, 0x7d2, x23
csrrw x0, mod2, x23
li x23, 0x9866bb3b
csrrw x0, 0x7d1, x23
csrrw x0, mod1, x23
li x23, 0x53769ada
csrrw x0, 0x7d0, x23
csrrw x0, mod0, x23

# x22 = 0x89c9b54f
csrrs x23, 0x7d5, x0
csrrs x23, mod5, x0

# Note that some instructions used the fixed inputs (from w1 and w2) others use
# results from previous instructions. When debugging an failure it is recommened
Expand All @@ -126,7 +126,7 @@ csrrs x23, 0x7d5, x0
bn.wsrr w1, 0x0 /* MOD */

# Request an RND value with a write to CSR RND_PREFETCH
csrrw x0, 0x7d8, x0
csrrw x0, rnd_prefetch, x0

# sim environment provides a fixed value for RND (in other environment RND isn't
# fixed so this test will have a different final state)
Expand Down Expand Up @@ -185,7 +185,7 @@ bn.addc w15, w10, w11, FG0
bn.subb w17, w3, w4, FG1

# x24 = {fg1, fg0} = 0x52
csrrs x24, 0x7c8, x0
csrrs x24, flags, x0

# w18 = w1 + (w2 << 136) = 0x23a7769f_bbc28381_34745fe9_22168a4e_c79af825_69be586e_9866bb3b_53769ada
bn.add w18, w1, w2 << 136
Expand Down
67 changes: 42 additions & 25 deletions hw/top_darjeeling/rtl/autogen/chip_darjeeling_cw310.sv
Original file line number Diff line number Diff line change
Expand Up @@ -1499,54 +1499,71 @@ module chip_darjeeling_cw310 #(

// Capture trigger.
// We use the clkmgr_aon_idle signal of the IP of interest to form a precise capture trigger.
// GPIO[11:9] is used for selecting the IP of interest. The encoding is as follows (see
// GPIO[11:10] is used for selecting the IP of interest. The encoding is as follows (see
// hint_names_e enum in clkmgr_pkg.sv for details).
//
// IP - GPIO[11:9] - Index for clkmgr_aon_idle
// ------------------------------------------------------------
// AES - 000 - 0
// HMAC - 001 - 1 - not implemented on CW305
// KMAC - 010 - 2 - not implemented on CW305
// OTBN (IO_DIV4) - 011 - 3 - not implemented on CW305
// OTBN - 100 - 4 - not implemented on CW305
// IP - GPIO[11:10] - Index for clkmgr_aon_idle
// -------------------------------------------------------------
// AES - 00 - 0
// HMAC - 01 - 1 - not implemented on CW305
// KMAC - 10 - 2 - not implemented on CW305
// OTBN - 11 - 3 - not implemented on CW305
//
// In addition, GPIO8 is used for gating the capture trigger in software.
// Note that GPIO[11:8] are connected to LED[3:0] on the CW310.
// On the CW305, GPIO[9,8] are connected to LED[5,7].
// GPIO9 is used for gating the selected capture trigger in software. Alternatively, GPIO8
// can be used to implement a less precise but fully software-controlled capture trigger
// similar to what can be done on ASIC.
//
// Note that on the CW305, GPIO[9,8] are connected to LED[5(Green),7(Red)].

prim_mubi_pkg::mubi4_t clk_trans_idle, manual_in_io_clk_idle;

clkmgr_pkg::hint_names_e trigger_sel;
always_comb begin : trigger_sel_mux
unique case ({dio_out[DioGpioGpio11], dio_out[DioGpioGpio10], dio_out[DioGpioGpio9]})
3'b000: trigger_sel = clkmgr_pkg::HintMainAes;
3'b001: trigger_sel = clkmgr_pkg::HintMainHmac;
3'b010: trigger_sel = clkmgr_pkg::HintMainKmac;
3'b100: trigger_sel = clkmgr_pkg::HintMainOtbn;
unique case ({dio_out[DioGpioGpio11], dio_out[DioGpioGpio10]})
2'b00: trigger_sel = clkmgr_pkg::HintMainAes;
2'b01: trigger_sel = clkmgr_pkg::HintMainHmac;
2'b10: trigger_sel = clkmgr_pkg::HintMainKmac;
2'b11: trigger_sel = clkmgr_pkg::HintMainOtbn;
default: trigger_sel = clkmgr_pkg::HintMainAes;
endcase;
end
assign clk_trans_idle = top_darjeeling.clkmgr_aon_idle[trigger_sel];

logic clk_io_div4_trigger_en, manual_in_io_clk_trigger_en;
logic clk_io_div4_trigger_oe, manual_in_io_clk_trigger_oe;
assign clk_io_div4_trigger_en = dio_out[DioGpioGpio8];
assign clk_io_div4_trigger_oe = dio_oe[DioGpioGpio8];
logic clk_io_div4_trigger_hw_en, manual_in_io_clk_trigger_hw_en;
logic clk_io_div4_trigger_hw_oe, manual_in_io_clk_trigger_hw_oe;
logic clk_io_div4_trigger_sw_en, manual_in_io_clk_trigger_sw_en;
logic clk_io_div4_trigger_sw_oe, manual_in_io_clk_trigger_sw_oe;
assign clk_io_div4_trigger_hw_en = dio_out[DioGpioGpio9];
assign clk_io_div4_trigger_hw_oe = dio_oe[DioGpioGpio9];
assign clk_io_div4_trigger_sw_en = dio_out[DioGpioGpio8];
assign clk_io_div4_trigger_sw_oe = dio_oe[DioGpioGpio8];

// Synchronize signals to manual_in_io_clk.
prim_flop_2sync #(
.Width ($bits(clk_trans_idle) + 2)
.Width ($bits(clk_trans_idle) + 4)
) u_sync_trigger (
.clk_i (manual_in_io_clk),
.rst_ni(manual_in_por_n),
.d_i ({clk_trans_idle, clk_io_div4_trigger_en, clk_io_div4_trigger_oe}),
.q_o ({manual_in_io_clk_idle, manual_in_io_clk_trigger_en, manual_in_io_clk_trigger_oe})
.d_i ({clk_trans_idle,
clk_io_div4_trigger_hw_en,
clk_io_div4_trigger_hw_oe,
clk_io_div4_trigger_sw_en,
clk_io_div4_trigger_sw_oe}),
.q_o ({manual_in_io_clk_idle,
manual_in_io_clk_trigger_hw_en,
manual_in_io_clk_trigger_hw_oe,
manual_in_io_clk_trigger_sw_en,
manual_in_io_clk_trigger_sw_oe})
);

// Generate the actual trigger signal.
// Generate the actual trigger signal as trigger_sw OR trigger_hw.
assign manual_attr_io_trigger = '0;
assign manual_oe_io_trigger = manual_in_io_clk_trigger_oe;
assign manual_out_io_trigger = manual_in_io_clk_trigger_en &
prim_mubi_pkg::mubi4_test_false_strict(manual_in_io_clk_idle);
assign manual_oe_io_trigger =
manual_in_io_clk_trigger_sw_oe | manual_in_io_clk_trigger_hw_oe;
assign manual_out_io_trigger =
manual_in_io_clk_trigger_sw_en | (manual_in_io_clk_trigger_hw_en &
prim_mubi_pkg::mubi4_test_false_strict(manual_in_io_clk_idle));

endmodule : chip_darjeeling_cw310
67 changes: 42 additions & 25 deletions hw/top_earlgrey/rtl/autogen/chip_earlgrey_cw310.sv
Original file line number Diff line number Diff line change
Expand Up @@ -1109,54 +1109,71 @@ module chip_earlgrey_cw310 #(

// Capture trigger.
// We use the clkmgr_aon_idle signal of the IP of interest to form a precise capture trigger.
// GPIO[11:9] is used for selecting the IP of interest. The encoding is as follows (see
// GPIO[11:10] is used for selecting the IP of interest. The encoding is as follows (see
// hint_names_e enum in clkmgr_pkg.sv for details).
//
// IP - GPIO[11:9] - Index for clkmgr_aon_idle
// ------------------------------------------------------------
// AES - 000 - 0
// HMAC - 001 - 1 - not implemented on CW305
// KMAC - 010 - 2 - not implemented on CW305
// OTBN (IO_DIV4) - 011 - 3 - not implemented on CW305
// OTBN - 100 - 4 - not implemented on CW305
// IP - GPIO[11:10] - Index for clkmgr_aon_idle
// -------------------------------------------------------------
// AES - 00 - 0
// HMAC - 01 - 1 - not implemented on CW305
// KMAC - 10 - 2 - not implemented on CW305
// OTBN - 11 - 3 - not implemented on CW305
//
// In addition, GPIO8 is used for gating the capture trigger in software.
// Note that GPIO[11:8] are connected to LED[3:0] on the CW310.
// On the CW305, GPIO[9,8] are connected to LED[5,7].
// GPIO9 is used for gating the selected capture trigger in software. Alternatively, GPIO8
// can be used to implement a less precise but fully software-controlled capture trigger
// similar to what can be done on ASIC.
//
// Note that on the CW305, GPIO[9,8] are connected to LED[5(Green),7(Red)].

prim_mubi_pkg::mubi4_t clk_trans_idle, manual_in_io_clk_idle;

clkmgr_pkg::hint_names_e trigger_sel;
always_comb begin : trigger_sel_mux
unique case ({mio_out[MioOutGpioGpio11], mio_out[MioOutGpioGpio10], mio_out[MioOutGpioGpio9]})
3'b000: trigger_sel = clkmgr_pkg::HintMainAes;
3'b001: trigger_sel = clkmgr_pkg::HintMainHmac;
3'b010: trigger_sel = clkmgr_pkg::HintMainKmac;
3'b100: trigger_sel = clkmgr_pkg::HintMainOtbn;
unique case ({mio_out[MioOutGpioGpio11], mio_out[MioOutGpioGpio10]})
2'b00: trigger_sel = clkmgr_pkg::HintMainAes;
2'b01: trigger_sel = clkmgr_pkg::HintMainHmac;
2'b10: trigger_sel = clkmgr_pkg::HintMainKmac;
2'b11: trigger_sel = clkmgr_pkg::HintMainOtbn;
default: trigger_sel = clkmgr_pkg::HintMainAes;
endcase;
end
assign clk_trans_idle = top_earlgrey.clkmgr_aon_idle[trigger_sel];

logic clk_io_div4_trigger_en, manual_in_io_clk_trigger_en;
logic clk_io_div4_trigger_oe, manual_in_io_clk_trigger_oe;
assign clk_io_div4_trigger_en = mio_out[MioOutGpioGpio8];
assign clk_io_div4_trigger_oe = mio_oe[MioOutGpioGpio8];
logic clk_io_div4_trigger_hw_en, manual_in_io_clk_trigger_hw_en;
logic clk_io_div4_trigger_hw_oe, manual_in_io_clk_trigger_hw_oe;
logic clk_io_div4_trigger_sw_en, manual_in_io_clk_trigger_sw_en;
logic clk_io_div4_trigger_sw_oe, manual_in_io_clk_trigger_sw_oe;
assign clk_io_div4_trigger_hw_en = mio_out[MioOutGpioGpio9];
assign clk_io_div4_trigger_hw_oe = mio_oe[MioOutGpioGpio9];
assign clk_io_div4_trigger_sw_en = mio_out[MioOutGpioGpio8];
assign clk_io_div4_trigger_sw_oe = mio_oe[MioOutGpioGpio8];

// Synchronize signals to manual_in_io_clk.
prim_flop_2sync #(
.Width ($bits(clk_trans_idle) + 2)
.Width ($bits(clk_trans_idle) + 4)
) u_sync_trigger (
.clk_i (manual_in_io_clk),
.rst_ni(manual_in_por_n),
.d_i ({clk_trans_idle, clk_io_div4_trigger_en, clk_io_div4_trigger_oe}),
.q_o ({manual_in_io_clk_idle, manual_in_io_clk_trigger_en, manual_in_io_clk_trigger_oe})
.d_i ({clk_trans_idle,
clk_io_div4_trigger_hw_en,
clk_io_div4_trigger_hw_oe,
clk_io_div4_trigger_sw_en,
clk_io_div4_trigger_sw_oe}),
.q_o ({manual_in_io_clk_idle,
manual_in_io_clk_trigger_hw_en,
manual_in_io_clk_trigger_hw_oe,
manual_in_io_clk_trigger_sw_en,
manual_in_io_clk_trigger_sw_oe})
);

// Generate the actual trigger signal.
// Generate the actual trigger signal as trigger_sw OR trigger_hw.
assign manual_attr_io_trigger = '0;
assign manual_oe_io_trigger = manual_in_io_clk_trigger_oe;
assign manual_out_io_trigger = manual_in_io_clk_trigger_en &
prim_mubi_pkg::mubi4_test_false_strict(manual_in_io_clk_idle);
assign manual_oe_io_trigger =
manual_in_io_clk_trigger_sw_oe | manual_in_io_clk_trigger_hw_oe;
assign manual_out_io_trigger =
manual_in_io_clk_trigger_sw_en | (manual_in_io_clk_trigger_hw_en &
prim_mubi_pkg::mubi4_test_false_strict(manual_in_io_clk_idle));

endmodule : chip_earlgrey_cw310
1 change: 1 addition & 0 deletions sw/device/sca/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ opentitan_flash_binary(
"//sw/device/lib/testing/test_framework:check",
"//sw/device/lib/testing/test_framework:ottf_ld_silicon_creator_slot_a",
"//sw/device/lib/testing/test_framework:ottf_main",
"//sw/device/sca/lib:aes",
"//sw/device/sca/lib:prng",
"//sw/device/sca/lib:sca",
"//sw/device/sca/lib:simple_serial",
Expand Down
Loading
Loading