33.3.24-25Vector Crypto X: SM3 Expansion & SM4 Key Schedule

Part III Linux boot: optional Vol. I (Unprivileged) pp. 537–542 · ~1 min read

SM3 message expansion and SM4 key schedule
OperationIn
vsm3me.vvSM3 message expansion via the P1 permutation (x ^ rol(x,15) ^ rol(x,23)) — the vectorized scalar sm3p1, diffusing each new schedule word over 256-bit element groups.Zvksh
vsm4k.viSM4 key schedule: SBox + the L′ key-expansion linear layer, with the immediate selecting the round constant (CK).Zvksed
Dotted-underlined cells have explanations — click one.

Hardware Designer Notes

Same story as scalar: SM3 is fixed rotate-XOR (cheap), SM4 has the one real SBox array. Vectorized, both replicate per lane for throughput. The SM4 round instruction (vsm4r) and the widening shift (vwsll) close the reference on the next page.

Minimal Linux-boot hart MUST

  • vsm3me: the P1 rotate-XOR permutation over 256-bit message groups
  • vsm4k: the SM4 SBox + L′ linear layer + CK round constant (immediate-selected) per key group
  • Data-independent latency; SM4 SBox distinct from AES (different field/affine)

MAY simplify / trap-and-emulate

  • Share the SM4 SBox and linear-layer datapath with the scalar Zksed if both present, widened to lanes
  • Omit the ShangMi vector extensions outside Chinese-market designs

Check yourself — SM3 expansion & SM4 key

1.vsm3me.vv (SM3 message expansion) uses which SM3 primitive?

2.vsm4k.vi is the SM4 key schedule with an immediate. What does the immediate select?

2 questions