Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Macros | Functions | Variables
aes_generic.c File Reference
#include <crypto/aes.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/types.h>
#include <linux/errno.h>
#include <linux/crypto.h>
#include <asm/byteorder.h>

Go to the source code of this file.

Macros

#define star_x(x)   (((x) & 0x7f7f7f7f) << 1) ^ ((((x) & 0x80808080) >> 7) * 0x1b)
 
#define imix_col(y, x)
 
#define ls_box(x)
 
#define loop4(i)
 
#define loop6(i)
 
#define loop8tophalf(i)
 
#define loop8(i)
 
#define f_rn(bo, bi, n, k)
 
#define f_nround(bo, bi, k)
 
#define f_rl(bo, bi, n, k)
 
#define f_lround(bo, bi, k)
 
#define i_rn(bo, bi, n, k)
 
#define i_nround(bo, bi, k)
 
#define i_rl(bo, bi, n, k)
 
#define i_lround(bo, bi, k)
 

Functions

 EXPORT_SYMBOL_GPL (crypto_ft_tab)
 
 EXPORT_SYMBOL_GPL (crypto_fl_tab)
 
 EXPORT_SYMBOL_GPL (crypto_it_tab)
 
 EXPORT_SYMBOL_GPL (crypto_il_tab)
 
int crypto_aes_expand_key (struct crypto_aes_ctx *ctx, const u8 *in_key, unsigned int key_len)
 
 EXPORT_SYMBOL_GPL (crypto_aes_expand_key)
 
int crypto_aes_set_key (struct crypto_tfm *tfm, const u8 *in_key, unsigned int key_len)
 
 EXPORT_SYMBOL_GPL (crypto_aes_set_key)
 
 module_init (aes_init)
 
 module_exit (aes_fini)
 
 MODULE_DESCRIPTION ("Rijndael (AES) Cipher Algorithm")
 
 MODULE_LICENSE ("Dual BSD/GPL")
 
 MODULE_ALIAS ("aes")
 

Variables

const u32 crypto_ft_tab [4][256]
 
const u32 crypto_fl_tab [4][256]
 
const u32 crypto_it_tab [4][256]
 
const u32 crypto_il_tab [4][256]
 

Macro Definition Documentation

#define f_lround (   bo,
  bi,
  k 
)
Value:
do {\
f_rl(bo, bi, 0, k); \
f_rl(bo, bi, 1, k); \
f_rl(bo, bi, 2, k); \
f_rl(bo, bi, 3, k); \
} while (0)

Definition at line 1322 of file aes_generic.c.

#define f_nround (   bo,
  bi,
  k 
)
Value:
do {\
f_rn(bo, bi, 0, k); \
f_rn(bo, bi, 1, k); \
f_rn(bo, bi, 2, k); \
f_rn(bo, bi, 3, k); \
k += 4; \
} while (0)

Definition at line 1307 of file aes_generic.c.

#define f_rl (   bo,
  bi,
  n,
  k 
)
Value:
do { \
bo[n] = crypto_fl_tab[0][byte(bi[n], 0)] ^ \
crypto_fl_tab[1][byte(bi[(n + 1) & 3], 1)] ^ \
crypto_fl_tab[2][byte(bi[(n + 2) & 3], 2)] ^ \
crypto_fl_tab[3][byte(bi[(n + 3) & 3], 3)] ^ *(k + n); \
} while (0)

Definition at line 1315 of file aes_generic.c.

#define f_rn (   bo,
  bi,
  n,
  k 
)
Value:
do { \
bo[n] = crypto_ft_tab[0][byte(bi[n], 0)] ^ \
crypto_ft_tab[1][byte(bi[(n + 1) & 3], 1)] ^ \
crypto_ft_tab[2][byte(bi[(n + 2) & 3], 2)] ^ \
crypto_ft_tab[3][byte(bi[(n + 3) & 3], 3)] ^ *(k + n); \
} while (0)

Definition at line 1300 of file aes_generic.c.

