Skip to content

crypto: offload OpenSSL SM4 block modes to SG2002 - #514

Closed
dormancygrace wants to merge 1 commit into
codex/openssl-tdesfrom
codex/openssl-sm4
Closed

dormancygrace wants to merge 1 commit into
codex/openssl-tdesfrom
codex/openssl-sm4

Conversation

@dormancygrace

Copy link
Copy Markdown
Owner

Adds 0008-sm4-dma.patch on top of #513. SM4 ECB/CBC/CTR offload a confirmed whole-block prefix through SG2002. OpenSSL retains padding, partial updates, context duplication and software continuation; CTR consumes outstanding keystream bytes before DMA. Other modes, newer RISC-V crypto implementations and FIPS stay unchanged.

Validation: full warning-free RISC-V OpenSSL 3.5.9 build. Shared ASan/UBSan block-state and independent EVP-reference suites include all three SM4 modes. Native correctness, driver counter proof, CPU/RAM and crossover measurements are pending. The 1024-byte minimum is provisional; this draft claims no measured speedup.

@dormancygrace dormancygrace left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

The CBC, ECB and CTR glue mirrors the AES version in #511 and is correct. cipher_sm4_sg2002.inc differs from the AES include only in names, so a shared include would help later maintenance.

+{
+ PROV_SM4_CTX *a = (PROV_SM4_CTX *)ctx;
+ return ossl_sg2002_cipher(SG2002_ALG_SM4, mode, ctx->enc,
+ a->sg2002_key, ctx->keylen, ctx->iv, 16, in, out, len, SG2002_SM4_MIN);

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

SM4-CTR passes counter_bytes = 16, so it relies on the same unverified assumption as AES-CTR in #511: that the engine carries the full 128-bit counter inside a request. Please apply whatever fix is chosen there, and include SM4-CTR in the on-device carry test.

@github-actions

Copy link
Copy Markdown

Build outputs

Compared with the build of main at c93fb1a; codex/openssl-tdes is at 975f969, so outputs changed since then are listed too.

3 changed, 14 added, 0 removed of 584 outputs.

directory files
changed opensbi opensbi/build-manifest.json (records the hash of platform/build.sh)
changed server server/NanoKVM-Server
server/nkos-update
added tools 14 files
Hashes: outputs-sha256 artifact of this run.

@dormancygrace
dormancygrace deleted the codex/openssl-sm4 branch October 27, 2026 11:10
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.

1 participant