Skip to content

[otbn,sim] Extend the OTBN simulator with the KMAC interface#30386

Open
etterli wants to merge 3 commits into
lowRISC:masterfrom
etterli:otbn-kmac-sim
Open

[otbn,sim] Extend the OTBN simulator with the KMAC interface#30386
etterli wants to merge 3 commits into
lowRISC:masterfrom
etterli:otbn-kmac-sim

Conversation

@etterli

@etterli etterli commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

This is a first draft of the OTBNSim KMAC interface implementation.

Only the last commit is relevant. Others are from:

@etterli etterli requested a review from andrea-caforio June 12, 2026 14:22
@etterli etterli force-pushed the otbn-kmac-sim branch 3 times, most recently from 8d696cb to 118baff Compare June 15, 2026 09:36
@andrea-caforio

Copy link
Copy Markdown
Contributor

A rudimentary adaption of the ML-DSA XOF driver works in the simulator with this new KMAC interface. Let me know how you wanna proceed once this is getting ready to be merged.

@andrea-caforio andrea-caforio 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.

The good news is, it functions correctly and the ML-DSA runs without problems. But I'm not sure if this kind of complexity is really needed (see comment below).

Comment thread hw/ip/otbn/dv/otbnsim/sim/kmac.py Outdated
Comment thread hw/ip/otbn/dv/otbnsim/sim/kmac.py Outdated
# applies to SHA3. SHA3 used as a XOF is non standard but the HWIP does not
# forbid it and just keeps squeezing until DONE.
if self._app_mode == _Mode.SHA3:
# TODO: pycryptodome only provides the fixed length SHA3 digest, so we

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.

The KMAC block allows this, non-standard SHA3 digest? What is the application for this?

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.

Yes it does. I have no clue why. I just tried to match the simulator as good as possible. But I think the best option is to disable this in the KMAC itself.

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.

#30402 now changes this.

Comment thread hw/ip/otbn/dv/otbnsim/sim/kmac.py
Comment thread hw/ip/otbn/dv/otbnsim/sim/kmac.py Outdated
self._csrs.KMAC_STATUS.hw_set_rsp_valid(rsp_valid_d)

# Advance the FSM model
self._state = state_d

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'm wondering if the emulation of the RTL behavioural model is appropriate for Python code? Doesn't it make the implementation more complicated? If you compare it to the previous implementation (which mostly doesn't use this technique), it is much more complicated even though the actual adjustments I had to make in the ML-DSA driver were rather minimal.

@etterli etterli Jun 15, 2026

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.

This needs cleanup, I agree. It stems from an initial implementation where I modeled the actual KMAC interface such that later the UVM framework can 'easily' inject the responses coming from the KMAC DV agent. But this is now postponed, so I think the simulator should be simplified.

@etterli

etterli commented Jun 16, 2026

Copy link
Copy Markdown
Contributor Author

I have now cleaned up the simulator.

@etterli etterli force-pushed the otbn-kmac-sim branch 3 times, most recently from 15f51ae to ec290b6 Compare June 17, 2026 15:29
# Create a tuple key using the Enums
class _Mode(IntEnum):
SHA3 = 0
SHAKE = 1

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.

Is this intended that the SHAKE enum is now 1 when it was 2 before? Same for CSHAKE.

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.

Yes because previously it used the encodings how Ibex SW writes to the configuration register. But the app interface uses a different encoding. See

// The possible hashing operation for an interface.
typedef enum logic [1:0] {
AppSHA3 = 2'b00,
AppShake = 2'b01,
AppCShake = 2'b10,
AppKMAC = 2'b11
} app_mode_e;
.

@thommythomaso thommythomaso 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. I had one question regarding the enum values.

@andrea-caforio andrea-caforio 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.

Very nice. @etterli This is much cleaner now and easier to parse.

This extends the OTBN simulator by the KMAC interface. The KMAC interface is only supported for
standalone simulator use. It is not yet possible to do a RTL co-simulation.

Signed-off-by: Pascal Etterli <pascal.etterli@lowrisc.org>
@etterli etterli marked this pull request as ready for review June 25, 2026 07:51
@etterli etterli requested a review from a team as a code owner June 25, 2026 07:51
@etterli etterli requested review from andrea-caforio, h-filali, hcallahan-lowrisc, nasahlpa and rswarbrick and removed request for a team and hcallahan-lowrisc June 25, 2026 07:51
Signed-off-by: Andrea Caforio <andrea.caforio@lowrisc.org>
It also removes an obsolete OTBN-KMAC interface test.

Signed-off-by: Andrea Caforio <andrea.caforio@lowrisc.org>

@nasahlpa nasahlpa 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 Pascal.

I mostly had a look into the adaptions in the OTBN snippets. It would be good if somebody with more OTBN simulator experience could have a look into that part as well - maybe @h-filali or @thommythomaso?

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.

4 participants