From nobody Wed Aug 10 00:28:21 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 4M2W4j2grKz4Y5S7; Wed, 10 Aug 2022 00:28:21 +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 4M2W4j2Cbfz3pbJ; Wed, 10 Aug 2022 00:28:21 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1660091301; 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=4BzfWqcFz7SWhK5scGYinozKxQJhpRDqY5YbbMjb+RA=; b=fZjh3E+6H5c9WJ15MZciEH950/Z7u/3Anb3yIsmcjMBmUTaS1AUG7XZbGzUS2H+DNQXV7t 17t7JmC9TJ68uRTZOmSFyQ9mkQlK5S6DFibN3Xa0XPnf6Fl2eLN/6OjGI1DXo5C9eLOpdV HIfSYOkxFIOgRrKZoFiBqjIlvJxT7rYvadYP8Nwd60ATV74K67I2ncqUuyxB16wazswz5p AcES4jns6pB5nNEdoUyIMjzvOsDTD9aKEtX4ZUO72nCwWBWZoFuJqP6MaXDzA7a0M/KAMP OMGJ9oqb9zGyPIPEUdEWuJIm7rutHks4+gePaR3u56/mAqFzPMGodwYKVI0e6Q== 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 4M2W4j193hzrsN; Wed, 10 Aug 2022 00:28:21 +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 27A0SLih090305; Wed, 10 Aug 2022 00:28:21 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 27A0SLgo090304; Wed, 10 Aug 2022 00:28:21 GMT (envelope-from git) Date: Wed, 10 Aug 2022 00:28:21 GMT Message-Id: <202208100028.27A0SLgo090304@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Xin LI Subject: git: e9a2e4d1d28b - main - 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/main X-Git-Reftype: branch X-Git-Commit: e9a2e4d1d28bf608a2ec915e25df9200af98e3b8 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1660091301; 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=4BzfWqcFz7SWhK5scGYinozKxQJhpRDqY5YbbMjb+RA=; b=r6ESi0cx+Lv4inUTH1qbjkFiKPmG5fyIvapaeMS7mEmsiChhcaXUlZjE2MvIsBYVUSGCYa tfU8/2et6QjbNijkWQWaAIu0KBMT5659MdhnXOXwuWWfbGoOrIhcR4HiLow7SZeyoDnYh1 oDSO/11BFMZh8fsEWBPWR/d4h0vPfwRtEbSNZYVDgkLDQMOxeItkbPwbm64llI3uTpKv7n ZKuCrYKDcxxk2Edp4ydLlgJOoaFZh+GcfrKHafnny+O8VwJ48ZKWUe+laoXhLeHJ30X1o1 NSy0x/q963MX4m5rovWnoMGc0gD6T9w/XrCnHUBgjqyRoapO8Y7b2/Y958oI8g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1660091301; a=rsa-sha256; cv=none; b=FucJAczd78wZen7nzx7Vs8TDMC5wqi/Vxkbuc9VNHGIy2wuGIDC1IYWSNHA3B/yz0j0y0+ xiHjHbXYLJcf0Pxi8iAR4uyMJgARhQf6Os3uZAfKkBa6LGI/aN04jGlY/nA/HT1M3YUibo 2jp1MnmlIkD3+cZ6vJdp8Jsvk/Jxj1xp1MGyphQBIx5hG//P9oOaWXcRpHx9n+Wr0EVcfG tsAFYAVxMbH352RZwqDnbbUXGgtRIWs+LQ4+eQF2bnL8rXtl6gQL9wpoxTuzvC5Nbga0fM QfH7o8SIHUhBGn05HX3jrNz7WBzYHvqkEImk8yFz5yhkk2YAQtcymExHy3cD+g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by delphij: URL: https://cgit.FreeBSD.org/src/commit/?id=e9a2e4d1d28bf608a2ec915e25df9200af98e3b8 commit e9a2e4d1d28bf608a2ec915e25df9200af98e3b8 Author: Xin LI AuthorDate: 2022-08-10 00:27:54 +0000 Commit: Xin LI CommitDate: 2022-08-10 00:27:55 +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) MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D36088 --- 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