Re: svn commit: r366620 - in head/sys: conf dev/random/fenestrasX

2020-10-11 Thread Mark Murray


> On 10 Oct 2020, at 22:45, Conrad Meyer  wrote:
> 
> Author: cem
> Date: Sat Oct 10 21:45:59 2020
> New Revision: 366620
> URL: https://svnweb.freebsd.org/changeset/base/366620
> 
> Log:
>  Add "Fenestras X" alternative /dev/random implementation

This is a much needed improvement to the (CS)PRNG, as we are
now supporting SMTP architectures with many cores, where this
should shine!

I have not had the time to do the work myself, so I'm delighted that
*someone* got to it!

Thanks, Conrad!

M
--



signature.asc
Description: Message signed with OpenPGP


svn commit: r366620 - in head/sys: conf dev/random/fenestrasX

2020-10-10 Thread Conrad Meyer
Author: cem
Date: Sat Oct 10 21:45:59 2020
New Revision: 366620
URL: https://svnweb.freebsd.org/changeset/base/366620

Log:
  Add "Fenestras X" alternative /dev/random implementation
  
  Fortuna remains the default; no functional change to GENERIC.
  
  Big picture:
  - Scalable entropy generation with per-CPU, buffered local generators.
  - "Push" system for reseeding child generators when root PRNG is
reseeded.  (Design can be extended to arc4random(9) and userspace
generators.)
  - Similar entropy pooling system to Fortuna, but starts with a single
pool to quickly bootstrap as much entropy as possible early on.
  - Reseeding from pooled entropy based on time schedule.  The time
interval starts small and grows exponentially until reaching a cap.
Again, the goal is to have the RNG state depend on as much entropy as
possible quickly, but still periodically incorporate new entropy for
the same reasons as Fortuna.
  
  Notable design choices in this implementation that differ from those
  specified in the whitepaper:
  - Blake2B instead of SHA-2 512 for entropy pooling
  - Chacha20 instead of AES-CTR DRBG
  - Initial seeding.  We support more platforms and not all of them use
loader(8).  So we have to grab the initial entropy sources in kernel
mode instead, as much as possible.  Fortuna didn't have any mechanism
for this aside from the special case of loader-provided previous-boot
entropy, so most of these sources remain TODO after this commit.
  
  Reviewed by:  markm
  Approved by:  csprng (markm)
  Differential Revision:https://reviews.freebsd.org/D22837

Added:
  head/sys/dev/random/fenestrasX/
  head/sys/dev/random/fenestrasX/fx_brng.c   (contents, props changed)
  head/sys/dev/random/fenestrasX/fx_brng.h   (contents, props changed)
  head/sys/dev/random/fenestrasX/fx_hash.h   (contents, props changed)
  head/sys/dev/random/fenestrasX/fx_main.c   (contents, props changed)
  head/sys/dev/random/fenestrasX/fx_pool.c   (contents, props changed)
  head/sys/dev/random/fenestrasX/fx_pool.h   (contents, props changed)
  head/sys/dev/random/fenestrasX/fx_priv.h   (contents, props changed)
  head/sys/dev/random/fenestrasX/fx_rng.c   (contents, props changed)
  head/sys/dev/random/fenestrasX/fx_rng.h   (contents, props changed)
Modified:
  head/sys/conf/NOTES
  head/sys/conf/files
  head/sys/conf/options

Modified: head/sys/conf/NOTES
==
--- head/sys/conf/NOTES Sat Oct 10 18:22:12 2020(r366619)
+++ head/sys/conf/NOTES Sat Oct 10 21:45:59 2020(r366620)
@@ -2772,6 +2772,8 @@ options   RCTL
 optionsMAXFILES=999
 
 # Random number generator
+# Alternative algorithm.
+#options   RANDOM_FENESTRASX
 # Allow the CSPRNG algorithm to be loaded as a module.
 #options   RANDOM_LOADABLE
 # Select this to allow high-rate but potentially expensive

Modified: head/sys/conf/files
==
--- head/sys/conf/files Sat Oct 10 18:22:12 2020(r366619)
+++ head/sys/conf/files Sat Oct 10 21:45:59 2020(r366620)
@@ -722,7 +722,7 @@ contrib/zstd/lib/decompress/zstd_decompress_block.c op
compile-with "${ZSTD_C} ${ZSTD_DECOMPRESS_BLOCK_FLAGS}"
 contrib/zstd/lib/decompress/huf_decompress.c   optional zstdio compile-with 
${ZSTD_C}
 # Blake 2
-contrib/libb2/blake2b-ref.coptional crypto | ipsec | ipsec_support \
+contrib/libb2/blake2b-ref.coptional crypto | ipsec | ipsec_support | 
!random_loadable random_fenestrasx \
compile-with "${NORMAL_C} -I$S/crypto/blake2 -Wno-cast-qual 
-DSUFFIX=_ref -Wno-unused-function"
 contrib/libb2/blake2s-ref.coptional crypto | ipsec | ipsec_support \
compile-with "${NORMAL_C} -I$S/crypto/blake2 -Wno-cast-qual 
-DSUFFIX=_ref -Wno-unused-function"
@@ -2820,7 +2820,14 @@ rt2860.fwoptional rt2860fw | 
ralfw   \
 dev/random/random_infra.c  standard
 dev/random/random_harvestq.c   standard
 dev/random/randomdev.c optional !random_loadable
-dev/random/fortuna.c   optional !random_loadable
+dev/random/fenestrasX/fx_brng.coptional !random_loadable 
random_fenestrasx
+dev/random/fenestrasX/fx_main.coptional !random_loadable 
random_fenestrasx \
+   compile-with "${NORMAL_C} -I$S/crypto/blake2"
+dev/random/fenestrasX/fx_pool.coptional !random_loadable 
random_fenestrasx \
+   compile-with "${NORMAL_C} -I$S/crypto/blake2"
+dev/random/fenestrasX/fx_rng.c optional !random_loadable random_fenestrasx \
+   compile-with "${NORMAL_C} -I$S/crypto/blake2"
+dev/random/fortuna.c   optional !random_loadable !random_fenestrasx
 dev/random/hash.c  optional !random_loadable
 dev/rccgpio/rccgpio.c  optional rccgpio gpio
 dev/re/if_re.c optional re

Modified: head/sys/conf/options