Crypto: Micro-optimize AES encrypt loop

This commit is contained in:
zzz
2022-03-28 08:08:22 -04:00
parent 7cf9895908
commit acbf849b44

View File

@ -127,13 +127,12 @@ public final class CryptixAESEngine extends AESEngine {
} }
} }
int numblock = length / 16;
DataHelper.xor(iv, ivOffset, payload, payloadIndex, out, outIndex, 16); DataHelper.xor(iv, ivOffset, payload, payloadIndex, out, outIndex, 16);
encryptBlock(out, outIndex, sessionKey, out, outIndex); encryptBlock(out, outIndex, sessionKey, out, outIndex);
for (int x = 1; x < numblock; x++) { for (int x = 16; x < length; x += 16) {
DataHelper.xor(out, outIndex + (x-1) * 16, payload, payloadIndex + x * 16, out, outIndex + x * 16, 16); int off = outIndex + x;
encryptBlock(out, outIndex + x * 16, sessionKey, out, outIndex + x * 16); DataHelper.xor(out, off - 16, payload, payloadIndex + x, out, off, 16);
encryptBlock(out, off, sessionKey, out, off);
} }
} }