Home/Instructions/SM3 Permutation P0
SM3P0

RISC-V SM3P0 Instruction Details

Instruction ManualI-type

SM3 hash P0 permutation: P0(x) = x ^ ROTL(x,9) ^ ROTL(x,17)

Instruction Syntax

sm3p0 rd, rs1
Operand Breakdown
Destination rd: general-purpose register receiving the result.
Source rs1: register holding the first operand.
Immediate imm: 12-bit signed value, sign-extended before operation with rs1.
ZkshCrypto & Security

Instruction Behavior

sm3p0 is defined in RV32 and RV64 and implements the SM3 P0 transform. It takes X(rs1)[31:0], computes r1 ^ ROL32(r1, 9) ^ ROL32(r1, 17), and writes rd; RV64 writes the 32-bit result with EXTS.

SM3P0 Decode And Execute Animation

Bounded teaching inputs execute the official SM3 fixed-width bit operations; this does not model a complete algorithm or microarchitecture.

rd
rs1
sm3p0
,

SM3P0 is defined in RV32/RV64; RV64 uses X(rs1)[31:0] and sign-extends the 32-bit result to XLEN.

fixed selector
source
fixed
destination
OP-IMM
31..20
000100001000
19..15
rs1=x11
14..12
001
11..7
rd=x10
6..0
0010011
Execution Data Path
inb
0x89ABCDEF
rol32(inb, 9)
0x579BDF13
rol32(inb, 17)
0x9BDF1357
result
0xCC44CC44
Architectural Result
a0(x10) = 0xCC44CC44

This animation shows only official ISA fields and architectural state; it does not model a complete hash algorithm, pipeline, cache, or timing implementation.

Quick Understanding & Search Notes

SM3P0 is a Zksh scalar cryptography instruction for SM3 P0 transform. This page is checked against the official scalar crypto extension, avoiding confusion among round functions, key schedule steps, and operand sources.

Performs the P0 transform from the SM3 hash algorithm using fixed rotate-left and XOR combinations.
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 «sm3p0 a0, a1».

Chinese National Crypto

Understand this scenario with real code like «sm3p0 a0, a1».

Pre-Use Checklist

Syntax Check
  • Verify the immediate field is within the valid range.
  • Confirm source register rs1 points to the correct operand.
Semantic Check
  • Check if the immediate sign-extension matches expectations.
  • Ensure the result register rd has a clear purpose.

Pitfalls / Common Confusions

P0 uses rotate-left (ROTL), not rotate-right (ROTR).
Note difference from sm3p1 (P1): shift amounts (9,17) vs (15,23).

FAQ

Does SM3P0 use floating-point or vector registers?

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

Is SM3P0 a complete algorithm implementation?

No. It implements one SM3 P0 transform defined by the manual.