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 Encoding

31..20
imm[11:0]
19..15
rs1
14..12
funct3
11..7
rd
6..0
opcode

SM3P0 uses opcode 0010011 (0x13), funct3 001, funct7 0001100. The rs1 field selects the source register, the 12-bit immediate provides the second operand, and rd selects the destination.

Format: I-type
opcode: 0010011 (0x13)
funct3: 001 (0x1)
funct7: 0001100 (0x0c)

Instruction Behavior

sm3p0 is the Zksh SM3 hash P0 permutation instruction. Implements P0(x) = x ^ ROTL(x, 9) ^ ROTL(x, 17) where ROTL is rotate left. Reads rs1, computes P0, writes to rd. SM3 is the Chinese national cryptographic hash standard (GM/T 0004-2012); P0 is used in SM3 message expansion and compression.

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
  • Confirm the current instruction format is I-type.
  • Confirm the operand order matches the example.
Semantic Check
  • Ensure the destination register usage is compatible with the calling convention.
  • Confirm this is not the lower-level form of a pseudo-instruction expansion.

Pitfalls / Common Confusions

SM3 is a Chinese national standard (GM/T 0004-2012); P0 differs from SM4 S-Box and round function.
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 is a low-level step from AES, SHA, SM3, or SM4; software still combines instructions with the algorithm schedule, round constants, or round keys.