SM4EKEY (vector)

Data processing (scalar floating-point and Advanced SIMD)

fixed bit field field the encoding fixes should be

Vector crypto sm4 sm4enckey

313029282726252423222120191817161514131211109876543210
11001110011Rm110010RnRd

11001110011xxxxx110010xxxxxxxxxx

Decode Sail

if not_bool(HaveSM4Ext()) then {
    throw(Error_Undefined())
};
let 'd = UInt(Rd);
let 'n = UInt(Rn);
let 'm = UInt(Rm);
execute_aarch64_instrs_vector_crypto_sm4_sm4enckey(d, m, n)

Operation Sail

AArch64_CheckFPAdvSIMDEnabled();
let Vm : bits(128) = V_read(m, 128);
intval : bits(32) = undefined;
const : bits(32) = undefined;
roundresult : bits(128) = V_read(n, 128);
foreach (index from 0 to 3 by 1 in inc) {
    const = Elem_read(Vm, index, 32);
    intval = EOR(EOR(EOR(roundresult[127 .. 96], roundresult[95 .. 64]), roundresult[63 .. 32]), const);
    foreach (i from 0 to 3 by 1 in inc) {
        intval = Elem_set(intval, i, 8, Sbox(Elem_read(intval, i, 8)))
    };
    intval = EOR(EOR(intval, ROL(intval, 13)), ROL(intval, 23));
    intval = EOR(intval, roundresult[31 .. 0]);
    roundresult[31 .. 0] = roundresult[63 .. 32];
    roundresult[63 .. 32] = roundresult[95 .. 64];
    roundresult[95 .. 64] = roundresult[127 .. 96];
    roundresult[127 .. 96] = intval
};
V_set(d, 128) = roundresult

Made from ScarletNX's Sail at 166ad3910f80. sail-arm's definitions are Arm's ASL in Sail (BSD 3-Clause Clear, license); ScarletNX's fixups are GPL-3.0-or-later.