Perform Last Round of AES Decryption

Encoding

EncodingOperand 1Operand 2Operand 3Operand 4
rmn/aModRM.reg[rw]ModRM.r/m[r]
rvmn/aModRM.reg[rw]VEX.vvvv[r]ModRM.r/m[r]
ervmfull-memModRM.reg[rw]EVEX.vvvvv[r]ModRM.r/m[r]

Description

The (V)AESDECLAST instruction performs the last round of AES decryption using one, two, or four 128 bit states from the first source operand using 128 bit round keys from the second source operand. The result is stored in in the destination operand.

Due to the nature of AES, this instruction must be used for only the last decryption round. For all previous rounds, use the AESDEC (Perform One Round of AES Decryption) instruction.

All forms except the legacy SSE one will zero the upper (untouched) bits.

Operation

public void AESDECLAST(SimdU128 dest, SimdU128 src)
{
    U128 state = dest[0];
    state = AesInvShiftRows(state);
    state = AesInvSubBytes(state);
    dest[0] = state ^ src[0];
    // dest[1..] is unmodified
}

void VAESDECLAST(SimdU128 dest, SimdU128 src1, SimdU128 src2, int kl)
{
    for (int n = 0; n < kl; n++)
    {
        U128 state = src1[n];
        state = AesInvShiftRows(state);
        state = AesInvSubBytes(state);
        dest[n] = state ^ src2[n];
    }
    dest[kl..] = 0;
}

public void VAESDECLAST_Vex128(SimdU128 dest, SimdU128 src1, SimdU128 src2) =>
    VAESDECLAST(dest, src1, src2, 1);
public void VAESDECLAST_Vex256(SimdU128 dest, SimdU128 src1, SimdU128 src2) =>
    VAESDECLAST(dest, src1, src2, 2);

public void VAESDECLAST_Evex128(SimdU128 dest, SimdU128 src1, SimdU128 src2) =>
    VAESDECLAST(dest, src1, src2, 1);
public void VAESDECLAST_Evex256(SimdU128 dest, SimdU128 src1, SimdU128 src2) =>
    VAESDECLAST(dest, src1, src2, 2);
public void VAESDECLAST_Evex512(SimdU128 dest, SimdU128 src1, SimdU128 src2) =>
    VAESDECLAST(dest, src1, src2, 4);

Intrinsics

Exceptions

SIMD Floating-Point

None.

Other Exceptions

VEX Encoded Form: See Type 4 Exception Conditions.
EVEX Encoded Form: See Type E4NF Exception Conditions.