From patchwork Fri Dec 30 09:36:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Turner X-Patchwork-Id: 1989 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.89.21 with SMTP id n21csp2772666vsb; Fri, 30 Dec 2016 01:43:21 -0800 (PST) X-Received: by 10.28.137.193 with SMTP id l184mr37346909wmd.88.1483091001457; Fri, 30 Dec 2016 01:43:21 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id x11si29915154wmb.59.2016.12.30.01.43.20; Fri, 30 Dec 2016 01:43:21 -0800 (PST) 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=@googlemail.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=QUARANTINE dis=NONE) header.from=googlemail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2BDD8689A4B; Fri, 30 Dec 2016 11:43:14 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf0-f195.google.com (mail-pf0-f195.google.com [209.85.192.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5E2D8680D1D for ; Fri, 30 Dec 2016 11:43:07 +0200 (EET) Received: by mail-pf0-f195.google.com with SMTP id 127so11870496pfg.0 for ; Fri, 30 Dec 2016 01:43:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:subject:date:message-id; bh=/NIMlfOosQtb1irEuWK8q+1NKK75cKXZzSxbYiIm7jI=; b=LFUnJ8QV0n/9pwLGC4xuWqX8edNdksAPbWRs7hd3zD93RqqBdwyNyiyfjxOn+KJKbW tJFJ1e4/6FN+iyE+btB96KytMbJl1GZy7sgQOVWJ5KYwQTn9ng3tStChDnmZ3n8c90Nh E/Cmrg24mRDWXK8ubPNsd9ju5d2z9OHXt/ZuiTPpIOcJLVev4APQYwRa/Jfh55uohj9f lajuFIhjSdBeVtJdHXTAj7m5PgHrV5NX/JyhV15CjOzgYBJMseQvvjGo55MbQuUJ01fR 02kVVVvBmO0Ez33DOssBqQS57JfPnXpUQ5KgC8l2Lw9EL5wP4fBmpMBcX9VJuIONI8B/ 91kQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=/NIMlfOosQtb1irEuWK8q+1NKK75cKXZzSxbYiIm7jI=; b=XZHMmdVyEbfO3b0gITjcSQQY8p5Vqd/WzX4BEqzFY/QW+jPRqNCmC7g+BRY239t7ga Z0+lXnXggX8w35NyYBANCrqEx+P3sK4ZxyXzseHPJX2DKrTwuDVS9+NscSK68cTEGd1e kdcATy21sJTx4scnSp4O60B0UR/LrrkWdjp6G25608MSXQl5YLqK1rIwjmz+wjS6jKoi UXKB/W5TMyFtUFey1MDqG72NLJ8fz/VTQCOaDrEwLpImMiJIfTLDsUTt9iTlX9d2VEfy ZCzrohYnWTHUPyWAa8ZbvTS8fqkmJQu6pQY6ttSelGsO28UOu2z6SCdr/skbNGNX6Zin vO3A== X-Gm-Message-State: AIkVDXIixyOcJ2f//Kw/6lFqkhy5GsD1ovJ8pm22nNZIbJOU1rHNqvtd1UM0G8++GkZm2Q== X-Received: by 10.98.14.82 with SMTP id w79mr42115923pfi.153.1483090605386; Fri, 30 Dec 2016 01:36:45 -0800 (PST) Received: from Zany.fios-router.home ([47.147.141.23]) by smtp.gmail.com with ESMTPSA id s5sm111862496pgj.19.2016.12.30.01.36.44 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 30 Dec 2016 01:36:44 -0800 (PST) From: Thomas Turner To: ffmpeg-devel@ffmpeg.org Date: Fri, 30 Dec 2016 01:36:35 -0800 Message-Id: <1483090595-17207-1-git-send-email-thomastdt@googlemail.com> X-Mailer: git-send-email 1.9.1 Subject: [FFmpeg-devel] [PATCH] avutil/tests: Added selftest for aes_ctr.c 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: Thomas Turner --- libavutil/Makefile | 1 + libavutil/tests/aes_ctr.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++ tests/fate/libavutil.mak | 5 ++++ 3 files changed, 76 insertions(+) create mode 100644 libavutil/tests/aes_ctr.c diff --git a/libavutil/Makefile b/libavutil/Makefile index 2dd91b8..15d95de 100644 --- a/libavutil/Makefile +++ b/libavutil/Makefile @@ -181,6 +181,7 @@ SKIPHEADERS-$(CONFIG_OPENCL) += opencl.h TESTPROGS = adler32 \ aes \ + aes_ctr \ atomic \ audio_fifo \ avstring \ diff --git a/libavutil/tests/aes_ctr.c b/libavutil/tests/aes_ctr.c new file mode 100644 index 0000000..8216b20 --- /dev/null +++ b/libavutil/tests/aes_ctr.c @@ -0,0 +1,70 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * 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 + */ + +#include +#include "libavutil/log.h" +#include "libavutil/mem.h" +#include "libavutil/aes_ctr.h" +#include "libavutil/aes.h" + +const DECLARE_ALIGNED(8, uint8_t, plain)[] = { + 0x6d, 0x6f, 0x73, 0x74, ' ', 0x72, 0x61, 0x6e, 0x64, 0x6f, 0x6d +}; +static DECLARE_ALIGNED(8, uint8_t, tmp)[11]; + +int main (void) +{ + struct AVAESCTR *ae, *ad; + const uint8_t *iv; + + ae = av_aes_ctr_alloc(); + ad = av_aes_ctr_alloc(); + + if (!ae || !ad) + goto ERROR; + + if (av_aes_ctr_init(ae, (const uint8_t*)"0123456789abcdef") < 0) + goto ERROR; + + if (av_aes_ctr_init(ad, (const uint8_t*)"0123456789abcdef") < 0) + goto ERROR; + + av_aes_ctr_set_random_iv(ae); + iv = av_aes_ctr_get_iv(ae); + av_aes_ctr_set_iv(ad, iv); + + av_aes_ctr_crypt(ae, tmp, plain, sizeof(tmp)); + av_aes_ctr_crypt(ad, tmp, tmp, sizeof(tmp)); + + if (memcmp(tmp, plain, sizeof(tmp)) != 0){ + av_log(NULL, AV_LOG_ERROR, "test failed\n"); + goto ERROR; + } + + av_log(NULL, AV_LOG_INFO, "test passed\n"); + #define DEALLOCATE() \ + av_aes_ctr_free(ae); \ + av_aes_ctr_free(ad); + + DEALLOCATE(); + return 0; + +ERROR: + DEALLOCATE(); + return 1; +} \ No newline at end of file diff --git a/tests/fate/libavutil.mak b/tests/fate/libavutil.mak index 5987a83..a7bf739 100644 --- a/tests/fate/libavutil.mak +++ b/tests/fate/libavutil.mak @@ -8,6 +8,11 @@ fate-aes: libavutil/tests/aes$(EXESUF) fate-aes: CMD = run libavutil/tests/aes fate-aes: REF = /dev/null +FATE_LIBAVUTIL += fate-aes_ctr +fate-aes_ctr: libavutil/tests/aes_ctr$(EXESUF) +fate-aes_ctr: CMD = run libavutil/tests/aes_ctr +fate-aes_ctr: REF = /dev/null + FATE_LIBAVUTIL += fate-camellia fate-camellia: libavutil/tests/camellia$(EXESUF) fate-camellia: CMD = run libavutil/tests/camellia