Skip to content

[otbn,rtl] Shuffle order of multiplications for vectorized SIMD multiplications - #30959

Merged
vogelpi merged 2 commits into
lowRISC:masterfrom
etterli:otbn-mac-shuffling
Aug 10, 2026
Merged

[otbn,rtl] Shuffle order of multiplications for vectorized SIMD multiplications#30959
vogelpi merged 2 commits into
lowRISC:masterfrom
etterli:otbn-mac-shuffling

Conversation

@etterli

@etterli etterli commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

This implements a shuffling mechanism which randomizes the order in which the vector elements are processed during a SIMD multiplication instruction.

Previously a multiplication processed a vector in a fixed order, from the least significant words to the highest words. Now we randomize this order by sampling a start index. The elements are still processed in a raising order but the random start index makes it harder for SCA to align computations.

This shuffling can be disabled for SCA analysis with the SecFixMacOpSeq parameter.

See also #30940 to understand where which randomness is used from URND.

@etterli
etterli requested a review from a team as a code owner August 7, 2026 11:29
@etterli
etterli requested review from andrea-caforio, h-filali, marnovandermaas, nasahlpa, siemen11, thommythomaso and vogelpi and removed request for a team and marnovandermaas August 7, 2026 11:29

@vogelpi vogelpi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @etterli , the RTL looks great! But I would prefer if the elem_idx signal was defined outside of the loop (see my comment for details).

Comment thread hw/ip/otbn/rtl/otbn_mac_bignum_fsm.sv Outdated
Comment thread hw/ip/otbn/rtl/otbn_mac_bignum.sv Outdated
Comment on lines +667 to +669
// The shuffling index offset must be the same so we use the predecoded value. The shuffling
// could be made deterministic by attacking the URND bits going into the predecoder. But this
// is a SCA countermeasure so this is ok.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rephrase this to something like:
"We don't actually recompute the shuffling index and instead just use the value from the predecoder. This means we will never detect a mismatch for this signal. But that is acceptable as the shuffling is SCA countermeasure on top of the masking expected to be implemented in software."

Because this talks a bit less about attacks but makes it clear to DV folks that there will be a coverage gap here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm I see your point. But a different shuffle offset here leads to different 64-bit word selections. This would still be detected. The problem is that we do not have the URND bits from the last cycle available. So we just use the predecoded value again. The only attack point is now making the URND bits used by the predecoder static/deterministic. Then no mismatch can be detected. To fix this we would have to register the two URND bits and recompute the offset here. But I don't think this is needed. It would only benefit if a SCA and FI attack would be combined.

I tried to improve the comment.

             Predecoder              |       BN MAC

+------+       +-------------+   +------+
| URND |--o--> | Offset comp |-->| Flop |--------------------o-> To FSM
+------+  |    +-------------+   +------+                    |
          |                                                  v          
          |                                              Comparison
          |      This extra path would be required           ^
          |                      +------+   +-------------+  |
          +--------------------->| Flop |-->| Offset comp |--+
                                 +------+   +--------------

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is also my understanding and I think this is fine. Thanks @etterli !

* v v v v
* +-----+ +-----+ +-----+ Used as
* | ACC | | C | | TMP | shuffling
* +-----+ +-----+ +-----+ index

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding the drawing. IIUC, this means we'll use two bits of the current URND output to shuffle the order for the next vectorized multiplication. I think this is fine because:

  • There is a permutation (netlist secret) which obfuscates which two bits are used.
  • If it turned out to be a problem, software could add a NOP before the vectorized multiplication to ensure the same bits are not used for something else.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For completeness, SW can also make sure no MAI operation is ongoing. See also #30940 where and how URND is used.

OTBN uses netlist secret based permutations for certain URND users. This adds some helpers to
efficiently model these in the simulator.

Signed-off-by: Pascal Etterli <pascal.etterli@lowrisc.org>
@etterli
etterli force-pushed the otbn-mac-shuffling branch from 2eaa640 to a7e12fc Compare August 10, 2026 06:40

@etterli etterli left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @vogelpi for the review.