#define i_lround (   bo,
  bi,
  k 
)
Value:
do {\
i_rl(bo, bi, 0, k); \
i_rl(bo, bi, 1, k); \
i_rl(bo, bi, 2, k); \
i_rl(bo, bi, 3, k); \
} while (0)

Definition at line 1394 of file aes_generic.c.

#define i_nround (   bo,
  bi,
  k 
)
Value:
do {\
i_rn(bo, bi, 0, k); \
i_rn(bo, bi, 1, k); \
i_rn(bo, bi, 2, k); \
i_rn(bo, bi, 3, k); \
k += 4; \
} while (0)

Definition at line 1379 of file aes_generic.c.

#define i_rl (   bo,
  bi,
  n,
  k 
)
Value:
do { \
bo[n] = crypto_il_tab[0][byte(bi[n], 0)] ^ \
crypto_il_tab[1][byte(bi[(n + 3) & 3], 1)] ^ \
crypto_il_tab[2][byte(bi[(n + 2) & 3], 2)] ^ \
crypto_il_tab[3][byte(bi[(n + 1) & 3], 3)] ^ *(k + n); \
} while (0)

Definition at line 1387 of file aes_generic.c.

#define i_rn (   bo,
  bi,
  n,
  k 
)
Value:
do { \
bo[n] = crypto_it_tab[0][byte(bi[n], 0)] ^ \
crypto_it_tab[1][byte(bi[(n + 3) & 3], 1)] ^ \
crypto_it_tab[2][byte(bi[(n + 2) & 3], 2)] ^ \
crypto_it_tab[3][byte(bi[(n + 1) & 3], 3)] ^ *(k + n); \
} while (0)

Definition at line 1372 of file aes_generic.c.

#define imix_col (   y,
  x 
)
Value:
do { \
u = star_x(x); \
v = star_x(u); \
w = star_x(v); \
t = w ^ (x); \
(y) = u ^ v ^ w; \
(y) ^= ror32(u ^ t, 8) ^ \
ror32(v ^ t, 16) ^ \
ror32(t, 24); \
} while (0)

Definition at line 1130 of file aes_generic.c.

#define loop4 (   i)
Value:
do { \
t = ror32(t, 8); \
t = ls_box(t) ^ rco_tab[i]; \
t ^= ctx->key_enc[4 * i]; \
ctx->key_enc[4 * i + 4] = t; \
t ^= ctx->key_enc[4 * i + 1]; \
ctx->key_enc[4 * i + 5] = t; \
t ^= ctx->key_enc[4 * i + 2]; \
ctx->key_enc[4 * i + 6] = t; \
t ^= ctx->key_enc[4 * i + 3]; \
ctx->key_enc[4 * i + 7] = t; \
} while (0)

Definition at line 1147 of file aes_generic.c.

#define loop6 (   i)
Value:
do { \
t = ror32(t, 8); \
t = ls_box(t) ^ rco_tab[i]; \
t ^= ctx->key_enc[6 * i]; \
ctx->key_enc[6 * i + 6] = t; \
t ^= ctx->key_enc[6 * i + 1]; \
ctx->key_enc[6 * i + 7] = t; \
t ^= ctx->key_enc[6 * i + 2]; \
ctx->key_enc[6 * i + 8] = t; \
t ^= ctx->key_enc[6 * i + 3]; \
ctx->key_enc[6 * i + 9] = t; \
t ^= ctx->key_enc[6 * i + 4]; \
ctx->key_enc[6 * i + 10] = t; \
t ^= ctx->key_enc[6 * i + 5]; \
ctx->key_enc[6 * i + 11] = t; \
} while (0)

Definition at line 1160 of file aes_generic.c.

#define loop8 (   i)
Value:
do { \
loop8tophalf(i); \
t = ctx->key_enc[8 * i + 4] ^ ls_box(t); \
ctx->key_enc[8 * i + 12] = t; \
t ^= ctx->key_enc[8 * i + 5]; \
ctx->key_enc[8 * i + 13] = t; \
t ^= ctx->key_enc[8 * i + 6]; \
ctx->key_enc[8 * i + 14] = t; \
t ^= ctx->key_enc[8 * i + 7]; \
ctx->key_enc[8 * i + 15] = t; \
} while (0)

