[FFmpeg-devel] [PATCH 09/10] tools/crypto_bench: add AES-CBC modes
--- tools/crypto_bench.c | 138 +-- 1 file changed, 135 insertions(+), 3 deletions(-) diff --git a/tools/crypto_bench.c b/tools/crypto_bench.c index ad20f95..0b1bfc8 100644 --- a/tools/crypto_bench.c +++ b/tools/crypto_bench.c @@ -52,6 +52,7 @@ static const char *enabled_algos; static unsigned specified_runs; static const uint8_t *hardcoded_key = "FFmpeg is the best program ever."; +static const uint8_t hardcoded_iv[16] = {0}; static void fatal_error(const char *tag) { @@ -136,6 +137,39 @@ static void run_lavu_aes256(uint8_t *output, const uint8_t *input, unsigned size av_aes_crypt(aes, output, input, size >> 4, NULL, 0); } +static void run_lavu_aes128cbc(uint8_t *output, const uint8_t *input, unsigned size) +{ +static struct AVAES *aes; +static uint8_t *iv; +if ((!aes && !(aes = av_aes_alloc())) || (!iv && !(iv = av_malloc(16 +fatal_error("out of memory"); +memcpy(iv, hardcoded_iv, 16); +av_aes_init(aes, hardcoded_key, 128, 0); +av_aes_crypt(aes, output, input, size >> 4, iv, 0); +} + +static void run_lavu_aes192cbc(uint8_t *output, const uint8_t *input, unsigned size) +{ +static struct AVAES *aes; +static uint8_t *iv; +if ((!aes && !(aes = av_aes_alloc())) || (!iv && !(iv = av_malloc(16 +fatal_error("out of memory"); +memcpy(iv, hardcoded_iv, 16); +av_aes_init(aes, hardcoded_key, 192, 0); +av_aes_crypt(aes, output, input, size >> 4, iv, 0); +} + +static void run_lavu_aes256cbc(uint8_t *output, const uint8_t *input, unsigned size) +{ +static struct AVAES *aes; +static uint8_t *iv; +if ((!aes && !(aes = av_aes_alloc())) || (!iv && !(iv = av_malloc(16 +fatal_error("out of memory"); +memcpy(iv, hardcoded_iv, 16); +av_aes_init(aes, hardcoded_key, 256, 0); +av_aes_crypt(aes, output, input, size >> 4, iv, 0); +} + static void run_lavu_blowfish(uint8_t *output, const uint8_t *input, unsigned size) { @@ -258,6 +292,42 @@ static void run_crypto_aes256(uint8_t *output, const uint8_t *input, unsigned si AES_encrypt(input + i, output + i, ); } +static void run_crypto_aes128cbc(uint8_t *output, const uint8_t *input, unsigned size) +{ +AES_KEY aes; +static uint8_t *iv; +if ((!iv && !(iv = av_malloc(16 +fatal_error("out of memory"); +memcpy(iv, hardcoded_iv, 16); + +AES_set_encrypt_key(hardcoded_key, 128, ); +AES_cbc_encrypt(input, output, size, , iv, 1); +} + +static void run_crypto_aes192cbc(uint8_t *output, const uint8_t *input, unsigned size) +{ +AES_KEY aes; +static uint8_t *iv; +if ((!iv && !(iv = av_malloc(16 +fatal_error("out of memory"); +memcpy(iv, hardcoded_iv, 16); + +AES_set_encrypt_key(hardcoded_key, 192, ); +AES_cbc_encrypt(input, output, size, , iv, 1); +} + +static void run_crypto_aes256cbc(uint8_t *output, const uint8_t *input, unsigned size) +{ +AES_KEY aes; +static uint8_t *iv; +if ((!iv && !(iv = av_malloc(16 +fatal_error("out of memory"); +memcpy(iv, hardcoded_iv, 16); + +AES_set_encrypt_key(hardcoded_key, 256, ); +AES_cbc_encrypt(input, output, size, , iv, 1); +} + static void run_crypto_blowfish(uint8_t *output, const uint8_t *input, unsigned size) { @@ -355,6 +425,39 @@ static void run_gcrypt_aes256(uint8_t *output, const uint8_t *input, unsigned si gcry_cipher_encrypt(aes, output, size, input, size); } +static void run_gcrypt_aes128cbc(uint8_t *output, + const uint8_t *input, unsigned size) +{ +static gcry_cipher_hd_t aes; +if (!aes) +gcry_cipher_open(, GCRY_CIPHER_AES128, GCRY_CIPHER_MODE_CBC, 0); +gcry_cipher_setkey(aes, hardcoded_key, 16); +gcry_cipher_setiv(aes, hardcoded_iv, 16); +gcry_cipher_encrypt(aes, output, size, input, size); +} + +static void run_gcrypt_aes192cbc(uint8_t *output, + const uint8_t *input, unsigned size) +{ +static gcry_cipher_hd_t aes; +if (!aes) +gcry_cipher_open(, GCRY_CIPHER_AES192, GCRY_CIPHER_MODE_CBC, 0); +gcry_cipher_setkey(aes, hardcoded_key, 24); +gcry_cipher_setiv(aes, hardcoded_iv, 16); +gcry_cipher_encrypt(aes, output, size, input, size); +} + +static void run_gcrypt_aes256cbc(uint8_t *output, + const uint8_t *input, unsigned size) +{ +static gcry_cipher_hd_t aes; +if (!aes) +gcry_cipher_open(, GCRY_CIPHER_AES256, GCRY_CIPHER_MODE_CBC, 0); +gcry_cipher_setkey(aes, hardcoded_key, 32); +gcry_cipher_setiv(aes, hardcoded_iv, 16); +gcry_cipher_encrypt(aes, output, size, input, size); +} + static void run_gcrypt_blowfish(uint8_t *output, const uint8_t *input, unsigned size) { @@ -459,6 +562,30 @@ static void run_tomcrypt_aes256(uint8_t *output, const uint8_t *input, unsigned
Re: [FFmpeg-devel] [PATCH 09/10] tools/crypto_bench: add AES-CBC modes
On Mon, Oct 12, 2015 at 07:33:32PM -0500, Rodger Combs wrote: > --- > tools/crypto_bench.c | 138 > +-- > 1 file changed, 135 insertions(+), 3 deletions(-) > > diff --git a/tools/crypto_bench.c b/tools/crypto_bench.c > index ad20f95..0b1bfc8 100644 > --- a/tools/crypto_bench.c > +++ b/tools/crypto_bench.c > @@ -52,6 +52,7 @@ static const char *enabled_algos; > static unsigned specified_runs; > > static const uint8_t *hardcoded_key = "FFmpeg is the best program ever."; > +static const uint8_t hardcoded_iv[16] = {0}; > > static void fatal_error(const char *tag) > { > @@ -136,6 +137,39 @@ static void run_lavu_aes256(uint8_t *output, const > uint8_t *input, unsigned size > av_aes_crypt(aes, output, input, size >> 4, NULL, 0); > } > > +static void run_lavu_aes128cbc(uint8_t *output, const uint8_t *input, > unsigned size) > +{ > +static struct AVAES *aes; > +static uint8_t *iv; > +if ((!aes && !(aes = av_aes_alloc())) || (!iv && !(iv = av_malloc(16 > +fatal_error("out of memory"); > +memcpy(iv, hardcoded_iv, 16); > +av_aes_init(aes, hardcoded_key, 128, 0); > +av_aes_crypt(aes, output, input, size >> 4, iv, 0); > +} > + > +static void run_lavu_aes192cbc(uint8_t *output, const uint8_t *input, > unsigned size) > +{ > +static struct AVAES *aes; > +static uint8_t *iv; > +if ((!aes && !(aes = av_aes_alloc())) || (!iv && !(iv = av_malloc(16 > +fatal_error("out of memory"); > +memcpy(iv, hardcoded_iv, 16); > +av_aes_init(aes, hardcoded_key, 192, 0); > +av_aes_crypt(aes, output, input, size >> 4, iv, 0); > +} > + > +static void run_lavu_aes256cbc(uint8_t *output, const uint8_t *input, > unsigned size) > +{ > +static struct AVAES *aes; > +static uint8_t *iv; > +if ((!aes && !(aes = av_aes_alloc())) || (!iv && !(iv = av_malloc(16 > +fatal_error("out of memory"); > +memcpy(iv, hardcoded_iv, 16); > +av_aes_init(aes, hardcoded_key, 256, 0); > +av_aes_crypt(aes, output, input, size >> 4, iv, 0); > +} > + > static void run_lavu_blowfish(uint8_t *output, >const uint8_t *input, unsigned size) > { > @@ -258,6 +292,42 @@ static void run_crypto_aes256(uint8_t *output, const > uint8_t *input, unsigned si > AES_encrypt(input + i, output + i, ); > } > > +static void run_crypto_aes128cbc(uint8_t *output, const uint8_t *input, > unsigned size) > +{ > +AES_KEY aes; > +static uint8_t *iv; > +if ((!iv && !(iv = av_malloc(16 > +fatal_error("out of memory"); > +memcpy(iv, hardcoded_iv, 16); > + > +AES_set_encrypt_key(hardcoded_key, 128, ); > +AES_cbc_encrypt(input, output, size, , iv, 1); > +} > + > +static void run_crypto_aes192cbc(uint8_t *output, const uint8_t *input, > unsigned size) > +{ > +AES_KEY aes; > +static uint8_t *iv; > +if ((!iv && !(iv = av_malloc(16 > +fatal_error("out of memory"); > +memcpy(iv, hardcoded_iv, 16); > + > +AES_set_encrypt_key(hardcoded_key, 192, ); > +AES_cbc_encrypt(input, output, size, , iv, 1); > +} > + > +static void run_crypto_aes256cbc(uint8_t *output, const uint8_t *input, > unsigned size) > +{ > +AES_KEY aes; > +static uint8_t *iv; > +if ((!iv && !(iv = av_malloc(16 > +fatal_error("out of memory"); > +memcpy(iv, hardcoded_iv, 16); > + > +AES_set_encrypt_key(hardcoded_key, 256, ); > +AES_cbc_encrypt(input, output, size, , iv, 1); > +} > + > static void run_crypto_blowfish(uint8_t *output, > const uint8_t *input, unsigned size) > { > @@ -355,6 +425,39 @@ static void run_gcrypt_aes256(uint8_t *output, const > uint8_t *input, unsigned si > gcry_cipher_encrypt(aes, output, size, input, size); > } > > +static void run_gcrypt_aes128cbc(uint8_t *output, > + const uint8_t *input, unsigned size) > +{ > +static gcry_cipher_hd_t aes; > +if (!aes) > +gcry_cipher_open(, GCRY_CIPHER_AES128, GCRY_CIPHER_MODE_CBC, 0); > +gcry_cipher_setkey(aes, hardcoded_key, 16); > +gcry_cipher_setiv(aes, hardcoded_iv, 16); > +gcry_cipher_encrypt(aes, output, size, input, size); > +} > + > +static void run_gcrypt_aes192cbc(uint8_t *output, > + const uint8_t *input, unsigned size) > +{ > +static gcry_cipher_hd_t aes; > +if (!aes) > +gcry_cipher_open(, GCRY_CIPHER_AES192, GCRY_CIPHER_MODE_CBC, 0); > +gcry_cipher_setkey(aes, hardcoded_key, 24); > +gcry_cipher_setiv(aes, hardcoded_iv, 16); > +gcry_cipher_encrypt(aes, output, size, input, size); > +} > + > +static void run_gcrypt_aes256cbc(uint8_t *output, > + const uint8_t *input, unsigned size) > +{ > +static gcry_cipher_hd_t aes; > +if (!aes) > +gcry_cipher_open(, GCRY_CIPHER_AES256, GCRY_CIPHER_MODE_CBC, 0); > +gcry_cipher_setkey(aes, hardcoded_key,