From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-183.mta0.migadu.com (out-183.mta0.migadu.com [91.218.175.183]) (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 E49CB3D6CBA for ; Tue, 14 Apr 2026 15:49:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.183 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776181754; cv=none; b=SHdBuVM8I1F3LYRWeSrLVwnlzImVFOsXk7kzKZAJdGx6r+qE2Rni2L3r0QOfGXAibMaLiVKmryq+ZpV8k01zshzP8JZ3J7Yv52a1FsMCBtcYotPKleCKsvYjVX8+/xhLelWygeU6oh7hQD6H4I3mw5CV7Zxr42aKjzwTvsYI+yg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776181754; c=relaxed/simple; bh=V1Fk519hgo3dpZBGJB1Y3JfAX4U+Qfb1seDaiWtoFMw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=JZuGlZ5/TuLfxK8TaBMjpkRYtXwitMD0TAIeyioqRj6r3ViIDS6mp8vFEmPSS13q4iQr/rdSMpSWLZXPI4AKIKf/KB0gkhiXNIRnZdeWSeHk7yuMWqauhycOskv8hVhpZ4YdJHs3dRPR+yP2xaYq3ANJ9MtN8011DQ17mM+8FpE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=sbxicmW6; arc=none smtp.client-ip=91.218.175.183 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="sbxicmW6" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1776181749; 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; bh=STfz/ccXR7C9ENHj5rGcf2fIXq9sUv9WzGnqBbk19js=; b=sbxicmW6jI3cdclr/KpsdmmH6iWO28WXsrq0nTgd1KigvmhyGZclhmt4zD8pU2a5j+X7jV SnPCK95CjJZ4Plo9Gzx0badiqgfL2wbMUXR8iCJJWCVvMd+zo5yFfYPTrQwDVswvMSpRUU scel4B3itKFXbTR2yOci5yqOcjf+nsQ= From: Thorsten Blum To: Herbert Xu , "David S. Miller" Cc: Thorsten Blum , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] crypto: blake2b - use memcpy_and_pad in __blake2b_init Date: Tue, 14 Apr 2026 17:49:03 +0200 Message-ID: <20260414154902.344182-3-thorsten.blum@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=883; i=thorsten.blum@linux.dev; h=from:subject; bh=V1Fk519hgo3dpZBGJB1Y3JfAX4U+Qfb1seDaiWtoFMw=; b=owGbwMvMwCUWt7pQ4caZUj3G02pJDJn3Et+xiX1p12WcFLtos8Bs/2cCZ9JWynX8zz/t8rObd WFhevPsjlIWBjEuBlkxRZYHs37M8C2tqdxkErETZg4rE8gQBi5OAZhIbBYjw6qrW9+vmPnx0Du2 F3635tZM7vk2wzxToIt/72qfnwvrF1xk+Gei+eO+cYDGb+2iR8HPFeo+K4oKfTJIWr3H8tNfPhv vc+wA X-Developer-Key: i=thorsten.blum@linux.dev; a=openpgp; fpr=1D60735E8AEF3BE473B69D84733678FD8DFEEAD4 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT Use memcpy_and_pad() instead of memcpy() followed by memset() to simplify __blake2b_init(). Use sizeof(ctx->buf) instead of the macro BLAKE2B_BLOCK_SIZE. Signed-off-by: Thorsten Blum --- include/crypto/blake2b.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/include/crypto/blake2b.h b/include/crypto/blake2b.h index 3bc37fd103a7..a7a6440bd784 100644 --- a/include/crypto/blake2b.h +++ b/include/crypto/blake2b.h @@ -66,9 +66,8 @@ static inline void __blake2b_init(struct blake2b_ctx *ctx, size_t outlen, ctx->buflen = 0; ctx->outlen = outlen; if (keylen) { - memcpy(ctx->buf, key, keylen); - memset(&ctx->buf[keylen], 0, BLAKE2B_BLOCK_SIZE - keylen); - ctx->buflen = BLAKE2B_BLOCK_SIZE; + memcpy_and_pad(ctx->buf, sizeof(ctx->buf), key, keylen, 0); + ctx->buflen = sizeof(ctx->buf); } }