31 #include "../gf256mul/gf256mul.h"
36 void aes_shiftcol(
void *data, uint8_t shift)
39 tmp[0] = ((uint8_t*) data)[0];
40 tmp[1] = ((uint8_t*) data)[4];
41 tmp[2] = ((uint8_t*) data)[8];
42 tmp[3] = ((uint8_t*) data)[12];
43 ((uint8_t*) data)[0] = tmp[(shift + 0) & 3];
44 ((uint8_t*) data)[4] = tmp[(shift + 1) & 3];
45 ((uint8_t*) data)[8] = tmp[(shift + 2) & 3];
46 ((uint8_t*) data)[12] = tmp[(shift + 3) & 3];
49 #define GF256MUL_1(a) (a)
50 #define GF256MUL_2(a) (gf256mul(2, (a), 0x1b))
51 #define GF256MUL_3(a) (gf256mul(3, (a), 0x1b))
59 for (i = 0; i < 16; ++i) {
60 tmp[i] = ROMEM_READ_BYTE(aes_sbox_T_p + state->s[i]);
63 aes_shiftcol(tmp + 1, 1);
64 aes_shiftcol(tmp + 2, 2);
65 aes_shiftcol(tmp + 3, 3);
67 for (i = 0; i < 4; ++i) {
68 t = tmp[4 * i + 0] ^ tmp[4 * i + 1] ^ tmp[4 * i + 2] ^ tmp[4 * i + 3];
70 GF256MUL_2(tmp[4*i+0]^tmp[4*i+1])
74 GF256MUL_2(tmp[4*i+1]^tmp[4*i+2])
78 GF256MUL_2(tmp[4*i+2]^tmp[4*i+3])
82 GF256MUL_2(tmp[4*i+3]^tmp[4*i+0])
88 for (i = 0; i < 16; ++i) {
89 state->s[i] ^= k->ks[i];
98 for (i = 0; i < 16; ++i) {
99 state->s[i] = ROMEM_READ_BYTE(aes_sbox_T_p + state->s[i]);
102 aes_shiftcol(state->s + 1, 1);
103 aes_shiftcol(state->s + 2, 2);
104 aes_shiftcol(state->s + 3, 3);
106 for (i = 0; i < 16; ++i) {
107 state->s[i] ^= k->ks[i];
115 for (i = 0; i < 16; ++i) {
116 state->s[i] ^= ks->key[0].ks[i];
119 for (; rounds > 1; --rounds) {
120 aes_enc_round(state, &(ks->key[i]));
123 aes_enc_lastround(state, &(ks->key[i]));
void aes256_enc(void *buffer, aes256_ctx_t *ctx)
encrypt with 256 bit key.
void aes128_enc(void *buffer, aes128_ctx_t *ctx)
encrypt with 128 bit key.
void aes192_enc(void *buffer, aes192_ctx_t *ctx)
encrypt with 192 bit key.