[FFmpeg-devel] [PATCH] strict-aliasing-safe aes.c

Måns Rullgård mans
Tue Jun 29 19:44:49 CEST 2010


Reimar D?ffinger <Reimar.Doeffinger at gmx.de> writes:

> -static void subshift(uint8_t s0[2][16], int s, const uint8_t *box){
> -    uint8_t (*s1)[16]= s0[0] - s;
> -    uint8_t (*s3)[16]= s0[0] + s;
> -    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]];
> -    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]];
> -    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]];
> -    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]];
> +static void subshift(av_aes_block s0[2], int s, const uint8_t *box){
> +    av_aes_block *s1= (av_aes_block *)(s0[0].u8 - s);
> +    av_aes_block *s3= (av_aes_block *)(s0[0].u8 + s);
> +    s0[0].u8[0]=box[s0[1].u8[ 0]]; s0[0].u8[ 4]=box[s0[1].u8[ 4]]; s0[0].u8[ 8]=box[s0[1].u8[ 8]]; s0[0].u8[12]=box[s0[1].u8[12]];
> +    s1[0].u8[3]=box[s1[1].u8[ 7]]; s1[0].u8[ 7]=box[s1[1].u8[11]]; s1[0].u8[11]=box[s1[1].u8[15]]; s1[0].u8[15]=box[s1[1].u8[ 3]];
> +    s0[0].u8[2]=box[s0[1].u8[10]]; s0[0].u8[10]=box[s0[1].u8[ 2]]; s0[0].u8[ 6]=box[s0[1].u8[14]]; s0[0].u8[14]=box[s0[1].u8[ 6]];
> +    s3[0].u8[1]=box[s3[1].u8[13]]; s3[0].u8[13]=box[s3[1].u8[ 9]]; s3[0].u8[ 9]=box[s3[1].u8[ 5]]; s3[0].u8[ 5]=box[s3[1].u8[ 1]];
>  }
>  
>  static inline int mix_core(uint32_t multbl[][256], int a, int b, int c, int d){
> @@ -70,11 +77,11 @@
>  #endif
>  }
>  
> -static inline void mix(uint8_t state[2][4][4], uint32_t multbl[][256], int s1, int s3){
> -    ((uint32_t *)(state))[0] = mix_core(multbl, state[1][0][0], state[1][s1  ][1], state[1][2][2], state[1][s3  ][3]);
> -    ((uint32_t *)(state))[1] = mix_core(multbl, state[1][1][0], state[1][s3-1][1], state[1][3][2], state[1][s1-1][3]);
> -    ((uint32_t *)(state))[2] = mix_core(multbl, state[1][2][0], state[1][s3  ][1], state[1][0][2], state[1][s1  ][3]);
> -    ((uint32_t *)(state))[3] = mix_core(multbl, state[1][3][0], state[1][s1-1][1], state[1][1][2], state[1][s3-1][3]);
> +static inline void mix(av_aes_block state[2], uint32_t multbl[][256], int s1, int s3){
> +    state[0].u32[0] = mix_core(multbl, state[1].u8x4[0][0], state[1].u8x4[s1  ][1], state[1].u8x4[2][2], state[1].u8x4[s3  ][3]);
> +    state[0].u32[1] = mix_core(multbl, state[1].u8x4[1][0], state[1].u8x4[s3-1][1], state[1].u8x4[3][2], state[1].u8x4[s1-1][3]);
> +    state[0].u32[2] = mix_core(multbl, state[1].u8x4[2][0], state[1].u8x4[s3  ][1], state[1].u8x4[0][2], state[1].u8x4[s1  ][3]);
> +    state[0].u32[3] = mix_core(multbl, state[1].u8x4[3][0], state[1].u8x4[s1-1][1], state[1].u8x4[1][2], state[1].u8x4[s3-1][3]);
>  }

These blocks are extremely dense both before and after.  Is there any
way they could be made more readable?  This is not a criticism of your
patch, just an observation.

-- 
M?ns Rullg?rd
mans at mansr.com



More information about the ffmpeg-devel mailing list