Definition at line 1190 of file aes_generic.c.

#define loop8tophalf (   i)
Value:
do { \
t = ror32(t, 8); \
t = ls_box(t) ^ rco_tab[i]; \
t ^= ctx->key_enc[8 * i]; \
ctx->key_enc[8 * i + 8] = t; \
t ^= ctx->key_enc[8 * i + 1]; \
ctx->key_enc[8 * i + 9] = t; \
t ^= ctx->key_enc[8 * i + 2]; \
ctx->key_enc[8 * i + 10] = t; \
t ^= ctx->key_enc[8 * i + 3]; \
ctx->key_enc[8 * i + 11] = t; \
} while (0)

Definition at line 1177 of file aes_generic.c.

#define ls_box (   x)
Value:
crypto_fl_tab[0][byte(x, 0)] ^ \
crypto_fl_tab[1][byte(x, 1)] ^ \
crypto_fl_tab[2][byte(x, 2)] ^ \
crypto_fl_tab[3][byte(x, 3)]

Definition at line 1141 of file aes_generic.c.

#define star_x (   x)    (((x) & 0x7f7f7f7f) << 1) ^ ((((x) & 0x80808080) >> 7) * 0x1b)

Definition at line 1128 of file aes_generic.c.

Function Documentation

int crypto_aes_expand_key ( struct crypto_aes_ctx ctx,
const u8 in_key,
unsigned int  key_len 
)

crypto_aes_expand_key - Expands the AES key as described in FIPS-197 : The location where the computed key will be stored. : The supplied key. : The length of the supplied key.

Returns 0 on success. The function fails only if an invalid key size (or pointer) is supplied. The expanded key size is 240 bytes (max of 14 rounds with a unique 16 bytes key schedule plus a 16 bytes key which is used before the first round). The decryption key is prepared for the "Equivalent Inverse Cipher" as described in FIPS-197. The first slot (16 bytes) of each key (enc or dec) is for the initial combination, the second slot for the first round and so on.

Definition at line 1216 of file aes_generic.c.

int crypto_aes_set_key ( struct crypto_tfm tfm,
const u8 in_key,
unsigned int  key_len 
)

crypto_aes_set_key - Set the AES key. : The crypto_tfm that is used in the context. : The input key. : The size of the key.

Returns 0 on success, on failure the CRYPTO_TFM_RES_BAD_KEY_LEN flag in tfm is set. The function uses crypto_aes_expand_key() to expand the key. &crypto_aes_ctx must be the private data embedded in which is retrieved with crypto_tfm_ctx().

Definition at line 1282 of file aes_generic.c.

EXPORT_SYMBOL_GPL ( crypto_ft_tab  )
EXPORT_SYMBOL_GPL ( crypto_fl_tab  )
EXPORT_SYMBOL_GPL ( crypto_it_tab  )
EXPORT_SYMBOL_GPL ( crypto_il_tab  )
EXPORT_SYMBOL_GPL ( crypto_aes_expand_key  )
EXPORT_SYMBOL_GPL ( crypto_aes_set_key  )
MODULE_ALIAS ( "aes"  )
MODULE_DESCRIPTION ( "Rijndael (AES) Cipher Algorithm"  )
module_exit ( aes_fini  )
module_init ( aes_init  )
MODULE_LICENSE ( "Dual BSD/GPL"  )

Variable Documentation

const u32 crypto_fl_tab[4][256]

Definition at line 329 of file aes_generic.c.

const u32 crypto_ft_tab[4][256]

Definition at line 65 of file aes_generic.c.

const u32 crypto_il_tab[4][256]

Definition at line 857 of file aes_generic.c.

const u32 crypto_it_tab[4][256]

Definition at line 593 of file aes_generic.c.