about summary refs log tree commit diff
path: root/compat
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2022-12-23 17:11:44 -0500
committerJune McEnroe <june@causal.agency>2022-12-23 17:11:44 -0500
commit076695966a9df1902f60ec67595946ad643cdd29 (patch)
tree71fe7fbc40ecf77375205d80e790d1100b4c20fc /compat
parentImport LibreSSL 3.5.3 (diff)
downloadlibretls-076695966a9df1902f60ec67595946ad643cdd29.tar.gz
libretls-076695966a9df1902f60ec67595946ad643cdd29.zip
Import LibreSSL 3.6.0
Diffstat (limited to 'compat')
-rw-r--r--compat/arc4random.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/compat/arc4random.c b/compat/arc4random.c
index 6f95d57..1ec8e1e 100644
--- a/compat/arc4random.c
+++ b/compat/arc4random.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: arc4random.c,v 1.56 2022/02/28 21:56:29 dtucker Exp $	*/
+/*	$OpenBSD: arc4random.c,v 1.58 2022/07/31 13:41:45 tb Exp $	*/
 
 /*
  * Copyright (c) 1996, David Mazieres <dm@uun.org>
@@ -49,6 +49,8 @@
 #define BLOCKSZ	64
 #define RSBUFSZ	(16*BLOCKSZ)
 
+#define REKEY_BASE	(1024*1024) /* NB. should be a power of 2 */
+
 /* Marked MAP_INHERIT_ZERO, so zero'd out in fork children. */
 static struct _rs {
 	size_t		rs_have;	/* valid bytes at end of rs_buf */
@@ -86,6 +88,7 @@ static void
 _rs_stir(void)
 {
 	u_char rnd[KEYSZ + IVSZ];
+	uint32_t rekey_fuzz = 0;
 
 	if (getentropy(rnd, sizeof rnd) == -1)
 		_getentropy_fail();
@@ -100,7 +103,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