From patchwork Sun Sep 22 16:36:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Tomas_H=C3=A4rdin?= X-Patchwork-Id: 51697 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:d154:0:b0:48e:c0f8:d0de with SMTP id bt20csp2043417vqb; Sun, 22 Sep 2024 09:44:18 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCW9Ic+evh5/0X2KbqCpPvmKyTwSc3gbCIhONUM3qT15gZtKiI5KklwHCr2cL9rP9ZCZgHKRbSLqtRN1Pa7KnG5p@gmail.com X-Google-Smtp-Source: AGHT+IGFmwr2aRv8o5JwCi4wuEmewBUwrxcPs/059Md7qeSIXvC7NjAXJxo+Nk2QNpEmyNH551mq X-Received: by 2002:a17:907:d16:b0:a8d:7b7d:8c47 with SMTP id a640c23a62f3a-a90d5197004mr1026270366b.59.1727023458108; Sun, 22 Sep 2024 09:44:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1727023458; cv=none; d=google.com; s=arc-20240605; b=NmqhXzEiKftJNiX0nik9FwWKOf7aiwbBBuCi5i52pDRrzBvBpinvuJFvytvnUH0IWB 7AuXcdmYfaG4wzx5d85r1TK8YbzkI+mHcdG+NqyZSUqlQqtdidSoI2AW7XwFlPkDJltw q45c/a9PdjISO9ywE/UGnY6mD7RVB4KXRnVRA30Z2tp3Vsz6+sBkthJK3FSYlS8tQ7Yw s+rIiwEdxHCDi74WgpN0tFZT757CRhm8PH04htdi3E34lVWneaJ+BlgTTigQe1iRbj/U eueacZOXG1B00OHDnP7bftrps/afj9Q5fmkW8713bQCLGiukuEkKKoVBrmkMfKA8SfyO j9OQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:user-agent:references:in-reply-to:date:to:from :message-id:delivered-to; bh=pjk8LzQsVmK7kf6oa23gA9/2gFkF2BSdQjdi4PMXBD8=; fh=e5zN9xSzcxLA6bGo3lF+CqTbY/oLwzApV03EO/RBfgQ=; b=Gxo7sZ2jj5aJG0OU+SrA4fSwp+CmzQZ2SCBbqwZ2kVsYhgbxVBCKcrPu8myxSPFLd9 IxPmUhZoNa4K1LlBDCZivGrL8W8c1IpkDk8CFhugqi50DMkdcjRvgXYpCwnQsUcHV5IO magivXQmIsXIhvc9S09FQ+q2CDYlsAqltnbrnViarLiMDHqQc4RwnZ96c4AXkcRTDw4a IZLcjlfOunvVsP4MTYgnRFdC9xVAehKNapzvpTSjI9VcNafwmuSbe2IeM2G0GcFLr9Nq f6Nfdo9JLYuvI3/AMEujTSbwALhD3iCUwVShbl1Tui1F9Fe+ypEZDOAQpcs4dobBDoLB ZUpg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id a640c23a62f3a-a906109ab76si1256303466b.207.2024.09.22.09.44.17; Sun, 22 Sep 2024 09:44:18 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 66C8B68DAE2; Sun, 22 Sep 2024 19:36:50 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from glom.nmugroup.com (glom.nmugroup.com [193.183.80.6]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 20AA368CEEA for ; Sun, 22 Sep 2024 19:36:44 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by glom.nmugroup.com (Postfix) with ESMTP id AEFB15423920 for ; Sun, 22 Sep 2024 18:36:43 +0200 (CEST) Received: from debian.lan (unknown [IPv6:2a00:66c0:a::72c]) (Authenticated sender: git01) by glom.nmugroup.com (Postfix) with ESMTPSA id 78E4B5422937 for ; Sun, 22 Sep 2024 18:36:43 +0200 (CEST) Message-ID: From: Tomas =?iso-8859-1?q?H=E4rdin?= To: FFmpeg development discussions and patches Date: Sun, 22 Sep 2024 18:36:42 +0200 In-Reply-To: <1de0719456ef2f015b83d214d73334853af26612.camel@haerdin.se> References: <1de0719456ef2f015b83d214d73334853af26612.camel@haerdin.se> User-Agent: Evolution 3.46.4-2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/5] lavf/mxfdec: Add and use mxf_is_encrypted_triplet_key() X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: dHiSGrc9ERVh mxf_match_uid() is rather slow and gets called a lot. Unrolling it like this saves some cycles, but probably not enough to justify making the code much more verbose /Tomas From ed92d030212e230c7a12d2b265feb470ffd5caa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= Date: Sat, 14 Sep 2024 11:19:41 +0200 Subject: [PATCH 3/5] lavf/mxfdec: Add and use mxf_is_encrypted_triplet_key() --- libavformat/mxfdec.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c index 5fe6918353..4823aae135 100644 --- a/libavformat/mxfdec.c +++ b/libavformat/mxfdec.c @@ -1584,6 +1584,25 @@ static int mxf_match_uid(const UID key, const uint8_t uid_prefix[], int len) return 1; } +/* + * Checks if key is mxf_is_encrypted_triplet_key, while also knowing that key[0..3] == mxf_klv_key + * Returns: boolean + */ +static int mxf_is_encrypted_triplet_key(const UID key) +{ + return key[4 ] == mxf_encrypted_triplet_key[4 ] && + key[5 ] == mxf_encrypted_triplet_key[5 ] && + key[6 ] == mxf_encrypted_triplet_key[6 ] && + key[8 ] == mxf_encrypted_triplet_key[8 ] && + key[9 ] == mxf_encrypted_triplet_key[9 ] && + key[10] == mxf_encrypted_triplet_key[10] && + key[11] == mxf_encrypted_triplet_key[11] && + key[12] == mxf_encrypted_triplet_key[12] && + key[13] == mxf_encrypted_triplet_key[13] && + key[14] == mxf_encrypted_triplet_key[14] && + key[15] == mxf_encrypted_triplet_key[15]; +} + static const MXFCodecUL *mxf_get_codec_ul(const MXFCodecUL *uls, UID *uid) { while (uls->uid[0]) { @@ -3754,7 +3773,7 @@ static int mxf_read_header(AVFormatContext *s) PRINT_KEY(s, "read header", klv.key); av_log(s, AV_LOG_TRACE, "size %"PRIu64" offset %#"PRIx64"\n", klv.length, klv.offset); - if (mxf_match_uid(klv.key, mxf_encrypted_triplet_key, sizeof(mxf_encrypted_triplet_key)) || + if (mxf_is_encrypted_triplet_key(klv.key) || IS_KLV_KEY_FAST(klv.key, mxf_essence_element_key) || IS_KLV_KEY_FAST(klv.key, mxf_canopus_essence_element_key) || IS_KLV_KEY_FAST(klv.key, mxf_avid_essence_element_key) || @@ -4005,7 +4024,7 @@ static int mxf_read_packet(AVFormatContext *s, AVPacket *pkt) pos = klv.next_klv - klv.length; PRINT_KEY(s, "read packet", klv.key); av_log(s, AV_LOG_TRACE, "size %"PRIu64" offset %#"PRIx64"\n", klv.length, klv.offset); - if (mxf_match_uid(klv.key, mxf_encrypted_triplet_key, sizeof(mxf_encrypted_triplet_key))) { + if (mxf_is_encrypted_triplet_key(klv.key)) { ret = mxf_decrypt_triplet(s, pkt, &klv); if (ret < 0) { av_log(s, AV_LOG_ERROR, "invalid encoded triplet\n"); -- 2.39.2