From nobody Wed Aug 24 05:11:24 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4MCDhs0mQvz4ZDYT; Wed, 24 Aug 2022 05:11:25 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4MCDhs0CwHz3GpJ; Wed, 24 Aug 2022 05:11:25 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1661317885; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=HVGjFB1MkbQY7ii9E/37gYlsQBC948hndFdoOojypYw=; b=XGZ6+t95mHsM1A35EKmShU1Up77Ake7SwIWL0ms26C9Qdjg9VOhI7t7+Bd883J2QaXRmgq SGqQ9gSyp0GU0IFBr8XBRgjxXgz7dExDZVA09R9Pg6+IHcDY7bVsMvES8q9gcVd7HWvheg N1EoCUWUmQ17VeM48mxzWhkwLnGcaZwFULzKg/NY+9HLUAcMXF7BZXSGA5bM04IDVg5q+7 1GQ45Gpj2QlGkT4xaIYrjj2iup74JlgRUQB6b7oBP5oa2ZdK6r4NvWmvIGt0l3ffha/k91 PAXMwpSx7m25lYepvL2L03DtJawo9+GG55VoM6lGYXEXzOiD4PAGvzqH9IUA4Q== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4MCDhr6PVHzx0M; Wed, 24 Aug 2022 05:11:24 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 27O5BOtt063537; Wed, 24 Aug 2022 05:11:24 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 27O5BOcG063536; Wed, 24 Aug 2022 05:11:24 GMT (envelope-from git) Date: Wed, 24 Aug 2022 05:11:24 GMT Message-Id: <202208240511.27O5BOcG063536@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Xin LI Subject: git: 09f390a21553 - stable/13 - arc4random(3): Reduce diff with OpenBSD. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: delphij X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 09f390a21553f9adf8f581b40060b9b3c0f6a021 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1661317885; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=HVGjFB1MkbQY7ii9E/37gYlsQBC948hndFdoOojypYw=; b=JlMdTl+MnizqNrgl0+Nt+Yk+Vr6fzL5Vp6h+5N5LgCvlKN2L4BcrBxcR9Ye5vGdCiK3lp+ mkMo0t5ZHFvWEXZn++15bQ1FAZOCu+l0WDSjSgEQ4S7kjVwuq7ulJfgZUpGeoT/LuAlgFT DVZ5hQ9U0O319GG5skvg/IftD1tokFlFpK0s29sgLNW42A49sbnlqrdXbJYYhdDDu0v1d9 j3luLiUgSDwNNq/szrhgg9INWNgL06hCxAOb1rJoQxZzyT/P1BibFJKBG0BJk9FqD21sgk lsHRR0RdZuQD29CLhVGuFQiKmPOt9Fzd8BbQwO+ozP72ClCu9OAjpAidfGFWsA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1661317885; a=rsa-sha256; cv=none; b=J3PhjZB6OPLwxI79WnuwrFhiekZgVcIXtjNJxp5qC6kqaqkExbMFaL5rlFOQmlr07HQQBv r2lJfHh6AwpoauaMUFmOQx6xJSXAm1+AtbmxkxfsUQDmA1f3RB3KXUlBFgW9S/VXmdlfjE y5pQAN0SzDFvlUQqbEpjnY/vwmEppqg8rGs09Jhl02+nCpUfUKjZ6gZRhpVPWoBKRAocOR zI49hf4nhytLuRACONpfKgaUKq0RoeVVavOcpyU6XeVuxcfcgkL9wMYWd084lzp9i72YgT pHj3bgyN9XZpIx/7jsOLr6CtadUBXNI7FgvXS04+WYYV5wmM6TVrQjpCpSbGyw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by delphij: URL: https://cgit.FreeBSD.org/src/commit/?id=09f390a21553f9adf8f581b40060b9b3c0f6a021 commit 09f390a21553f9adf8f581b40060b9b3c0f6a021 Author: Xin LI AuthorDate: 2022-08-10 00:27:54 +0000 Commit: Xin LI CommitDate: 2022-08-24 05:11:09 +0000 arc4random(3): Reduce diff with OpenBSD. The main change was v1.57 by djm@: Randomise the rekey interval a little. Previously, the chacha20 instance would be rekeyed every 1.6MB. This makes it happen at a random point somewhere in the 1-2MB range. Reviewed by: csprng (markm, cem) Differential Revision: https://reviews.freebsd.org/D36088 (cherry picked from commit e9a2e4d1d28bf608a2ec915e25df9200af98e3b8) --- lib/libc/gen/arc4random.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/libc/gen/arc4random.c b/lib/libc/gen/arc4random.c index aecbdb8911bd..07e31e64e758 100644 --- a/lib/libc/gen/arc4random.c +++ b/lib/libc/gen/arc4random.c @@ -1,4 +1,4 @@ -/* $OpenBSD: arc4random.c,v 1.55 2019/03/24 17:56:54 deraadt Exp $ */ +/* $OpenBSD: arc4random.c,v 1.58 2022/07/31 13:41:45 tb Exp $ */ /* * Copyright (c) 1996, David Mazieres @@ -66,6 +66,8 @@ __FBSDID("$FreeBSD$"); #define BLOCKSZ 64 #define RSBUFSZ (16*BLOCKSZ) +#define REKEY_BASE (1024*1024) /* NB. should be a power of 2 */ + /* Marked INHERIT_ZERO, so zero'd out in fork children. */ static struct _rs { size_t rs_have; /* valid bytes at end of rs_buf */ @@ -106,6 +108,7 @@ static void _rs_stir(void) { u_char rnd[KEYSZ + IVSZ]; + uint32_t rekey_fuzz = 0; #if defined(__FreeBSD__) bool need_init; @@ -152,7 +155,10 @@ _rs_stir(void) rs->rs_have = 0; memset(rsx->rs_buf, 0, sizeof(rsx->rs_buf)); - rs->rs_count = 1600000; + /* rekey interval should not be predictable */ + chacha_encrypt_bytes(&rsx->rs_chacha, (uint8_t *)&rekey_fuzz, + (uint8_t *)&rekey_fuzz, sizeof(rekey_fuzz)); + rs->rs_count = REKEY_BASE + (rekey_fuzz % REKEY_BASE); } static inline void