FFmpeg
aes.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Rodger Combs <rodger.combs@gmail.com>
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 #include "checkasm.h"
22 #include "libavutil/aes.h"
23 #include "libavutil/aes_internal.h"
24 #include "libavutil/internal.h"
25 
26 #define MAX_COUNT 16
27 
29 {
30  int i, j, d;
31  AVAES b;
32  uint8_t pt[MAX_COUNT * 16];
33  uint8_t temp[2][MAX_COUNT * 16];
34  uint8_t iv[2][16];
35 
36  for (d = 0; d <= 1; d++) {
37  for (i = 128; i <= 256; i += 64) {
38  av_aes_init(&b, (const uint8_t*)"PI=3.1415926535897932384626433..", i, d);
39  if (check_func(b.crypt, "aes_%scrypt_%i", d ? "de" : "en", i)) {
40  declare_func(void, AVAES *a, uint8_t *dst, const uint8_t *src,
41  int count, uint8_t *iv, int rounds);
42  int count = (rnd() & (MAX_COUNT - 1)) + 1;
43  for (j = 0; j < 16 * MAX_COUNT; j++)
44  pt[j] = rnd();
45  for (j = 0; j < 16; j++)
46  iv[0][j] = iv[1][j] = rnd();
47  call_ref(&b, temp[0], pt, count, iv[0], b.rounds);
48  call_new(&b, temp[1], pt, count, iv[1], b.rounds);
49  if (memcmp(temp[0], temp[1], sizeof(16 * count)))
50  fail();
51  if (memcmp(iv[0], iv[1], sizeof(iv[0])))
52  fail();
53  call_ref(&b, temp[0], pt, count, NULL, b.rounds);
54  call_new(&b, temp[1], pt, count, NULL, b.rounds);
55  if (memcmp(temp[0], temp[1], sizeof(16 * count)))
56  fail();
57  if (memcmp(iv[0], iv[1], sizeof(iv[0])))
58  fail();
59  bench_new(&b, temp[1], pt, MAX_COUNT, NULL, b.rounds);
60  }
61  }
62  report("%scrypt", d ? "de" : "en");
63  }
64 }
av_aes_init
int av_aes_init(AVAES *a, const uint8_t *key, int key_bits, int decrypt)
Initialize an AVAES context.
Definition: aes.c:201
checkasm_check_aes
void checkasm_check_aes(void)
Definition: aes.c:28
check_func
#define check_func(func,...)
Definition: checkasm.h:185
b
#define b
Definition: input.c:42
call_ref
#define call_ref(...)
Definition: checkasm.h:200
AVAES::rounds
int rounds
Definition: aes_internal.h:39
fail
#define fail()
Definition: checkasm.h:194
checkasm.h
rnd
#define rnd()
Definition: checkasm.h:178
aes.h
call_new
#define call_new(...)
Definition: checkasm.h:303
NULL
#define NULL
Definition: coverity.c:32
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:83
MAX_COUNT
#define MAX_COUNT
Definition: aes.c:26
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
pt
int pt
Definition: rtp.c:35
aes_internal.h
report
#define report
Definition: checkasm.h:197
bench_new
#define bench_new(...)
Definition: checkasm.h:374
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
internal.h
AVAES
Definition: aes_internal.h:34
temp
else temp
Definition: vf_mcdeint.c:263
declare_func
#define declare_func(ret,...)
Definition: checkasm.h:189
src
#define src
Definition: vp8dsp.c:248