From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <ffmpeg-devel-bounces@ffmpeg.org>
Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100])
	by master.gitmailbox.com (Postfix) with ESMTPS id 3E6934BCD7
	for <ffmpegdev@gitmailbox.com>; Thu,  3 Apr 2025 20:59:32 +0000 (UTC)
Received: from [127.0.1.1] (localhost [127.0.0.1])
	by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 662C568B122;
	Thu,  3 Apr 2025 23:59:28 +0300 (EEST)
Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com
 [209.85.210.172])
 by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1F810687DBD
 for <ffmpeg-devel@ffmpeg.org>; Thu,  3 Apr 2025 23:59:22 +0300 (EEST)
Received: by mail-pf1-f172.google.com with SMTP id
 d2e1a72fcca58-736bfa487c3so1173850b3a.1
 for <ffmpeg-devel@ffmpeg.org>; Thu, 03 Apr 2025 13:59:21 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1743713959; x=1744318759; darn=ffmpeg.org;
 h=content-transfer-encoding:mime-version:references:in-reply-to
 :message-id:date:subject:to:from:from:to:cc:subject:date:message-id
 :reply-to; bh=dtZDyFqqH3rxoNrqLtNxRPS1CGdgVJizRrv8Pt4TSWQ=;
 b=Te/903FY0G4/asoglCRwWmgzxFCX52BUVX2p9pDwLEQtGEd4SsY5mRE9us4/0SNZV/
 aYTb5SRmTIDThWS01xHE6wfYc04XMshen+aNvAvoeNSYz/SUCpShBY80HczQmVEHf618
 Q5/G4tu7IW94LyNZn0ytmFMW+ZENOEPy+MEryVeC3AmpHDziPwoFo+oA9BlbSaN7seBh
 P3yCk08MgTzTYUAmbLuExJxHUJYV4ps5/ZX2dIMG6RXPsp7/y/ZKq+23uHJccIsQYhbL
 T3dUrLmfgTBLSKQ7ih6SxZM6XGAB7q27dEeNLgo4lZtMXEBZW+Alfn2OsmkmPvgjn4B4
 UUQQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1743713959; x=1744318759;
 h=content-transfer-encoding:mime-version:references:in-reply-to
 :message-id:date:subject:to:from:x-gm-message-state:from:to:cc
 :subject:date:message-id:reply-to;
 bh=dtZDyFqqH3rxoNrqLtNxRPS1CGdgVJizRrv8Pt4TSWQ=;
 b=l/nV8QIFobu7wzhvfLVSnQO6t/x1T9qg3cKiWFv5NPwqVhJWxPuMMCNBYxDFDci8lN
 zsGUw2cr6eJXkdS4zP1Q4XkmHgpR9Dm0qyYcKoR9mJj2HHymkHcDz+bjRpkPUrhE7nru
 9lor9saTNEPmT4iBBEjXV6p7EErk8pA3y6TTE/z2oJ6NkqPUBN8unmIFvJNF7asqFrBc
 +RdkktogX0+WwmSJ+7bErbrcSHD+vrQC+Tt5Knmj2BWxS9uusbc2y8JTM3vPd+msFAwU
 ycnRXx/PT7mS/4AS4OCLuVk7sY5ZM03zgrfrtGvSAZDa9RSm1WHSYvF4I+f8a56A9IPT
 wphg==
X-Gm-Message-State: AOJu0YxajaXr1Okzpbe+OG58h/jzz3ruu3EZqMFeOdB7cSazSwIr7f1M
 P5SdXAT1gWcT79oxvwkJlI5a0IwBhz0jf2LhwSNsazGP5pT3Ow17EGDa1A==
X-Gm-Gg: ASbGncve6TciPKaRv4KF5XEw0zfw2p2xEpPeo5b+udM1myskelgfm+It5Vibw+FGSNj
 5EI8H1MdjK1AR/wxQF7uEs+98OQGMMEprlQWTwyxPJG8t6elfNDUkTxMD1YZM2y7mZ5cYq+lekN
 CnLlfza8XRgiKdSZIwhx+Ovo1Xp1D9mlbosWfgg8WxguRrVon0ZiPcWBjMSJWEt6AvWVuv3Vcfa
 KTo+wHRxYI0OJq7zG5dZGPtbnvukZhUt0FFl1LBixNa5zQ0lKgzR8C3pG8/PdVcIpJxgXiODBOL
 grm6B5iXK9iT+vBmp0tBsbmhcWJm9r1RUWSmwLkF4ER7yp4msUKxbNo6MZ5/NRjo
X-Google-Smtp-Source: AGHT+IF0bQmUhzJK90kYvZX8lSUzKVaYifzCfMrLLy5hy1OH1u1IDjNs8zqjVHRRkDhs6/Dg7sxPDA==
X-Received: by 2002:a05:6a20:9e49:b0:1f5:63f9:9ea1 with SMTP id
 adf61e73a8af0-2010461cfdamr1336824637.13.1743713958958; 
 Thu, 03 Apr 2025 13:59:18 -0700 (PDT)
