Article View: linux.kernel.netdev
Article #18479[PATCH 6.12/sisyphus 03/29] crypto/krb5: Add an API to query the layout of the crypto section
From: Alexey Shabalin
Date: Wed, 18 Nov 2026 11:44
Date: Wed, 18 Nov 2026 11:44
170 lines
12871 bytes
12871 bytes
From: David Howells <dhowells@redhat.com>
Provide some functions to allow the called to find out about the layout of
the crypto section:
(1) Calculate, for a given size of data, how big a buffer will be
required to hold it and where the data will be within it.
(2) Calculate, for an amount of buffer, what's the maximum size of data
that will fit therein, and where it will start.
(3) Determine where the data will be in a received message.
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Herbert Xu <herbert@gondor.apana.org.au>
cc: "David S. Miller" <davem@davemloft.net>
cc: Chuck Lever <chuck.lever@oracle.com>
cc: Marc Dionne <marc.dionne@auristor.com>
cc: Eric Dumazet <edumazet@google.com>
cc: Jakub Kicinski <kuba@kernel.org>
cc: Paolo Abeni <pabeni@redhat.com>
cc: Simon Horman <horms@kernel.org>
cc: linux-afs@lists.infradead.org
cc: linux-nfs@vger.kernel.org
cc: linux-crypto@vger.kernel.org
cc: netdev@vger.kernel.org
(cherry picked from commit 025ac491f4eeb48c03353719f0de20a6db36b826)
---
crypto/krb5/krb5_api.c | 108 +++++++++++++++++++++++++++++++++++++++++
include/crypto/krb5.h | 9 ++++
2 files changed, 117 insertions(+)
diff --git a/crypto/krb5/krb5_api.c b/crypto/krb5/krb5_api.c
index 5c1cd5d07fc3..f6d1bc813daa 100644
--- a/crypto/krb5/krb5_api.c
+++ b/crypto/krb5/krb5_api.c
@@ -40,3 +40,111 @@ const struct krb5_enctype *crypto_krb5_find_enctype(u32 enctype)
return NULL;
}
EXPORT_SYMBOL(crypto_krb5_find_enctype);
+
+/**
+ * crypto_krb5_how_much_buffer - Work out how much buffer is required for an amount of data
+ * @krb5: The encoding to use.
+ * @mode: The mode in which to operated (checksum/encrypt)
+ * @data_size: How much data we want to allow for
+ * @_offset: Where to place the offset into the buffer
+ *
+ * Calculate how much buffer space is required to wrap a given amount of data.
+ * This allows for a confounder, padding and checksum as appropriate. The
+ * amount of buffer required is returned and the offset into the buffer at
+ * which the data will start is placed in *_offset.
+ */
+size_t crypto_krb5_how_much_buffer(const struct krb5_enctype *krb5,
+ enum krb5_crypto_mode mode,
+ size_t data_size, size_t *_offset)
+{
+ switch (mode) {
+ case KRB5_CHECKSUM_MODE:
+ *_offset = krb5->cksum_len;
+ return krb5->cksum_len + data_size;
+
+ case KRB5_ENCRYPT_MODE:
+ *_offset = krb5->conf_len;
+ return krb5->conf_len + data_size + krb5->cksum_len;
+
+ default:
+ WARN_ON(1);
+ *_offset = 0;
+ return 0;
+ }
+}
+EXPORT_SYMBOL(crypto_krb5_how_much_buffer);
+
+/**
+ * crypto_krb5_how_much_data - Work out how much data can fit in an amount of buffer
+ * @krb5: The encoding to use.
+ * @mode: The mode in which to operated (checksum/encrypt)
+ * @_buffer_size: How much buffer we want to allow for (may be reduced)
+ * @_offset: Where to place the offset into the buffer
+ *
+ * Calculate how much data can be fitted into given amount of buffer. This
+ * allows for a confounder, padding and checksum as appropriate. The amount of
+ * data that will fit is returned, the amount of buffer required is shrunk to
+ * allow for alignment and the offset into the buffer at which the data will
+ * start is placed in *_offset.
+ */
+size_t crypto_krb5_how_much_data(const struct krb5_enctype *krb5,
+ enum krb5_crypto_mode mode,
+ size_t *_buffer_size, size_t *_offset)
+{
+ size_t buffer_size = *_buffer_size, data_size;
+
+ switch (mode) {
+ case KRB5_CHECKSUM_MODE:
+ if (WARN_ON(buffer_size < krb5->cksum_len + 1))
+ goto bad;
+ *_offset = krb5->cksum_len;
+ return buffer_size - krb5->cksum_len;
+
+ case KRB5_ENCRYPT_MODE:
+ if (WARN_ON(buffer_size < krb5->conf_len + 1 + krb5->cksum_len))
+ goto bad;
+ data_size = buffer_size - krb5->cksum_len;
+ *_offset = krb5->conf_len;
+ return data_size - krb5->conf_len;
+
+ default:
+ WARN_ON(1);
+ goto bad;
+ }
+
+bad:
+ *_offset = 0;
+ return 0;
+}
+EXPORT_SYMBOL(crypto_krb5_how_much_data);
+
+/**
+ * crypto_krb5_where_is_the_data - Find the data in a decrypted message
+ * @krb5: The encoding to use.
+ * @mode: Mode of operation
+ * @_offset: Offset of the secure blob in the buffer; updated to data offset.
+ * @_len: The length of the secure blob; updated to data length.
+ *
+ * Find the offset and size of the data in a secure message so that this
+ * information can be used in the metadata buffer which will get added to the
+ * digest by crypto_krb5_verify_mic().
+ */
+void crypto_krb5_where_is_the_data(const struct krb5_enctype *krb5,
+ enum krb5_crypto_mode mode,
+ size_t *_offset, size_t *_len)
+{
+ switch (mode) {
+ case KRB5_CHECKSUM_MODE:
+ *_offset += krb5->cksum_len;
+ *_len -= krb5->cksum_len;
+ return;
+ case KRB5_ENCRYPT_MODE:
+ *_offset += krb5->conf_len;
+ *_len -= krb5->conf_len + krb5->cksum_len;
+ return;
+ default:
+ WARN_ON_ONCE(1);
+ return;
+ }
+}
+EXPORT_SYMBOL(crypto_krb5_where_is_the_data);
diff --git a/include/crypto/krb5.h b/include/crypto/krb5.h
index 8fa6715ab35b..b414141b8b42 100644
--- a/include/crypto/krb5.h
+++ b/include/crypto/krb5.h
@@ -101,5 +101,14 @@ struct krb5_enctype {
* krb5_api.c
*/
const struct krb5_enctype *crypto_krb5_find_enctype(u32 enctype);
+size_t crypto_krb5_how_much_buffer(const struct krb5_enctype *krb5,
+ enum krb5_crypto_mode mode,
+ size_t data_size, size_t *_offset);
+size_t crypto_krb5_how_much_data(const struct krb5_enctype *krb5,
+ enum krb5_crypto_mode mode,
+ size_t *_buffer_size, size_t *_offset);
+void crypto_krb5_where_is_the_data(const struct krb5_enctype *krb5,
+ enum krb5_crypto_mode mode,
+ size_t *_offset, size_t *_len);
#endif /* _CRYPTO_KRB5_H */
--
2.50.1
Technical Details
Message-ID:
<20261118114518.3605222-4-shaba@altlinux.org>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-366087-linux-kernel-netdev=dewy.ruReferences:
<20261118114518.3605222-1-shaba@altlinux.org>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-366087-linux-kernel-netdev=dewy.ru From: shaba@altlinux.org (Alexey Shabalin) Newsgroups: linux.kernel.netdev Subject: [PATCH 6.12/sisyphus 03/29] crypto/krb5: Add an API to query the layout of the crypto section Date: Wed, 18 Nov 2026 14:44:52 +0300 Organization: Usenet Network Message-ID: <20261118114518.3605222-4-shaba@altlinux.org> References: <20261118114518.3605222-1-shaba@altlinux.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="2583428"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:aY0a1Gkwun3Xtfo3lyT3g0Cu+Xo= sha256:7oOlDAnKIO7DxUROLipzLix/SRON5jvh/kfuWDnRK3Y= sha1:4U0pOiNQ9WEV6GyJ9CMzksOhBUs= sha256:GfkyyqN0uaNTUsal7oy4/qdyr8sNx50PfTVwC3vbCS4= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 89F38115277; Wed, 18 Nov 2026 14:45:51 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -2.951 X-Spam-Status: No, score=-2.951 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 5IhQ2UW95M-E; Wed, 18 Nov 2026 14:45:47 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-366087-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=none (p=none dis=none) header.from=altlinux.org X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id 4F27211526D; Wed, 18 Nov 2026 14:45:41 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id 96FB0358FA; Wed, 18 Nov 2026 11:45:35 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795002328; b=T9yTRMV/7hmkQfw3WTBjGlXd2gMJQDGuG1KJ9keYh+/HxsQX/GJQYDnU6UGiO12/46Oz QyQc0lR25g9cvk3X7ti8m1Zp/wlMUVxTrRMC01cooEl84I7Z7z2GkaJ9goScPHrSs8sO+ ESh4W0XXARDjnkkvf2lRf8B+ZE3EAB02D4d+va9iopFpsfZauTcSFtb+xPQEWPuplEloj xHfAtqvncbNrO5uoR5ZONmmCpMQ9X5Nex+WVCBQJlvIVsa9gyD1E4MwiQPI+T5uIHuRsE h+VWu/dkFkKsgAoniWo5kwQ3poHvyXH91QzuDDbzGc6ZIQO27bUyJl2qiFgBG3Yo6EQ== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795002328; h=X-Original-To:Received:DMARC-Filter:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:In-Reply-To:References:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version:Content-Transfer-Encoding; bh=TNr17IsDH3CMJAsBddlI8ulC9BfuyexkixP3yKX5G7k=; b=MFiWyMlNYED0xKuNC1mq+l2x0dEx2QevHD9a22bN8feH3na9m3nG+5EXCe7R6lz5ResN wHyolQ5y6y0gmcp4wXN2ZT8GFLmOquHcDLjUL0pflr+OZ1dDC43u+bknjs+PPp5W3rcTf SybdERlIm6zDkaDIMW53nnqaW91eTlV0SI+lV4g5pBwM75rCUoNS6ox9OKWTUP3eBtC7t 2BxxK9JPar583VrTqSoyJxm96k3MW/a62cKCL3IMUya5vebxbt58HP14DRRzENk0fkFqJ beD0rli/dt7DL2HPfS/NMakb1bSQrg+XMODfEy0DYtA2pPzryjpn++5RRbr3Wx0IBeA== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=none header.from=altlinux.org; spf=fail smtp.mailfrom=altlinux.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BEF7160A2622; Wed, 18 Nov 2026 11:45:28 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=193.43.10.250 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795002328; b=sbybTf6RmTJPTyOyPHdmb0Pp34i5G+wVGrGSdKTNoqtZiJoytMolZHcpqpuc8OoWxl0m yoo8yidgM/HqfD8oNGp2BO9jl6eHOa99STjGvPepL95Udlfl2DsLyzdopSMGI4Hj+EOFk AhA17noLUXWryPKGj+f4beyWlRIkyBXDdJOInx30WhbtM7D+pgjvqCH14AilTcbMi3YRY 4u3LYcUmrK0/UPrtShgM38QiTaofDHSVIL/N9rsfu+XgqgB6z38JL7u6jrQSrCo6n1kWZ T8Uz9t7hXEMJOYB0Ae8QwiGNH9/MwT34IAP75o/d573Oxe2zxcZGklP2+6hQfX/+6gw== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795002328; h=DMARC-Filter:Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=TNr17IsDH3CMJAsBddlI8ulC9BfuyexkixP3yKX5G7k=; b=RmWl3FpW+1kNAE1jxET9Q8xJXThaZRtxcWGkoHze9bdo+DZR7rqPHxSqb8WeftrS+WrE zjl7weVO/UT+X0e0+TzA06IFW5eI9ojlfpxh6uJ97w00of4/RV5b2o2nBAr4C3dofZSVv XHTpXKjljyCt44OGOejxUYac5EBf2JuID1zNrAZTN2pXKV6TdZKA6QMppD/tpa0ptm9Jp BezR/ez6f6HR+87Gj4X+OYaImRAc/yQ/uaAvrJcrZjHwMScwN+r2iI0xfQqsb1l+DYfv0 NyZEpJ6A55UKLns7+wlQ/XprB/Jo1onF+FUW0QemBijfTa3ZRO9s1+kI5GtJ87sJUCQ== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=altlinux.org; spf=fail smtp.mailfrom=altlinux.org; arc=none smtp.remote-ip=193.43.10.250 X-Received: from basalt.external.altlinux.org (unknown [193.43.10.250]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 83985606A32C; Wed, 18 Nov 2026 11:45:26 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 83985606A32C X-Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=altlinux.org X-Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=altlinux.org X-Received: by basalt.external.altlinux.org (Postfix, from userid 1137) id D76372DF335; Wed, 18 Nov 2026 14:45:18 +0300 (MSK) X-Cc: David Howells <dhowells@redhat.com>, Herbert Xu <herbert@gondor.apana.org.au>, "David S. Miller" <davem@davemloft.net>, Chuck Lever <chuck.lever@oracle.com>, Marc Dionne <marc.dionne@auristor.com>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>, linux-afs@lists.infradead.org, linux-nfs@vger.kernel.org, linux-crypto@vger.kernel.org, netdev@vger.kernel.org X-Mailer: git-send-email 2.50.1 X-In-Reply-To: <20261118114518.3605222-1-shaba@altlinux.org> X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list