From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6BE70483815 for ; Thu, 13 Aug 2026 13:50:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786629027; cv=none; b=ZqPJjrb5u4FC0gFyT1M8VhEPermlWd70tUClBYIWutE61mycFd02mkHigIaPBX4xRgbsv9ptwtrMQ73MvQEoM3E87mBlsuiKXr4253eJJ5KsErfFdTrE2xIIQfqoic1+Po1ax9Ch63VRb0/L3oDYqV3i9BjD5YOjFJNC3jj39yQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786629027; c=relaxed/simple; bh=zTVu/A2ms08L5lU1yEoQM73ayTlZ9/oZk9DjvB1306I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kHHWmBvFmnK1HFfbaLqAoamYURuWqXMFDS4aRxZ/JRWRVho6asy2V3CDeyVVELpmS9kVG43pcH4DsPpXHGd4KXLxq/uBHXzArMpfJ3SPCXGA8v+m7WoNV6f6gsF/yczrJBDne92n++yBpbAPj+xdAE/5jLZbLrLlWtyUXr+Xnb4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=KfR3WL7G; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="KfR3WL7G" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1786629025; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fjC6RQ33hHDSrNn6DlYe2EQPZM5s0/22UcKy9xjB7gs=; b=KfR3WL7G51m+5q0SnNxLSh3bqPP4gzBcM6Emo2kQHwpA4XUxJ21RpAhAvxTYq7nPXfWsks uYRQZ8hTcumlwNDA0Qi+mEEIVWDXgkx76SAEt7pRTExPCPjBzpyv+Fmfs64OW/PVtT/xIy 6XRxlSK/IJM9hhZe0tXYH5BO9wgz9KA= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-213-q7eoBlF5N9ai4fDiJ00OMg-1; Thu, 13 Aug 2026 09:50:23 -0400 X-MC-Unique: q7eoBlF5N9ai4fDiJ00OMg-1 X-Mimecast-MFC-AGG-ID: q7eoBlF5N9ai4fDiJ00OMg_1786629020 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B8BFD19560AE; Thu, 13 Aug 2026 13:50:20 +0000 (UTC) Received: from thuth-p1g4.redhat.corp (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 45F981800348; Thu, 13 Aug 2026 13:50:18 +0000 (UTC) From: Thomas Huth To: Eric Biggers , "Jason A. Donenfeld" , Ard Biesheuvel , Herbert Xu , "David S. Miller" Cc: x86@kernel.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 06/11] lib/crypto: md5: Provide a function for zeroizing hmac_md5_ctx structures Date: Thu, 13 Aug 2026 15:49:44 +0200 Message-ID: <20260813134953.979481-7-thuth@redhat.com> In-Reply-To: <20260813134953.979481-1-thuth@redhat.com> References: <20260813134953.979481-1-thuth@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 From: Thomas Huth Some crypto code functions need to zeroize their local hmac_md5_ctx structures after use to avoid leaking sensitive material on the stack. Provide a hmac_md5_zeroize_ctx() helper function that can be used with __cleanup() to automatically zeroize the context when it goes out of scope. Signed-off-by: Thomas Huth --- include/crypto/md5.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/include/crypto/md5.h b/include/crypto/md5.h index c47aedfe67ecd..8cf26fd965323 100644 --- a/include/crypto/md5.h +++ b/include/crypto/md5.h @@ -4,6 +4,7 @@ #include #include +#include #define MD5_DIGEST_SIZE 16 #define MD5_HMAC_BLOCK_SIZE 64 @@ -108,6 +109,20 @@ struct hmac_md5_ctx { struct md5_block_state ostate; }; +/** + * hmac_md5_zeroize_ctx() - Zeroize an hmac_md5_ctx structure + * @ctx: The location of the context that should be zeroized + * + * This function explicitly fills the hmac_md5_ctx with zeroes. For + * example, use it with __cleanup() for local hmac_md5_ctx structures + * on the stack, so that their content is not leaked when the context is + * left. Note: This is only required when not using hmac_md5_final(). + */ +static inline void hmac_md5_zeroize_ctx(struct hmac_md5_ctx *ctx) +{ + memzero_explicit(ctx, sizeof(*ctx)); +} + /** * hmac_md5_preparekey() - Prepare a key for HMAC-MD5 * @key: (output) the key structure to initialize -- 2.55.0