Skip to content

Conversation

andrea-caforio
Copy link
Contributor

Use the proper run_rsa_modexp OTBN app instead of the orthogonal rsa.s for all (pen-)testing functions.

@andrea-caforio andrea-caforio force-pushed the rsa-switch-testing-bin branch 5 times, most recently from a18af45 to da9c85c Compare September 24, 2025 14:24
@andrea-caforio andrea-caforio marked this pull request as ready for review September 24, 2025 14:51
@andrea-caforio andrea-caforio requested a review from a team as a code owner September 24, 2025 14:51
@andrea-caforio andrea-caforio requested review from alees24, nasahlpa and johannheyszl and removed request for a team September 24, 2025 14:51
Copy link
Member

@nasahlpa nasahlpa left a comment

Choose a reason for hiding this comment

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

Thanks Andi.

Just two minor comments from my side.

.equ MODE_RSA_4096_MODEXP, 0x70b
.equ MODE_RSA_4096_MODEXP_F4, 0x0ee

# Testing only! These key lengths are not supported.
Copy link
Member

Choose a reason for hiding this comment

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

What do you mean with this? If it is not supported why are we have this here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Both otcrypto and pentesting use RSA-512 and RSA-1024 for tests. I'm making it explicit here,
that we cannot support them for anything other than tests because both are insecure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Before there was a hack that bypassed the cryptolib API in order to force the usage of RSA-512 and RSA-1024. I don't think it should be done that way.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the explanation, makes sense!

Copy link
Contributor

Choose a reason for hiding this comment

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

we dont save code size by removing support for short key sizes, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, because the implementation is independent of the key size.


uint32_t n_limbs = size_bytes / kOtbnWideWordBytes;
if (n_limbs == 0 || n_limbs > 16) {
if (size_bytes == 0 || size_bytes > 512) {
Copy link
Member

Choose a reason for hiding this comment

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

Do we have an enum for these 512 bits somewhere?

Copy link
Member

Choose a reason for hiding this comment

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

Ah we actually don't need this, right? Because above the switch case should already check size_bytes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct, I removed it.


uint32_t n_limbs = size_bytes / kOtbnWideWordBytes;
if (n_limbs == 0 || n_limbs > 16) {
if (size_bytes == 0 || size_bytes > 512) {
Copy link
Member

Choose a reason for hiding this comment

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

Ah we actually don't need this, right? Because above the switch case should already check size_bytes.

.equ MODE_RSA_4096_MODEXP, 0x70b
.equ MODE_RSA_4096_MODEXP_F4, 0x0ee

# Testing only! These key lengths are not supported.
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the explanation, makes sense!

Use the proper `run_rsa_modexp` OTBN app instead of the orthogonal
`rsa.s` for all (pen-)testing functions.

Signed-off-by: Andrea Caforio <[email protected]>
@nasahlpa nasahlpa added this pull request to the merge queue Sep 25, 2025
Merged via the queue into lowRISC:master with commit 7f86158 Sep 25, 2025
46 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