From patchwork Fri Aug 26 02:54:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 301 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.134 with SMTP id o128csp120400vsd; Thu, 25 Aug 2016 19:55:57 -0700 (PDT) X-Received: by 10.194.149.176 with SMTP id ub16mr876692wjb.54.1472180157330; Thu, 25 Aug 2016 19:55:57 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id vi10si16728552wjb.278.2016.08.25.19.55.56; Thu, 25 Aug 2016 19:55:57 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 537046898F4; Fri, 26 Aug 2016 05:55:43 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-oi0-f65.google.com (mail-oi0-f65.google.com [209.85.218.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DA1B96898F4 for ; Fri, 26 Aug 2016 05:55:28 +0300 (EEST) Received: by mail-oi0-f65.google.com with SMTP id s207so5970037oie.0 for ; Thu, 25 Aug 2016 19:55:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id; bh=t3aFIkF1M8pw021/OofMRUs+97gr47uIPCF3X5wkXcA=; b=XU5x4CCJqdqLRwx1qjrOTVsgsRmRMkY4EVXhXhRH5W/EJRhgroFBc1Ul9sZR6N4IV5 k9am3heltdQnHr0JCFddp4C5jOIv5pWkJ1K/MRbuKYcuzFK8m8nen8GOCzapQRT98Whf GhtM4rlqu7rzAfaF5bskqoZYvqrBwYXDhaUs7mZiqg6OkPIPpd6r6QfXinAjDOAi31tI wliGEwgm7wxEXPwcKLVbAZ3wWbTt3HE9vS6Yo+bGD5eZCg2VHECdjtd+RsEVC+ABGisy bYkvULrHO3FxHCBo4fNyTa2hcj+D3gvOk9I/nkkMBCJb/QdI42ttR0d57LJ7jafPe/QR 0SiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id; bh=t3aFIkF1M8pw021/OofMRUs+97gr47uIPCF3X5wkXcA=; b=f8PZ13DgQpAlaLqkacPQ3Z+DVCjS9OsdDQvhVAQB5blhPyI6qoAho68M6u+r1CzuQp qRwZeNxzRlMVaATzB3R6+Erz6hzSvFRrfK8y3pPDihT0a6Bnp/BZHJoi15OG78f6yyeQ kPGvWE/bhE60ah96mR/lvyaOaCZMuqX1W0LVJE15/EFCTEu6CoOqBt32HUQmS8z2ae1q 2EJChiIuSOiq5RF8l+27M7vcpWvplgJFPDDiMk/Yv++JPBxcX9PmWFR4qX1Q8ac1KrVD IAHZQMptslEBhXWeRLVB6UrW4GBD+Smh79ci62NdnLEajvVPAfIJ/tvgAdAYB6Rmbllm hU+w== X-Gm-Message-State: AE9vXwMx17q3miqDIikqHx/2OjdzAB38r8Mnyl2gp5aoF8iJRBI+Pm+IL8d05xgPbx6yAw== X-Received: by 10.202.214.141 with SMTP id n135mr522188oig.152.1472180130319; Thu, 25 Aug 2016 19:55:30 -0700 (PDT) Received: from localhost.localdomain ([181.22.0.212]) by smtp.gmail.com with ESMTPSA id a5sm4210371oii.3.2016.08.25.19.55.28 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 25 Aug 2016 19:55:29 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Thu, 25 Aug 2016 23:54:48 -0300 Message-Id: <20160826025449.5916-1-jamrial@gmail.com> X-Mailer: git-send-email 2.9.1 Subject: [FFmpeg-devel] [PATCH 1/2] tools/crypto_bench: simply gcrypt functions using a macro X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: James Almer --- tools/crypto_bench.c | 65 +++++++++++++--------------------------------------- 1 file changed, 16 insertions(+), 49 deletions(-) diff --git a/tools/crypto_bench.c b/tools/crypto_bench.c index b3b24a6..2535228 100644 --- a/tools/crypto_bench.c +++ b/tools/crypto_bench.c @@ -287,55 +287,22 @@ DEFINE_GCRYPT_WRAPPER(sha256, SHA256) DEFINE_GCRYPT_WRAPPER(sha512, SHA512) DEFINE_GCRYPT_WRAPPER(ripemd160, RMD160) -static void run_gcrypt_aes128(uint8_t *output, - const uint8_t *input, unsigned size) -{ - static gcry_cipher_hd_t aes; - if (!aes) - gcry_cipher_open(&aes, GCRY_CIPHER_AES128, GCRY_CIPHER_MODE_ECB, 0); - gcry_cipher_setkey(aes, hardcoded_key, 16); - gcry_cipher_encrypt(aes, output, size, input, size); -} - -static void run_gcrypt_blowfish(uint8_t *output, - const uint8_t *input, unsigned size) -{ - static gcry_cipher_hd_t blowfish; - if (!blowfish) - gcry_cipher_open(&blowfish, GCRY_CIPHER_BLOWFISH, GCRY_CIPHER_MODE_ECB, 0); - gcry_cipher_setkey(blowfish, hardcoded_key, 16); - gcry_cipher_encrypt(blowfish, output, size, input, size); -} - -static void run_gcrypt_camellia(uint8_t *output, - const uint8_t *input, unsigned size) -{ - static gcry_cipher_hd_t camellia; - if (!camellia) - gcry_cipher_open(&camellia, GCRY_CIPHER_CAMELLIA128, GCRY_CIPHER_MODE_ECB, 0); - gcry_cipher_setkey(camellia, hardcoded_key, 16); - gcry_cipher_encrypt(camellia, output, size, input, size); -} - -static void run_gcrypt_cast128(uint8_t *output, - const uint8_t *input, unsigned size) -{ - static gcry_cipher_hd_t cast; - if (!cast) - gcry_cipher_open(&cast, GCRY_CIPHER_CAST5, GCRY_CIPHER_MODE_ECB, 0); - gcry_cipher_setkey(cast, hardcoded_key, 16); - 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 DEFINE_GCRYPT_CYPHER_WRAPPER(suffix, cypher, sz) \ +static void run_gcrypt_ ## suffix(uint8_t *output, \ + const uint8_t *input, unsigned size) \ +{ \ + static gcry_cipher_hd_t suffix; \ + if (!suffix) \ + gcry_cipher_open(&suffix, GCRY_CIPHER_ ## cypher, GCRY_CIPHER_MODE_ECB, 0); \ + gcry_cipher_setkey(suffix, hardcoded_key, sz); \ + gcry_cipher_encrypt(suffix, output, size, input, size); \ +} + +DEFINE_GCRYPT_CYPHER_WRAPPER(aes128, AES128, 16) +DEFINE_GCRYPT_CYPHER_WRAPPER(blowfish, BLOWFISH, 16) +DEFINE_GCRYPT_CYPHER_WRAPPER(camellia, CAMELLIA128, 16) +DEFINE_GCRYPT_CYPHER_WRAPPER(cast128, CAST5, 16) +DEFINE_GCRYPT_CYPHER_WRAPPER(twofish, TWOFISH128, 16) #define IMPL_USE_gcrypt(...) IMPL_USE(__VA_ARGS__) #else