Home/Instructions/SM4 Encrypt/Decrypt
SM4ED

RISC-V SM4ED Instruction Details

Instruction ManualR-type

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

Instruction Syntax

sm4ed 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

sm4ed is a Zksed SM4 encrypt/decrypt round-function acceleration instruction for RV32 and RV64. It selects one byte from rs2[31:0] using bs, applies the SM4 S-Box and data-round 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.

SM4ED 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.

sm4ed

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

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

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

result pending

Quick Understanding & Search Notes

SM4ED is a Zksed scalar cryptography instruction for SM4 encrypt/decrypt round 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/data-round 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 «sm4ed a0, a1, a2, 0».

Chinese National Crypto

Understand this scenario with real code like «sm4ed 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.
This instruction processes one source byte selected by bs; it does not perform a complete SM4 round by itself.
On RV64, the 32-bit result is sign-extended to XLEN.

FAQ

Does SM4ED use floating-point or vector registers?

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

Is SM4ED a complete algorithm implementation?

No. It defines one byte operation of the SM4 encrypt/decrypt round function.