Go to the source code of this file.
Data Structures | |
struct | _rijndael_ctx |
Typedefs | |
typedef uint8 | u1byte |
typedef uint16 | u2byte |
typedef uint32 | u4byte |
typedef int8 | s1byte |
typedef int16 | s2byte |
typedef int32 | s4byte |
typedef struct _rijndael_ctx | rijndael_ctx |
Functions | |
rijndael_ctx * | rijndael_set_key (rijndael_ctx *, const u4byte *, const u4byte, int) |
void | rijndael_encrypt (rijndael_ctx *, const u4byte *, u4byte *) |
void | rijndael_decrypt (rijndael_ctx *, const u4byte *, u4byte *) |
void | aes_set_key (rijndael_ctx *ctx, const uint8 *key, unsigned keybits, int enc) |
void | aes_ecb_encrypt (rijndael_ctx *ctx, uint8 *data, unsigned len) |
void | aes_ecb_decrypt (rijndael_ctx *ctx, uint8 *data, unsigned len) |
void | aes_cbc_encrypt (rijndael_ctx *ctx, uint8 *iva, uint8 *data, unsigned len) |
void | aes_cbc_decrypt (rijndael_ctx *ctx, uint8 *iva, uint8 *data, unsigned len) |
typedef struct _rijndael_ctx rijndael_ctx |
Definition at line 29 of file rijndael.h.
Definition at line 30 of file rijndael.h.
Definition at line 31 of file rijndael.h.
Definition at line 25 of file rijndael.h.
Definition at line 26 of file rijndael.h.
Definition at line 27 of file rijndael.h.
void aes_cbc_decrypt | ( | rijndael_ctx * | ctx, | |
uint8 * | iva, | |||
uint8 * | data, | |||
unsigned | len | |||
) |
Definition at line 567 of file rijndael.c.
References buf, and rijndael_decrypt().
Referenced by AES_cbc_encrypt(), and rj_decrypt().
{ uint32 *d = (uint32 *) data; unsigned bs = 16; uint32 buf[4], iv[4]; memcpy(iv, iva, bs); while (len >= bs) { buf[0] = d[0]; buf[1] = d[1]; buf[2] = d[2]; buf[3] = d[3]; rijndael_decrypt(ctx, buf, d); d[0] ^= iv[0]; d[1] ^= iv[1]; d[2] ^= iv[2]; d[3] ^= iv[3]; iv[0] = buf[0]; iv[1] = buf[1]; iv[2] = buf[2]; iv[3] = buf[3]; d += 4; len -= bs; } }
void aes_cbc_encrypt | ( | rijndael_ctx * | ctx, | |
uint8 * | iva, | |||
uint8 * | data, | |||
unsigned | len | |||
) |
Definition at line 545 of file rijndael.c.
References rijndael_encrypt().
Referenced by AES_cbc_encrypt(), and rj_encrypt().
{ uint32 *iv = (uint32 *) iva; uint32 *d = (uint32 *) data; unsigned bs = 16; while (len >= bs) { d[0] ^= iv[0]; d[1] ^= iv[1]; d[2] ^= iv[2]; d[3] ^= iv[3]; rijndael_encrypt(ctx, d, d); iv = d; d += bs / 4; len -= bs; } }
void aes_ecb_decrypt | ( | rijndael_ctx * | ctx, | |
uint8 * | data, | |||
unsigned | len | |||
) |
Definition at line 529 of file rijndael.c.
References rijndael_decrypt().
Referenced by AES_ecb_encrypt(), and rj_decrypt().
{ unsigned bs = 16; uint32 *d; while (len >= bs) { d = (uint32 *) data; rijndael_decrypt(ctx, d, d); len -= bs; data += bs; } }
void aes_ecb_encrypt | ( | rijndael_ctx * | ctx, | |
uint8 * | data, | |||
unsigned | len | |||
) |
Definition at line 513 of file rijndael.c.
References rijndael_encrypt().
Referenced by AES_ecb_encrypt(), and rj_encrypt().
{ unsigned bs = 16; uint32 *d; while (len >= bs) { d = (uint32 *) data; rijndael_encrypt(ctx, d, d); len -= bs; data += bs; } }
void aes_set_key | ( | rijndael_ctx * | ctx, | |
const uint8 * | key, | |||
unsigned | keybits, | |||
int | enc | |||
) |
Definition at line 504 of file rijndael.c.
References rijndael_set_key().
Referenced by AES_set_decrypt_key(), AES_set_encrypt_key(), and rj_real_init().
{ uint32 *k; k = (uint32 *) key; rijndael_set_key(ctx, k, keybits, enc); }
void rijndael_decrypt | ( | rijndael_ctx * | , | |
const u4byte * | , | |||
u4byte * | ||||
) |
Definition at line 451 of file rijndael.c.
References _rijndael_ctx::d_key, _rijndael_ctx::e_key, i_lround, i_nround, io_swap, and _rijndael_ctx::k_len.
Referenced by aes_cbc_decrypt(), and aes_ecb_decrypt().
{ u4byte b0[4], b1[4], *kp; u4byte k_len = ctx->k_len; u4byte *e_key = ctx->e_key; u4byte *d_key = ctx->d_key; b0[0] = io_swap(in_blk[0]) ^ e_key[4 * k_len + 24]; b0[1] = io_swap(in_blk[1]) ^ e_key[4 * k_len + 25]; b0[2] = io_swap(in_blk[2]) ^ e_key[4 * k_len + 26]; b0[3] = io_swap(in_blk[3]) ^ e_key[4 * k_len + 27]; kp = d_key + 4 * (k_len + 5); if (k_len > 6) { i_nround(b1, b0, kp); i_nround(b0, b1, kp); } if (k_len > 4) { i_nround(b1, b0, kp); i_nround(b0, b1, kp); } i_nround(b1, b0, kp); i_nround(b0, b1, kp); i_nround(b1, b0, kp); i_nround(b0, b1, kp); i_nround(b1, b0, kp); i_nround(b0, b1, kp); i_nround(b1, b0, kp); i_nround(b0, b1, kp); i_nround(b1, b0, kp); i_lround(b0, b1, kp); out_blk[0] = io_swap(b0[0]); out_blk[1] = io_swap(b0[1]); out_blk[2] = io_swap(b0[2]); out_blk[3] = io_swap(b0[3]); }
void rijndael_encrypt | ( | rijndael_ctx * | , | |
const u4byte * | , | |||
u4byte * | ||||
) |
Definition at line 387 of file rijndael.c.
References _rijndael_ctx::e_key, f_lround, f_nround, io_swap, and _rijndael_ctx::k_len.
Referenced by aes_cbc_encrypt(), aes_ecb_encrypt(), and ciph_encrypt().
{ u4byte k_len = ctx->k_len; u4byte *e_key = ctx->e_key; u4byte b0[4], b1[4], *kp; b0[0] = io_swap(in_blk[0]) ^ e_key[0]; b0[1] = io_swap(in_blk[1]) ^ e_key[1]; b0[2] = io_swap(in_blk[2]) ^ e_key[2]; b0[3] = io_swap(in_blk[3]) ^ e_key[3]; kp = e_key + 4; if (k_len > 6) { f_nround(b1, b0, kp); f_nround(b0, b1, kp); } if (k_len > 4) { f_nround(b1, b0, kp); f_nround(b0, b1, kp); } f_nround(b1, b0, kp); f_nround(b0, b1, kp); f_nround(b1, b0, kp); f_nround(b0, b1, kp); f_nround(b1, b0, kp); f_nround(b0, b1, kp); f_nround(b1, b0, kp); f_nround(b0, b1, kp); f_nround(b1, b0, kp); f_lround(b0, b1, kp); out_blk[0] = io_swap(b0[0]); out_blk[1] = io_swap(b0[1]); out_blk[2] = io_swap(b0[2]); out_blk[3] = io_swap(b0[3]); }
rijndael_ctx* rijndael_set_key | ( | rijndael_ctx * | , | |
const u4byte * | , | |||
const | u4byte, | |||
int | ||||
) |
Definition at line 305 of file rijndael.c.
References _rijndael_ctx::d_key, _rijndael_ctx::decrypt, _rijndael_ctx::e_key, gen_tabs(), i, imix_col, io_swap, _rijndael_ctx::k_len, loop4, loop6, loop8, and tab_gen.
Referenced by aes_set_key(), and ciph_init().
{ u4byte i, t, u, v, w; u4byte *e_key = ctx->e_key; u4byte *d_key = ctx->d_key; ctx->decrypt = !encrypt; if (!tab_gen) gen_tabs(); ctx->k_len = (key_len + 31) / 32; e_key[0] = io_swap(in_key[0]); e_key[1] = io_swap(in_key[1]); e_key[2] = io_swap(in_key[2]); e_key[3] = io_swap(in_key[3]); switch (ctx->k_len) { case 4: t = e_key[3]; for (i = 0; i < 10; ++i) loop4(i); break; case 6: e_key[4] = io_swap(in_key[4]); t = e_key[5] = io_swap(in_key[5]); for (i = 0; i < 8; ++i) loop6(i); break; case 8: e_key[4] = io_swap(in_key[4]); e_key[5] = io_swap(in_key[5]); e_key[6] = io_swap(in_key[6]); t = e_key[7] = io_swap(in_key[7]); for (i = 0; i < 7; ++i) loop8(i); break; } if (!encrypt) { d_key[0] = e_key[0]; d_key[1] = e_key[1]; d_key[2] = e_key[2]; d_key[3] = e_key[3]; for (i = 4; i < 4 * ctx->k_len + 24; ++i) imix_col(d_key[i], e_key[i]); } return ctx; }