Home/Instructions/SM4 Key Schedule
SM4KS

RISC-V SM4KS Instruction Details

Instruction ManualR-type

SM4 key-schedule byte step: select an rs2[31:0] byte by bs, apply S-Box/key linear layer and rotate, then XOR rs1[31:0]

Instruction Syntax

sm4ks rd, rs1, rs2, bs
Operand Breakdown
Destination rd: register receiving the operation result.
Source rs1: register holding the first operand.
Source rs2: register holding the second operand.
ZksedCrypto & Security

Instruction Behavior

sm4ks is a Zksed SM4 key-schedule acceleration instruction for RV32 and RV64. It selects one byte from rs2[31:0] using bs, applies the SM4 S-Box and key-schedule linear layer, rotates the result to the byte position selected by bs, XORs it with rs1[31:0], and writes rd; on RV64 the 32-bit result is sign-extended to XLEN. It is used to build the SM4 key schedule, not to run the data encrypt/decrypt round directly.

SM4KS Decode And Execute Animation

This bounded model shows only official ISA-visible fields, state, and conditions; it does not model a complete cryptographic protocol or microarchitecture.

sm4ks

Execution context: RV32/RV64; bounded teaching data fixes both low 32-bit sources to zero.

fixed 11010rs2=a2rs1=a1funct3=000rd=a0opcode=0110011
Execution Data Path

sb_in=0x00 -> sbox=0xD6 -> y=0xC01A6BD6 -> z=0xC01A6BD6

result pending

Quick Understanding & Search Notes

SM4KS is a Zksed scalar cryptography instruction for SM4 key schedule byte step. This page is checked against the official scalar crypto extension, avoiding confusion among round functions, key schedule steps, and operand sources.

Selects an rs2[31:0] byte using bs, applies and rotates the SM4 S-box/key-schedule linear result, then XORs rs1[31:0]; on RV64 the 32-bit result is sign-extended.
Scalar crypto instructions use integer X registers, and the official spec requires the relevant crypto instructions to be implemented with data-independent execution latency.

Common Usage Scenarios

Crypto & Security

Understand this scenario with real code like «sm4ks a0, a1, a2, 0».

Chinese National Crypto

Understand this scenario with real code like «sm4ks a0, a1, a2, 0».

Key Schedule

Understand this scenario with real code like «sm4ks a0, a1, a2, 0».

Pre-Use Checklist

Syntax Check
  • Verify rd, rs1, rs2 (and rs3) are valid GPRs.
  • Confirm funct3 and funct7 encoding is correct.
Semantic Check
  • Check if the result affects subsequent branches or address calculations.
  • Ensure the rd register is not overwritten by another instruction.

Pitfalls / Common Confusions

bs selects one byte from rs2[31:0]; rs1 is the final XOR source.
The key-schedule linear layer differs from the data-round linear layer used by sm4ed.
On RV64, the 32-bit result is sign-extended to XLEN.

FAQ

Does SM4KS use floating-point or vector registers?

No. These scalar crypto extension instructions use integer X registers.

Is SM4KS a complete algorithm implementation?

No. It defines one byte operation of the SM4 key schedule.