Hello, I have added the necessary functions for twofish in crypto_bench. A note, there is no twofish implementation in openssl library but since the code demands that all the libraries have the impl, i have introduced a dummy function. Please let me know if anything has to be changed.
Thanks, Supraja
From 8b195ee7057d65d8cd2f81357af2a700317c993e Mon Sep 17 00:00:00 2001 From: Supraja Meedinti <supraja0...@gmail.com> Date: Sat, 14 Feb 2015 13:21:37 +0530 Subject: [PATCH] tools: crypto_bench: added support for Twofish Signed-off-by: Supraja Meedinti <supraja0...@gmail.com> --- tools/crypto_bench.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tools/crypto_bench.c b/tools/crypto_bench.c index 5e56d12..6b8a7e0 100644 --- a/tools/crypto_bench.c +++ b/tools/crypto_bench.c @@ -77,6 +77,7 @@ struct hash_impl { #include "libavutil/aes.h" #include "libavutil/camellia.h" #include "libavutil/cast5.h" +#include "libavutil/twofish.h" #define IMPL_USE_lavu IMPL_USE @@ -133,6 +134,15 @@ static void run_lavu_cast128(uint8_t *output, av_cast5_crypt(cast, output, input, size >> 3, 0); } +static void run_lavu_twofish(uint8_t *output, + const uint8_t *input, unsigned size) +{ + static struct AVTWOFISH *twofish; + if (!twofish && !(twofish = av_twofish_alloc())) + fatal_error("out of memory"); + av_twofish_init(twofish, hardcoded_key, 128); + av_twofish_crypt(twofish, output, input, size >> 4, NULL, 0); +} /*************************************************************************** * crypto: OpenSSL's libcrypto ***************************************************************************/ @@ -194,6 +204,12 @@ static void run_crypto_cast128(uint8_t *output, CAST_ecb_encrypt(input + i, output + i, &cast, 1); } +/* no twofish impl in openssl library : dummy function */ +static void run_crypto_twofish(uint8_t *output, + const uint8_t *input, unsigned size) +{ +} + #define IMPL_USE_crypto(...) IMPL_USE(__VA_ARGS__) #else #define IMPL_USE_crypto(...) /* ignore */ @@ -250,6 +266,16 @@ static void run_gcrypt_cast128(uint8_t *output, gcry_cipher_encrypt(cast, output, size, input, size); } +static void run_gcrypt_twofish(uint8_t *output, + const uint8_t *input, unsigned size) +{ + static gcry_cipher_hd_t twofish; + if (!twofish) + gcry_cipher_open(&twofish, GCRY_CIPHER_TWOFISH128, GCRY_CIPHER_MODE_ECB, 0); + gcry_cipher_setkey(twofish, hardcoded_key, 16); + gcry_cipher_encrypt(twofish, output, size, input, size); +} + #define IMPL_USE_gcrypt(...) IMPL_USE(__VA_ARGS__) #else #define IMPL_USE_gcrypt(...) /* ignore */ @@ -314,6 +340,19 @@ static void run_tomcrypt_cast128(uint8_t *output, cast5_ecb_encrypt(input + i, output + i, &cast); } +static void run_tomcrypt_twofish(uint8_t *output, + const uint8_t *input, unsigned size) +{ + symmetric_key twofish; + unsigned i; + + twofish_setup(hardcoded_key, 16, 0, &twofish); + size -= 15; + for (i = 0; i < size; i += 16) + twofish_ecb_encrypt(input + i, output + i, &twofish); +} + + #define IMPL_USE_tomcrypt(...) IMPL_USE(__VA_ARGS__) #else #define IMPL_USE_tomcrypt(...) /* ignore */ @@ -341,6 +380,8 @@ static void run_implementation(const uint8_t *input, uint8_t *output, if (enabled_libs && !av_stristr(enabled_libs, impl->lib) || enabled_algos && !av_stristr(enabled_algos, impl->name)) return; + if (!strcmp(impl->lib, "crypto") && !strcmp(impl->name, "TWOFISH")) /* return as no twofish impl in openssl library */ + return; if (!sscanf(impl->output, "crc:%x", &outcrc)) { outlen = strlen(impl->output) / 2; for (i = 0; i < outlen; i++) { @@ -398,6 +439,7 @@ struct hash_impl implementations[] = { IMPL_ALL("AES-128", aes128, "crc:ff6bc888") IMPL_ALL("CAMELLIA", camellia, "crc:7abb59a7") IMPL_ALL("CAST-128", cast128, "crc:456aa584") + IMPL_ALL("TWOFISH", twofish, "crc:9edbd5c1") }; int main(int argc, char **argv) -- 1.8.3.2
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel