27 for (i = 0; i < 8; i++) {
28 s->slice[i] |= (
byte & 1) << (r * 4 +
c);
36 for (
c = 0;
c < 4;
c++) {
38 for (r = 0; r < 4; r++) {
47 for (
c = 0;
c < 4;
c++) {
49 for (r = 0; r < 4; r++) {
52 for (b = 0; b < 8; b++) {
53 v |= ((s->slice[b] >> (r * 4 +
c)) & 1) << b;
66 uint16_t U0 = s->slice[7],
U1 = s->slice[6],
U2 = s->slice[5],
U3 = s->slice[4];
67 uint16_t U4 = s->slice[3],
U5 = s->slice[2],
U6 = s->slice[1],
U7 = s->slice[0];
69 uint16_t T1,
T2,
T3,
T4,
T5,
T6,
T7,
T8,
T9,
T10,
T11,
T12,
T13,
T14,
T15,
T16;
70 uint16_t T17,
T18,
T19,
T20,
T21,
T22,
T23,
T24,
T25,
T26,
T27,
D;
71 uint16_t M1,
M6,
M11,
M13,
M15,
M20,
M21,
M22,
M23,
M25,
M37,
M38,
M39,
M40;
72 uint16_t M41,
M42,
M43,
M44,
M45,
M46,
M47,
M48,
M49,
M50,
M51,
M52,
M53,
M54;
214 s->slice[0] =
P9 ^
P16;
247 s->slice[7] =
L6 ^
L24;
248 s->slice[6] = ~(
L16 ^
L26);
249 s->slice[5] = ~(
L19 ^
L28);
250 s->slice[4] =
L6 ^
L21;
253 s->slice[1] = ~(
L13 ^
L27);
254 s->slice[0] = ~(
L6 ^
L23);
258#define BIT_RANGE(from,to) (((1 << ((to) - (from))) - 1) << (from))
260#define BIT_RANGE_LEFT(x,from,to,shift) (((x) & BIT_RANGE((from), (to))) << (shift))
261#define BIT_RANGE_RIGHT(x,from,to,shift) (((x) & BIT_RANGE((from), (to))) >> (shift))
265 for (i = 0; i < 8; i++) {
277 for (i = 0; i < 8; i++) {
287#define ROT(x,b) (((x) >> ((b) * 4)) | ((x) << ((4-(b)) * 4)))
310 uint16_t s0 = s->slice[0],
s1 = s->slice[1],
s2 = s->slice[2],
s3 = s->slice[3];
311 uint16_t s4 = s->slice[4],
s5 = s->slice[5],
s6 = s->slice[6],
s7 = s->slice[7];
343 s->slice[0] ^=
t6_02;
349 s->slice[6] ^=
t4_02;
350 s->slice[7] ^=
t5_02;
356 for (b = 0; b < 8; b++) {
357 s->slice[b] ^= round->
slice[b];
364 for (b = 0; b < 8; b++) {
365 s->slice[b] = (
a->slice[b] >>
c) & 0x1111;
372 for (b = 0; b < 8; b++) {
373 r->
slice[b] |= ((s->slice[b] ^= ((
a->slice[b] >>
c2) & 0x1111)) & 0x1111) <<
c1;
380 for (b = 0; b < 8; b++) {
381 s->slice[b] = ((s->slice[b] >> 4) | (s->slice[b] << 12)) ^ r->
slice[b];
388 s->slice[7] = s->slice[6];
389 s->slice[6] = s->slice[5];
390 s->slice[5] = s->slice[4];
391 s->slice[4] = s->slice[3] ^
top;
392 s->slice[3] = s->slice[2] ^
top;
393 s->slice[2] = s->slice[1];
394 s->slice[1] = s->slice[0] ^
top;
418 for (i = 0; i <
nrounds + 1; i++) {
420 for (b = 0; b < 8; b++) {
428 for (r = 0; r < 4; r++) {
456 for (round = 1; round <
nrounds; round++) {
483 for (round = 1; round <
nrounds; round++) {
void AES128_encrypt(const AES128_ctx *ctx, size_t blocks, unsigned char *cipher16, const unsigned char *plain16)
void AES256_encrypt(const AES256_ctx *ctx, size_t blocks, unsigned char *cipher16, const unsigned char *plain16)
void AES192_decrypt(const AES192_ctx *ctx, size_t blocks, unsigned char *plain16, const unsigned char *cipher16)
static void LoadBytes(AES_state *s, const unsigned char *data16)
Load 16 bytes of data into 8 sliced integers.
static void KeySetupColumnMix(AES_state *s, AES_state *r, const AES_state *a, int c1, int c2)
column_c1(r) |= (column_0(s) ^= column_c2(a))
void AES256_init(AES256_ctx *ctx, const unsigned char *key32)
static void InvShiftRows(AES_state *s)
static void SubBytes(AES_state *s, int inv)
static void AES_setup(AES_state *rounds, const uint8_t *key, int nkeywords, int nrounds)
Expand the cipher key into the key schedule.
void AES256_decrypt(const AES256_ctx *ctx, size_t blocks, unsigned char *plain16, const unsigned char *cipher16)
static void AES_decrypt(const AES_state *rounds, int nrounds, unsigned char *plain16, const unsigned char *cipher16)
#define BIT_RANGE_RIGHT(x, from, to, shift)
void AES192_encrypt(const AES192_ctx *ctx, size_t blocks, unsigned char *cipher16, const unsigned char *plain16)
static void KeySetupTransform(AES_state *s, const AES_state *r)
Rotate the rows in s one position upwards, and xor in r.
static void AddRoundKey(AES_state *s, const AES_state *round)
static void AES_encrypt(const AES_state *rounds, int nrounds, unsigned char *cipher16, const unsigned char *plain16)
static void ShiftRows(AES_state *s)
static void MixColumns(AES_state *s, int inv)
void AES128_decrypt(const AES128_ctx *ctx, size_t blocks, unsigned char *plain16, const unsigned char *cipher16)
void AES128_init(AES128_ctx *ctx, const unsigned char *key16)
static void LoadByte(AES_state *s, unsigned char byte, int r, int c)
Convert a byte to sliced form, storing it corresponding to given row and column in s.
static void SaveBytes(unsigned char *data16, const AES_state *s)
Convert 8 sliced integers into 16 bytes of data.
static void GetOneColumn(AES_state *s, const AES_state *a, int c)
column_0(s) = column_c(a)
static void MultX(AES_state *s)
#define BIT_RANGE(from, to)
#define BIT_RANGE_LEFT(x, from, to, shift)
void AES192_init(AES192_ctx *ctx, const unsigned char *key24)
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.