Skip to content

Xilinx asu rsa standalone - #11052

Open
night1rider wants to merge 6 commits into
wolfSSL:masterfrom
night1rider:Xilinx-ASU-RSA-standalone
Open

Xilinx asu rsa standalone#11052
night1rider wants to merge 6 commits into
wolfSSL:masterfrom
night1rider:Xilinx-ASU-RSA-standalone

Conversation

@night1rider

Copy link
Copy Markdown
Contributor

No description provided.

@night1rider night1rider self-assigned this Aug 4, 2026

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #11052

Scan targets checked: wolfcrypt-port-bugs, wolfcrypt-rs-bugs, wolfssl-bugs, wolfssl-src

Findings: 4
4 finding(s) posted as inline comments (see file-level comments below)

This review was generated automatically by Fenrir. Findings are non-blocking.

Comment thread wolfcrypt/src/port/xilinx/versal_gen2_asu/asu_rsa.c
Comment thread wolfcrypt/src/port/xilinx/versal_gen2_asu/asu_rsa.c
Comment thread wolfcrypt/src/port/xilinx/versal_gen2_asu/asu_rsa.c
@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown

MemBrowse Memory Report

gcc-arm-cortex-m3

  • FLASH: .text +24 B (+0.0%, 123,523 B / 262,144 B, total: 47% used)

gcc-arm-cortex-m4-crypto-only

  • FLASH: .text +448 B (+0.3%, 175,914 B / 262,144 B, total: 67% used)

gcc-arm-cortex-m4-dtls13

  • FLASH: .text +192 B (+0.1%, 182,908 B / 1,048,576 B, total: 17% used)

gcc-arm-cortex-m4-openssl-compat

  • FLASH: .text +256 B (+0.0%, 775,484 B / 1,048,576 B, total: 74% used)

gcc-arm-cortex-m4-pkcs7

  • FLASH: .text +64 B (+0.0%, 214,702 B / 262,144 B, total: 82% used)

gcc-arm-cortex-m4-pq

  • FLASH: .text +256 B (+0.1%, 297,564 B / 1,048,576 B, total: 28% used)

gcc-arm-cortex-m4-rsa-only

  • FLASH: .text +256 B (+0.1%, 328,112 B / 1,048,576 B, total: 31% used)

gcc-arm-cortex-m4-tls13

  • FLASH: .text +192 B (+0.1%, 238,305 B / 262,144 B, total: 91% used)

gcc-arm-cortex-m7

  • FLASH: .text +64 B (+0.0%, 201,839 B / 262,144 B, total: 77% used)

gcc-arm-cortex-m7-pq

  • FLASH: .text +192 B (+0.1%, 298,460 B / 1,048,576 B, total: 28% used)

gcc-arm-cortex-m7-tls13

  • FLASH: .text +256 B (+0.1%, 238,369 B / 262,144 B, total: 91% used)

linuxkm-pie

  • Data: __patchable_function_entries +104 B (+0.4%, 26,560 B)

linuxkm-standard

  • Data: __patchable_function_entries +80 B (+0.2%, 49,376 B)

stm32-sim-stm32h753

Comment thread wolfcrypt/src/port/xilinx/versal_gen2_asu/asu_rsa.c
Comment thread wolfcrypt/src/port/xilinx/versal_gen2_asu/asu_rsa.c
Comment thread wolfcrypt/src/port/xilinx/versal_gen2_asu/asu_rsa.c

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #11052

Scan targets checked: wolfcrypt-port-bugs, wolfcrypt-rs-bugs, wolfssl-bugs, wolfssl-src

Findings: 9
9 finding(s) posted as inline comments (see file-level comments below)

This review was generated automatically by Fenrir. Findings are non-blocking.

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #11052

Scan targets checked: wolfcrypt-port-bugs, wolfcrypt-rs-bugs, wolfssl-bugs, wolfssl-src

Findings: 7
7 finding(s) posted as inline comments (see file-level comments below)

This review was generated automatically by Fenrir. Findings are non-blocking.

(unsigned int)keySize, (unsigned int)status, (unsigned int)addl);

