return_type aes_encrypt( const unsigned char in[N_BLOCK], unsigned char out[N_BLOCK], const aes_context ctx[1] ) { if( ctx->rnd ) { uint_8t s1[N_BLOCK], r; copy_and_key( s1, in, ctx->ksch ); for( r = 1 ; r < ctx->rnd ; ++r ) #if defined( VERSION_1 ) { mix_sub_columns( s1 ); add_round_key( s1, ctx->ksch + r * N_BLOCK); } #else { uint_8t s2[N_BLOCK]; mix_sub_columns( s2, s1 ); copy_and_key( s1, s2, ctx->ksch + r * N_BLOCK); } #endif shift_sub_rows( s1 ); copy_and_key( out, s1, ctx->ksch + r * N_BLOCK ); } else return (return_type) -1; return 0; }
void aes_encrypt_128( const unsigned char in[N_BLOCK], unsigned char out[N_BLOCK], const unsigned char key[N_BLOCK], unsigned char o_key[N_BLOCK] ) { uint_8t s1[N_BLOCK], r, rc = 1; if(o_key != key) block16_copy( o_key, key ); copy_and_key( s1, in, o_key ); for( r = 1 ; r < 10 ; ++r ) #if defined( VERSION_1 ) { mix_sub_columns( s1 ); update_encrypt_key_128( o_key, &rc ); add_round_key( s1, o_key ); } #else { uint_8t s2[N_BLOCK]; mix_sub_columns( s2, s1 ); update_encrypt_key_128( o_key, &rc ); copy_and_key( s1, s2, o_key ); } #endif shift_sub_rows( s1 ); update_encrypt_key_128( o_key, &rc ); copy_and_key( out, s1, o_key ); }
byte AES::encrypt (byte plain [N_BLOCK], byte cipher [N_BLOCK]) { if (round) { byte s1 [N_BLOCK], r ; copy_and_key (s1, plain, (byte*) (key_sched)) ; for (r = 1 ; r < round ; r++) { byte s2 [N_BLOCK] ; mix_sub_columns (s2, s1) ; copy_and_key (s1, s2, (byte*) (key_sched + r * N_BLOCK)) ; } shift_sub_rows (s1) ; copy_and_key (cipher, s1, (byte*) (key_sched + r * N_BLOCK)) ; } else { return AES_FAILURE ; } return AES_SUCCESS ; }
/** * Encrypts a single block of 16 bytes * @param in Buffer holding the input data * @param out Buffer holding the output data * @param ctx AES context * @return Status from the result */ aes_result AES::aes_encrypt( const unsigned char in[N_BLOCK], unsigned char out[N_BLOCK], const aes_context ctx[1] ) { if( ctx->rnd ) { uint_8t s1[N_BLOCK], r; copy_and_key( s1, in, ctx->ksch ); for( r = 1 ; r < ctx->rnd ; ++r ) { mix_sub_columns( s1 ); add_round_key( s1, ctx->ksch + r * N_BLOCK); } shift_sub_rows( s1 ); copy_and_key( out, s1, ctx->ksch + r * N_BLOCK ); } else return -1; return 0; }
/* encrypt one 128 bit block */ void nv_aes_encrypt(u_int8_t *in, u_int8_t *expkey, u_int8_t *out) { u_int8_t state[NVAES_STATECOLS * 4]; u_int32_t round; memcpy(state, in, NVAES_STATECOLS * 4); add_round_key((u_int32_t *)state, (u_int32_t *)expkey); for (round = 1; round < NVAES_ROUNDS + 1; round++) { if (round < NVAES_ROUNDS) mix_sub_columns (state); else shift_rows (state); add_round_key((u_int32_t *)state, (u_int32_t *)expkey + round * NVAES_STATECOLS); } memcpy(out, state, sizeof(state)); }