This file contains the definitions required to use AES in C. See aesopt.h for optimisation details. More...
#include "limits.h"

Go to the source code of this file.
Data Structures | |
| struct | aes_decrypt_ctx |
| struct | aes_encrypt_ctx |
Defines | |
| #define | AES_128 |
| #define | AES_BLOCK_SIZE 16 |
| #define | AES_DECRYPT |
| #define | AES_ENCRYPT |
| #define | AES_ERR_CHK |
| #define | aes_error -1 |
| #define | aes_good 0 |
| #define | aes_ret int |
| #define | aes_rval aes_ret |
| #define | KS_LENGTH 64 |
| #define | N_COLS 4 |
Functions | |
| aes_rval | aes_decrypt (const void *in_blk, void *out_blk, const aes_decrypt_ctx cx[1]) |
| aes_rval | aes_decrypt_key128 (const void *in_key, aes_decrypt_ctx cx[1]) |
| aes_rval | aes_encrypt (const void *in_blk, void *out_blk, const aes_encrypt_ctx cx[1]) |
| aes_rval | aes_encrypt_key128 (const void *in_key, aes_encrypt_ctx cx[1]) |
| void | gen_tabs (void) |
This file contains the definitions required to use AES in C. See aesopt.h for optimisation details.
Definition in file aes_internal.h.
| #define AES_128 |
Definition at line 60 of file aes_internal.h.
| #define AES_BLOCK_SIZE 16 |
Definition at line 85 of file aes_internal.h.
| #define AES_DECRYPT |
Definition at line 68 of file aes_internal.h.
| #define AES_ENCRYPT |
Definition at line 67 of file aes_internal.h.
| #define AES_ERR_CHK |
Definition at line 69 of file aes_internal.h.
| #define aes_error -1 |
Definition at line 97 of file aes_internal.h.
Referenced by aes_decrypt(), and aes_encrypt().
| #define aes_good 0 |
Definition at line 96 of file aes_internal.h.
Referenced by aes_decrypt(), and aes_encrypt().
| #define aes_ret int |
Definition at line 95 of file aes_internal.h.
| #define aes_rval aes_ret |
Definition at line 103 of file aes_internal.h.
| #define KS_LENGTH 64 |
Definition at line 92 of file aes_internal.h.
| #define N_COLS 4 |
Definition at line 86 of file aes_internal.h.
Referenced by aes_decrypt(), and aes_encrypt().
| aes_rval aes_decrypt | ( | const void * | in_blk, |
| void * | out_blk, | ||
| const aes_decrypt_ctx | cx[1] | ||
| ) |
Definition at line 239 of file aescrypt.c.
References aes_error, aes_good, inv_lrnd, inv_rnd, aes_decrypt_ctx::ks, l_copy, locals, N_COLS, round, state_in, and state_out.
{ aes_32t locals(b0, b1);
#ifdef dec_imvars
dec_imvars; /* declare variables for inv_mcol() if needed */
#endif
aes_32t nr = (cx->ks[45] ^ cx->ks[52] ^ cx->ks[53] ? cx->ks[52] : 14);
const aes_32t *kp = cx->ks + nr * N_COLS;
#ifdef AES_ERR_CHK
if( (nr != 10 || !(cx->ks[0] | cx->ks[3] | cx->ks[4]))
&& (nr != 12 || !(cx->ks[0] | cx->ks[5] | cx->ks[6]))
&& (nr != 14 || !(cx->ks[0] | cx->ks[7] | cx->ks[8])) )
return aes_error;
#endif
state_in(b0, in_blk, kp);
#if (DEC_UNROLL == FULL)
switch(nr)
{
case 14:
round(inv_rnd, b1, b0, kp - 1 * N_COLS);
round(inv_rnd, b0, b1, kp - 2 * N_COLS);
kp -= 2 * N_COLS;
case 12:
round(inv_rnd, b1, b0, kp - 1 * N_COLS);
round(inv_rnd, b0, b1, kp - 2 * N_COLS);
kp -= 2 * N_COLS;
case 10:
round(inv_rnd, b1, b0, kp - 1 * N_COLS);
round(inv_rnd, b0, b1, kp - 2 * N_COLS);
round(inv_rnd, b1, b0, kp - 3 * N_COLS);
round(inv_rnd, b0, b1, kp - 4 * N_COLS);
round(inv_rnd, b1, b0, kp - 5 * N_COLS);
round(inv_rnd, b0, b1, kp - 6 * N_COLS);
round(inv_rnd, b1, b0, kp - 7 * N_COLS);
round(inv_rnd, b0, b1, kp - 8 * N_COLS);
round(inv_rnd, b1, b0, kp - 9 * N_COLS);
round(inv_lrnd, b0, b1, kp - 10 * N_COLS);
}
#else
#if (DEC_UNROLL == PARTIAL)
{ aes_32t rnd;
for(rnd = 0; rnd < (nr >> 1) - 1; ++rnd)
{
kp -= N_COLS;
round(inv_rnd, b1, b0, kp);
kp -= N_COLS;
round(inv_rnd, b0, b1, kp);
}
kp -= N_COLS;
round(inv_rnd, b1, b0, kp);
#else
{ aes_32t rnd;
for(rnd = 0; rnd < nr - 1; ++rnd)
{
kp -= N_COLS;
round(inv_rnd, b1, b0, kp);
l_copy(b0, b1);
}
#endif
kp -= N_COLS;
round(inv_lrnd, b0, b1, kp);
}
#endif
state_out(out_blk, b0);
#ifdef AES_ERR_CHK
return aes_good;
#endif
}
| aes_rval aes_decrypt_key128 | ( | const void * | in_key, |
| aes_decrypt_ctx | cx[1] | ||
| ) |
| aes_rval aes_encrypt | ( | const void * | in_blk, |
| void * | out_blk, | ||
| const aes_encrypt_ctx | cx[1] | ||
| ) |
Definition at line 115 of file aescrypt.c.
References aes_error, aes_good, dec_fmvars, fwd_lrnd, fwd_rnd, aes_encrypt_ctx::ks, l_copy, locals, N_COLS, round, state_in, and state_out.
{ aes_32t locals(b0, b1);
const aes_32t *kp = cx->ks;
#ifdef dec_fmvars
dec_fmvars; /* declare variables for fwd_mcol() if needed */
#endif
aes_32t nr = (kp[45] ^ kp[52] ^ kp[53] ? kp[52] : 14);
#ifdef AES_ERR_CHK
if( (nr != 10 || !(kp[0] | kp[3] | kp[4]))
&& (nr != 12 || !(kp[0] | kp[5] | kp[6]))
&& (nr != 14 || !(kp[0] | kp[7] | kp[8])) )
return aes_error;
#endif
state_in(b0, in_blk, kp);
#if (ENC_UNROLL == FULL)
switch(nr)
{
case 14:
round(fwd_rnd, b1, b0, kp + 1 * N_COLS);
round(fwd_rnd, b0, b1, kp + 2 * N_COLS);
kp += 2 * N_COLS;
case 12:
round(fwd_rnd, b1, b0, kp + 1 * N_COLS);
round(fwd_rnd, b0, b1, kp + 2 * N_COLS);
kp += 2 * N_COLS;
case 10:
round(fwd_rnd, b1, b0, kp + 1 * N_COLS);
round(fwd_rnd, b0, b1, kp + 2 * N_COLS);
round(fwd_rnd, b1, b0, kp + 3 * N_COLS);
round(fwd_rnd, b0, b1, kp + 4 * N_COLS);
round(fwd_rnd, b1, b0, kp + 5 * N_COLS);
round(fwd_rnd, b0, b1, kp + 6 * N_COLS);
round(fwd_rnd, b1, b0, kp + 7 * N_COLS);
round(fwd_rnd, b0, b1, kp + 8 * N_COLS);
round(fwd_rnd, b1, b0, kp + 9 * N_COLS);
round(fwd_lrnd, b0, b1, kp +10 * N_COLS);
}
#else
#if (ENC_UNROLL == PARTIAL)
{ aes_32t rnd;
for(rnd = 0; rnd < (nr >> 1) - 1; ++rnd)
{
kp += N_COLS;
round(fwd_rnd, b1, b0, kp);
kp += N_COLS;
round(fwd_rnd, b0, b1, kp);
}
kp += N_COLS;
round(fwd_rnd, b1, b0, kp);
#else
{ aes_32t rnd;
for(rnd = 0; rnd < nr - 1; ++rnd)
{
kp += N_COLS;
round(fwd_rnd, b1, b0, kp);
l_copy(b0, b1);
}
#endif
kp += N_COLS;
round(fwd_lrnd, b0, b1, kp);
}
#endif
state_out(out_blk, b0);
#ifdef AES_ERR_CHK
return aes_good;
#endif
}
| aes_rval aes_encrypt_key128 | ( | const void * | in_key, |
| aes_encrypt_ctx | cx[1] | ||
| ) |