/* Fail-closed: only a clean VERIFIED status counts as verified. */
if (status == XST_SUCCESS &&

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟠 [Medium] PSS verify reports ASU transaction failures as an invalid signature · Incorrect error handling

wc_AsuRsaPssVerify sets ret = 0 regardless of status, so a failed submit, wait, or engine error leaves *res = 0 and RsaPssVerifyDevice turns it into SIG_VERIFY_E. Engine errors are indistinguishable from forged signatures, and no software fallback occurs. The raw, PSS-sign and OAEP paths in the same file return WC_HW_E here.

Related known finding #8257 (similar but distinct): Both involve ASU transaction error handling, but this finding is in wc_AsuRsaPssVerify and unconditionally converts a returned transaction/engine status into a signature verdict; #8257 is in wc_AsuTransact and submits despite a failed serialization-lock acquisition. The faulting operations and root causes differ, and correcting PSS status propagation would not fix lock handling.

Fix: Return WC_HW_E when status != XST_SUCCESS and only derive the *res verdict from a clean status with a verify pass/fail additional status.

/* DMA the ciphertext into req->out, then copy to the (maybe non-DMA) caller. */
req->oaep.XAsu_RsaOpComp.OutputDataAddr = (u64)(UINTPTR)req->out;
req->oaep.XAsu_RsaOpComp.KeyCompAddr = (u64)(UINTPTR)&req->key;
req->oaep.XAsu_RsaOpComp.Len = info->pk.rsa.inLen;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 [Low] OAEP encrypt does not validate the message against the OAEP capacity · Logic errors

hashLen is obtained but never used to bound info->pk.rsa.inLen. wolfSSL's caller only enforces the PKCS#1 v1.5 minimum (sz - 11), so messages longer than keySize - 2*hashLen - 2 (e.g. 191..245 bytes with SHA-256 and a 2048-bit key) reach the ASU, where software would have returned BAD_FUNC_ARG.

Fix: Reject or decline when info->pk.rsa.inLen > keySize - 2 * hashLen - 2 before submitting the request.

XAsu_RsaOaepPaddingParams oaep; /* OAEP encrypt params */
XAsu_RsaPvtKeyComp key;
byte out[XRSA_4096_KEY_SIZE]; /* DMA result, copied out */
byte scratch[XRSA_4096_KEY_SIZE]; /* PSS sign OutputDataAddr */

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚪ [Info] Comment on scratch buffer contradicts its use · Dead/unreachable code

scratch is documented as the "PSS sign OutputDataAddr", but wc_AsuRsaPssSign assigns req->out to OutputDataAddr and req->scratch to SignatureDataAddr. The mislabel obscures which field the hardware writes the signature into.

Fix: Reword the comment to say scratch backs the PSS-sign SignatureDataAddr.

count, start, ret); \
} while (0)

RSA_PAD_BENCH("raw-public", wc_RsaDirect(msg, bytes, enc, &outLen,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟠 [Medium] bench_rsa_pad passes an uninitialized outLen to wc_RsaDirect · Logic errors

outLen (declared at line 11232) is never initialized. wc_RsaDirect reads *outSz into key->dataLen (rsa.c:3353) and never writes it back on success, so both raw rows run on stack garbage: 0 gives BAD_FUNC_ARG, a value under the key width gives RSA_BUFFER_E.

Fix: Set outLen = bytes immediately before each wc_RsaDirect call.

}

/* Off by default: define WOLFSSL_BENCH_RSA_PAD to build this extra sweep. */
#if defined(WOLFSSL_BENCH_RSA_PAD) && \

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟠 [Medium] bench_rsa_pad guard omits the feature macros its API calls require · API contract violations

The body calls wc_RsaPSS_Sign/wc_RsaPSS_Verify, declared only under WC_RSA_PSS (rsa.h:375, :393), and wc_RsaDirect, declared only under WC_RSA_DIRECT/WC_RSA_NO_PADDING/OPENSSL_EXTRA* (rsa.h:499), but the guard requires none of them, so WOLFSSL_BENCH_RSA_PAD fails to compile on a plain RSA build.

Fix: Add the missing macros to the outer guard, or wrap the PSS and raw rows in their own #ifdef WC_RSA_PSS / wc_RsaDirect availability checks.

/* DMA the ciphertext into req->out, then copy to the (maybe non-DMA) caller. */
req->oaep.XAsu_RsaOpComp.OutputDataAddr = (u64)(UINTPTR)req->out;
req->oaep.XAsu_RsaOpComp.KeyCompAddr = (u64)(UINTPTR)&req->key;
req->oaep.XAsu_RsaOpComp.Len = info->pk.rsa.inLen;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 [Low] OAEP encrypt offload skips the message-length check software enforces · Cryptographic correctness

info->pk.rsa.inLen is passed to the ASU without checking inLen <= keySize - 2*hashLen - 2. RsaPublicEncryptEx only enforces the generic sz - RSA_MIN_PAD_SZ bound, so e.g. a 200-byte message with SHA-512 OAEP and a 2048-bit key reaches the hardware, where software returns BAD_FUNC_ARG (RsaPad_OAEP, rsa.c:1372).

Fix: Decline with CRYPTOCB_UNAVAILABLE when info->pk.rsa.inLen > keySize - 2 * hashLen - 2.

count, start, ret); \
} while (0)

RSA_PAD_BENCH("raw-public", wc_RsaDirect(msg, bytes, enc, &outLen,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 [Low] Uninitialized outLen passed to wc_RsaDirect in bench_rsa_pad · Integer overflow / underflow

outLen (declared at line 11232) is never initialized before its address is passed to wc_RsaDirect, which reads it (key->dataLen = *outSz) and compares it against the key width in wc_RsaFunctionSync. The raw-public/raw-private rows therefore pass or fail on an indeterminate stack value.

Fix: Initialize outLen = bytes before the first wc_RsaDirect call.

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.

2 participants