]> git.sesse.net Git - ffmpeg/blobdiff - libavutil/aes.c
Add support for RVTR fourCC
[ffmpeg] / libavutil / aes.c
index b05d56e59db1f66bc9e4f323d6c640f4c07339ba..5030dac487e063a7fa257e4075f1784aa45464d5 100644 (file)
@@ -1,6 +1,8 @@
 /*
  * copyright (c) 2007 Michael Niedermayer <michaelni@gmx.at>
  *
+ * some optimization ideas from aes128.c by Reimar Doeffinger
+ *
  * This file is part of FFmpeg.
  *
  * FFmpeg is free software; you can redistribute it and/or
  * You should have received a copy of the GNU Lesser General Public
  * License along with FFmpeg; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * some optimization ideas from aes128.c by Reimar Doeffinger
  */
 
 #include "common.h"
 #include "aes.h"
 
 typedef struct AVAES{
+    // Note: round_key[16] is accessed in the init code, but this only
+    // overwrites state, which does not matter (see also r7471).
     uint8_t round_key[15][4][4];
     uint8_t state[2][4][4];
     int rounds;
@@ -85,7 +87,7 @@ static inline void crypt(AVAES *a, int s, uint8_t *sbox, uint32_t *multbl){
     subshift(a->state[0][0], s, sbox);
 }
 
-void aes_crypt(AVAES *a, uint8_t *dst, uint8_t *src, int count, uint8_t *iv, int decrypt){
+void av_aes_crypt(AVAES *a, uint8_t *dst, uint8_t *src, int count, uint8_t *iv, int decrypt){
     while(count--){
         addkey(a->state[1], src, a->round_key[a->rounds]);
         if(decrypt) {
@@ -120,7 +122,7 @@ static void init_multbl2(uint8_t tbl[1024], int c[4], uint8_t *log8, uint8_t *al
 }
 
 // this is based on the reference AES code by Paulo Barreto and Vincent Rijmen
-int av_aes_init(AVAES *a, uint8_t *key, int key_bits, int decrypt) {
+int av_aes_init(AVAES *a, const uint8_t *key, int key_bits, int decrypt) {
     int i, j, t, rconpointer = 0;
     uint8_t tk[8][4];
     int KC= key_bits>>5;
@@ -128,7 +130,7 @@ int av_aes_init(AVAES *a, uint8_t *key, int key_bits, int decrypt) {
     uint8_t  log8[256];
     uint8_t alog8[512];
 
-    if(!enc_multbl[4][1023]){
+    if(!enc_multbl[0][sizeof(enc_multbl)/sizeof(enc_multbl[0][0])-1]){
         j=1;
         for(i=0; i<255; i++){
             alog8[i]=
@@ -192,7 +194,9 @@ int av_aes_init(AVAES *a, uint8_t *key, int key_bits, int decrypt) {
 #ifdef TEST
 #include "log.h"
 
-int main(){
+#undef random
+
+int main(void){
     int i,j;
     AVAES ae, ad, b;
     uint8_t rkey[2][16]= {
@@ -212,7 +216,7 @@ int main(){
 
     for(i=0; i<2; i++){
         av_aes_init(&b, rkey[i], 128, 1);
-        aes_crypt(&b, temp, rct[i], 1, NULL, 1);
+        av_aes_crypt(&b, temp, rct[i], 1, NULL, 1);
         for(j=0; j<16; j++)
             if(rpt[i][j] != temp[j])
                 av_log(NULL, AV_LOG_ERROR, "%d %02X %02X\n", j, rpt[i][j], temp[j]);
@@ -223,10 +227,10 @@ int main(){
             pt[j]= random();
         }
 {START_TIMER
-        aes_crypt(&ae, temp, pt, 1, NULL, 0);
+        av_aes_crypt(&ae, temp, pt, 1, NULL, 0);
         if(!(i&(i-1)))
             av_log(NULL, AV_LOG_ERROR, "%02X %02X %02X %02X\n", temp[0], temp[5], temp[10], temp[15]);
-        aes_crypt(&ad, temp, temp, 1, NULL, 1);
+        av_aes_crypt(&ad, temp, temp, 1, NULL, 1);
 STOP_TIMER("aes")}
         for(j=0; j<16; j++){
             if(pt[j] != temp[j]){