Received: from localhost.localdomain ([2800:2121:b000:82e:8402:2797:4dd9:1af3])
 by smtp.gmail.com with ESMTPSA id
 41be03b00d2f7-af9cc090c72sm32611a12.50.2025.04.03.13.59.17
 for <ffmpeg-devel@ffmpeg.org>
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Thu, 03 Apr 2025 13:59:18 -0700 (PDT)
From: James Almer <jamrial@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Date: Thu,  3 Apr 2025 17:59:01 -0300
Message-ID: <20250403205903.1390-1-jamrial@gmail.com>
X-Mailer: git-send-email 2.49.0
In-Reply-To: <20250401151637.2021-1-jamrial@gmail.com>
References: <20250401151637.2021-1-jamrial@gmail.com>
MIME-Version: 1.0
Subject: [FFmpeg-devel] [PATCH 4/6] avutil/test/aes_ctr: also check the
 encrypted buffer
X-BeenThere: ffmpeg-devel@ffmpeg.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: FFmpeg development discussions and patches <ffmpeg-devel.ffmpeg.org>
List-Unsubscribe: <https://ffmpeg.org/mailman/options/ffmpeg-devel>,
 <mailto:ffmpeg-devel-request@ffmpeg.org?subject=unsubscribe>
List-Archive: <https://ffmpeg.org/pipermail/ffmpeg-devel>
List-Post: <mailto:ffmpeg-devel@ffmpeg.org>
List-Help: <mailto:ffmpeg-devel-request@ffmpeg.org?subject=help>
List-Subscribe: <https://ffmpeg.org/mailman/listinfo/ffmpeg-devel>,
 <mailto:ffmpeg-devel-request@ffmpeg.org?subject=subscribe>
Reply-To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: ffmpeg-devel-bounces@ffmpeg.org
Sender: "ffmpeg-devel" <ffmpeg-devel-bounces@ffmpeg.org>
Archived-At: <https://master.gitmailbox.com/ffmpegdev/20250403205903.1390-1-jamrial@gmail.com/>
List-Archive: <https://master.gitmailbox.com/ffmpegdev/>
List-Post: <mailto:ffmpegdev@gitmailbox.com>

The test in its current form is just ensuring the plain text output is the same
as the plain text input, not bothering to check if anything was done with the
latter. av_aes_ctr_crypt() could be a simple memcpy under the hood and this
test would still succeed.

To check the integrity of the encrypted buffer, both the IV and the key need to
be fixed. As such, and in order to not remove the existing randomization of the
input IV, do two runs, one with random initialization data, and one with static
data.

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavutil/tests/aes_ctr.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/libavutil/tests/aes_ctr.c b/libavutil/tests/aes_ctr.c
index 65b49ee7fe..94b0201c7b 100644
--- a/libavutil/tests/aes_ctr.c
+++ b/libavutil/tests/aes_ctr.c
@@ -26,6 +26,16 @@ static const DECLARE_ALIGNED(8, uint8_t, plain)[] = {
     0x6d, 0x6f, 0x73, 0x74, 0x20, 0x72, 0x61, 0x6e, 0x64, 0x6f,
     0x6d, 0x6f, 0x73, 0x74, 0x20, 0x72, 0x61, 0x6e, 0x64, 0x6f
 };
+
+static const DECLARE_ALIGNED(8, uint8_t, encrypted)[] = {
+    0x95, 0xcd, 0x9a, 0x8a, 0x83, 0xa2, 0x1a, 0x84, 0x92, 0xed,
+    0xd6, 0xf2, 0x57, 0x2f, 0x61, 0x98, 0xbc, 0x20, 0x98, 0xee
+};
+
+static const DECLARE_ALIGNED(8, uint8_t, fixed_iv)[] = {
+    0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef
+};
+
 static DECLARE_ALIGNED(8, uint8_t, tmp)[20];
 
 int main (void)
@@ -34,6 +44,7 @@ int main (void)
     struct AVAESCTR *ae, *ad;
     const uint8_t *iv;
 
+    for (int i = 0; i < 2; i++) {
     ae = av_aes_ctr_alloc();
     ad = av_aes_ctr_alloc();
 
@@ -46,11 +57,18 @@ int main (void)
     if (av_aes_ctr_init(ad, (const uint8_t*)"0123456789abcdef") < 0)
         goto ERROR;
 
+        if (i)
+            av_aes_ctr_set_iv(ae, fixed_iv);
+        else
     av_aes_ctr_set_random_iv(ae);
     iv =   av_aes_ctr_get_iv(ae);
     av_aes_ctr_set_full_iv(ad, iv);
 
     av_aes_ctr_crypt(ae, tmp, plain, sizeof(tmp));
+        if (i && memcmp(tmp, encrypted, sizeof(tmp)) != 0) {
+            av_log(NULL, AV_LOG_ERROR, "test failed\n");
+            goto ERROR;
+        }
     av_aes_ctr_crypt(ad, tmp, tmp,   sizeof(tmp));
 
     if (memcmp(tmp, plain, sizeof(tmp)) != 0){
@@ -58,6 +76,11 @@ int main (void)
         goto ERROR;
     }
 
+        av_aes_ctr_free(ae);
+        av_aes_ctr_free(ad);
+        ae = ad = NULL;
+    }
+
     av_log(NULL, AV_LOG_INFO, "test passed\n");
     ret = 0;
 
-- 
2.49.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".