Comment thread hw/ip/otbn/rtl/otbn_mac_bignum_fsm.sv Outdated
Comment thread hw/ip/otbn/rtl/otbn_mac_bignum.sv Outdated
Comment on lines +667 to +669
// The shuffling index offset must be the same so we use the predecoded value. The shuffling
// could be made deterministic by attacking the URND bits going into the predecoder. But this
// is a SCA countermeasure so this is ok.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm I see your point. But a different shuffle offset here leads to different 64-bit word selections. This would still be detected. The problem is that we do not have the URND bits from the last cycle available. So we just use the predecoded value again. The only attack point is now making the URND bits used by the predecoder static/deterministic. Then no mismatch can be detected. To fix this we would have to register the two URND bits and recompute the offset here. But I don't think this is needed. It would only benefit if a SCA and FI attack would be combined.

I tried to improve the comment.

             Predecoder              |       BN MAC

+------+       +-------------+   +------+
| URND |--o--> | Offset comp |-->| Flop |--------------------o-> To FSM
+------+  |    +-------------+   +------+                    |
          |                                                  v          
          |                                              Comparison
          |      This extra path would be required           ^
          |                      +------+   +-------------+  |
          +--------------------->| Flop |-->| Offset comp |--+
                                 +------+   +--------------

@etterli
etterli force-pushed the otbn-mac-shuffling branch from a7e12fc to c308495 Compare August 10, 2026 07:56
…plications

This implements a shuffling mechanism which randomizes the order in which the vector elements are
processed during a SIMD multiplication instruction.

Previously a multiplication processed a vector in a fixed order, from the least significant words to
the highest words. Now we randomize this order by sampling a start index. The elements are still
processed in a raising order but the random start index makes it harder for SCA to align
computations.

This shuffling can be disabled for SCA analysis with the SecFixMacOpSeq parameter.

Signed-off-by: Pascal Etterli <pascal.etterli@lowrisc.org>
@etterli
etterli force-pushed the otbn-mac-shuffling branch from c308495 to fb6d73a Compare August 10, 2026 08:20
@etterli etterli added the CI:Rerun Rerun failed CI jobs label Aug 10, 2026
@github-actions github-actions Bot removed the CI:Rerun Rerun failed CI jobs label Aug 10, 2026
@vogelpi

vogelpi commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

CHANGE AUTHORIZED: hw/ip/otbn/data/otbn.hjson
CHANGE AUTHORIZED: hw/ip/otbn/rtl/otbn.sv
CHANGE AUTHORIZED: hw/ip/otbn/rtl/otbn_core.sv
CHANGE AUTHORIZED: hw/ip/otbn/rtl/otbn_instruction_fetch.sv
CHANGE AUTHORIZED: hw/ip/otbn/rtl/otbn_mac_bignum.sv
CHANGE AUTHORIZED: hw/ip/otbn/rtl/otbn_mac_bignum_fsm.sv
CHANGE AUTHORIZED: hw/ip/otbn/rtl/otbn_pkg.sv
CHANGE AUTHORIZED: hw/ip/otbn/rtl/otbn_predecode.sv
CHANGE AUTHORIZED: hw/top_earlgrey/rtl/autogen/earlgrey_pd_main.sv
CHANGE AUTHORIZED: hw/top_earlgrey/rtl/autogen/top_earlgrey.sv

This PR implements an approved feature.

@vogelpi

vogelpi commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

@nasahlpa , would you mind authorizing this PR too please?

@nasahlpa

Copy link
Copy Markdown
Contributor

CHANGE AUTHORIZED: hw/ip/otbn/data/otbn.hjson
CHANGE AUTHORIZED: hw/ip/otbn/rtl/otbn.sv
CHANGE AUTHORIZED: hw/ip/otbn/rtl/otbn_core.sv
CHANGE AUTHORIZED: hw/ip/otbn/rtl/otbn_instruction_fetch.sv
CHANGE AUTHORIZED: hw/ip/otbn/rtl/otbn_mac_bignum.sv
CHANGE AUTHORIZED: hw/ip/otbn/rtl/otbn_mac_bignum_fsm.sv
CHANGE AUTHORIZED: hw/ip/otbn/rtl/otbn_pkg.sv
CHANGE AUTHORIZED: hw/ip/otbn/rtl/otbn_predecode.sv
CHANGE AUTHORIZED: hw/top_earlgrey/rtl/autogen/earlgrey_pd_main.sv
CHANGE AUTHORIZED: hw/top_earlgrey/rtl/autogen/top_earlgrey.sv

This PR implements an approved feature.

@vogelpi
vogelpi added this pull request to the merge queue Aug 10, 2026
Merged via the queue into lowRISC:master with commit af43bb2 Aug 10, 2026
73 of 78 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants