Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "common.h"
00024 #include "aes.h"
00025
00026 typedef struct AVAES{
00027
00028
00029 uint8_t round_key[15][4][4];
00030 uint8_t state[2][4][4];
00031 int rounds;
00032 }AVAES;
00033
00034 const int av_aes_size= sizeof(AVAES);
00035
00036 static const uint8_t rcon[10] = {
00037 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36
00038 };
00039
00040 static uint8_t sbox[256];
00041 static uint8_t inv_sbox[256];
00042 #if CONFIG_SMALL
00043 static uint32_t enc_multbl[1][256];
00044 static uint32_t dec_multbl[1][256];
00045 #else
00046 static uint32_t enc_multbl[4][256];
00047 static uint32_t dec_multbl[4][256];
00048 #endif
00049
00050 static inline void addkey(uint64_t dst[2], const uint64_t src[2], const uint64_t round_key[2]){
00051 dst[0] = src[0] ^ round_key[0];
00052 dst[1] = src[1] ^ round_key[1];
00053 }
00054
00055 static void subshift(uint8_t s0[2][16], int s, const uint8_t *box){
00056 uint8_t (*s1)[16]= s0[0] - s;
00057 uint8_t (*s3)[16]= s0[0] + s;
00058 s0[0][0]=box[s0[1][ 0]]; s0[0][ 4]=box[s0[1][ 4]]; s0[0][ 8]=box[s0[1][ 8]]; s0[0][12]=box[s0[1][12]];
00059 s1[0][3]=box[s1[1][ 7]]; s1[0][ 7]=box[s1[1][11]]; s1[0][11]=box[s1[1][15]]; s1[0][15]=box[s1[1][ 3]];
00060 s0[0][2]=box[s0[1][10]]; s0[0][10]=box[s0[1][ 2]]; s0[0][ 6]=box[s0[1][14]]; s0[0][14]=box[s0[1][ 6]];
00061 s3[0][1]=box[s3[1][13]]; s3[0][13]=box[s3[1][ 9]]; s3[0][ 9]=box[s3[1][ 5]]; s3[0][ 5]=box[s3[1][ 1]];
00062 }
00063
00064 static inline int mix_core(uint32_t multbl[4][256], int a, int b, int c, int d){
00065 #if CONFIG_SMALL