Commit Graph

118 Commits

Author SHA1 Message Date
riastradh 67c16d2af5 Use an explicit run-time assertion where compile-time doesn't work. 2019-09-19 18:29:55 +00:00
riastradh 1557be4823 Use CTASSERT where possible, run-time assertion where not.
Should fix negative-length variable-length array found by kamil.
2019-09-19 14:34:59 +00:00
riastradh 8e07b51739 Switch from NIST CTR_DRBG with AES to NIST Hash_DRBG with SHA-256.
Benefits:

- larger seeds -- a 128-bit key alone is not enough for `128-bit security'
- better resistance to timing side channels than AES
- a better-understood security story (https://eprint.iacr.org/2018/349)
- no loss in compliance with US government standards that nobody ever
  got fired for choosing, at least in the US-dominated western world
- no dirty endianness tricks
- self-tests

Drawbacks:

- performance hit: throughput is reduced to about 1/3 in naive measurements
  => possible to mitigate by using hardware SHA-256 instructions
  => all you really need is 32 bytes to seed a userland PRNG anyway
  => if we just used ChaCha this would go away...

XXX pullup-7
XXX pullup-8
XXX pullup-9
2019-09-02 20:09:29 +00:00
mrg da2b3afaf6 add fallthru comments. i considered patching makefiles to ignore
these problems, but this code is dead upstream and likely will be
removed here rather than ever updated.
2019-02-04 08:23:53 +00:00
christos 87fd18f8e5 s/static inline/static __inline/g for consistency. 2018-04-19 21:50:06 +00:00
alnsn 6c4ed8c121 Add XTS mode. 2016-12-11 00:28:44 +00:00
riastradh 5c5f06b858 More rnd.h user cleanup. 2015-04-13 22:43:41 +00:00
riastradh 556fc62b15 cprng_strong(kern_cprng, ...) never blocks, pass 0 for flags.
FASYNC was wrong anyway!  It's FNONBLOCK.
2015-04-13 15:51:00 +00:00
justin 1624076525 Fix inconsistent use of inline in prototype and definition 2014-08-11 22:36:49 +00:00
riastradh 47d7f02ac0 Tweak cprng_fast_buf to use 32-bit unaligned writes if possible. 2014-08-11 13:22:16 +00:00
riastradh 0c0361fcdd Move initial entropy bookkeeping out of the fast path. 2014-08-11 13:12:53 +00:00
riastradh 7e518a1255 Use percpu_foreach instead of manual iteration. 2014-08-11 13:06:31 +00:00
riastradh 215d8661dd Access to struct cprng_fast must be consistently at IPL_VM. 2014-08-11 13:01:58 +00:00
riastradh bf5402594e No need for cprng_fast_seed to be inline. 2014-08-11 03:50:29 +00:00
riastradh a7da2729e7 Include <sys/rnd.h>, don't copypasta declare rnd_initial_entropy. 2014-08-11 03:47:49 +00:00
riastradh 8756d4c167 Sort #includes. 2014-08-11 03:46:54 +00:00
justin cd946d79cd define function consistently as inline 2014-08-10 22:35:32 +00:00
tls ea6af427bd Merge tls-earlyentropy branch into HEAD. 2014-08-10 16:44:32 +00:00
christos d22061e092 fix sprintf. 2014-03-25 16:28:15 +00:00
pgoyette f45c6e8a3c Create modules for software crypto components. 2014-01-01 15:18:57 +00:00
tls 6e1dd068e9 Separate /dev/random pseudodevice implemenation from kernel entropy pool
implementation.  Rewrite pseudodevice code to use cprng_strong(9).

The new pseudodevice is cloning, so each caller gets bits from a stream
generated with its own key.  Users of /dev/urandom get their generators
keyed on a "best effort" basis -- the kernel will rekey generators
whenever the entropy pool hits the high water mark -- while users of
/dev/random get their generators rekeyed every time key-length bits
are output.

The underlying cprng_strong API can use AES-256 or AES-128, but we use
AES-128 because of concerns about related-key attacks on AES-256.  This
improves performance (and reduces entropy pool depletion) significantly
for users of /dev/urandom but does cause users of /dev/random to rekey
twice as often.

Also fixes various bugs (including some missing locking and a reseed-counter
overflow in the CTR_DRBG code) found while testing this.

For long reads, this generator is approximately 20 times as fast as the
old generator (dd with bs=64K yields 53MB/sec on 2Ghz Core2 instead of
2.5MB/sec) and also uses a separate mutex per instance so concurrency
is greatly improved.  For reads of typical key sizes for modern
cryptosystems (16-32 bytes) performance is about the same as the old
code: a little better for 32 bytes, a little worse for 16 bytes.
2011-12-17 20:05:38 +00:00
macallan 19166a6288 NIST_CTR_DRBG.V is accessed as (unsigned long *) so we need to make sure
it's aligned accordingly or we go boom on sparc64
2011-11-21 23:48:52 +00:00
tls 3afd44cf08 First step of random number subsystem rework described in
<20111022023242.BA26F14A158@mail.netbsd.org>.  This change includes
the following:

	An initial cleanup and minor reorganization of the entropy pool
	code in sys/dev/rnd.c and sys/dev/rndpool.c.  Several bugs are
	fixed.  Some effort is made to accumulate entropy more quickly at
	boot time.

	A generic interface, "rndsink", is added, for stream generators to
	request that they be re-keyed with good quality entropy from the pool
	as soon as it is available.

	The arc4random()/arc4randbytes() implementation in libkern is
	adjusted to use the rndsink interface for rekeying, which helps
	address the problem of low-quality keys at boot time.

	An implementation of the FIPS 140-2 statistical tests for random
	number generator quality is provided (libkern/rngtest.c).  This
	is based on Greg Rose's implementation from Qualcomm.

	A new random stream generator, nist_ctr_drbg, is provided.  It is
	based on an implementation of the NIST SP800-90 CTR_DRBG by
	Henric Jungheim.  This generator users AES in a modified counter
	mode to generate a backtracking-resistant random stream.

	An abstraction layer, "cprng", is provided for in-kernel consumers
	of randomness.  The arc4random/arc4randbytes API is deprecated for
	in-kernel use.  It is replaced by "cprng_strong".  The current
	cprng_fast implementation wraps the existing arc4random
	implementation.  The current cprng_strong implementation wraps the
	new CTR_DRBG implementation.  Both interfaces are rekeyed from
	the entropy pool automatically at intervals justifiable from best
	current cryptographic practice.

	In some quick tests, cprng_fast() is about the same speed as
	the old arc4randbytes(), and cprng_strong() is about 20% faster
	than rnd_extract_data().  Performance is expected to improve.

	The AES code in src/crypto/rijndael is no longer an optional
	kernel component, as it is required by cprng_strong, which is
	not an optional kernel component.

	The entropy pool output is subjected to the rngtest tests at
	startup time; if it fails, the system will reboot.  There is
	approximately a 3/10000 chance of a false positive from these
	tests.  Entropy pool _input_ from hardware random numbers is
	subjected to the rngtest tests at attach time, as well as the
	FIPS continuous-output test, to detect bad or stuck hardware
	RNGs; if any are detected, they are detached, but the system
	continues to run.

	A problem with rndctl(8) is fixed -- datastructures with
	pointers in arrays are no longer passed to userspace (this
	was not a security problem, but rather a major issue for
	compat32).  A new kernel will require a new rndctl.

	The sysctl kern.arandom() and kern.urandom() nodes are hooked
	up to the new generators, but the /dev/*random pseudodevices
	are not, yet.

	Manual pages for the new kernel interfaces are forthcoming.
2011-11-19 22:51:18 +00:00
jmmv 9b52d4003a Revert my previous change. christos@ submitted a different fix pretty much
at the same time.  Did an update amd64 release build to ensure my change was
really not needed.
2011-05-14 16:46:55 +00:00
jmmv d899efcf6e Declare for-loop control variable outside of the for statement to prevent
a warning and therefore fix the build.
2011-05-14 16:27:49 +00:00
christos 018b374686 - don't assume aligned buffers.
- little KNF
2011-05-14 01:59:19 +00:00
drochner 9d083d2f9c add "camellia" crypto code, copied from FreeBSD 2011-05-05 17:38:35 +00:00
pooka 4d79e8c53d Apply const where necessary (XXX: where is bf_locl.org?) 2009-06-30 13:14:40 +00:00
dsl 02cdf4d2c8 Remove all the __P() from sys (excluding sys/dist)
Diff checked with grep and MK1 eyeball.
i386 and amd64 GENERIC and sys still build.
2009-03-14 14:45:51 +00:00
lukem 6ec6d598ac use __KERNEL_RCSID() 2007-12-11 23:31:07 +00:00
lukem 06d6cbc0d9 use __KERNEL_RCSID() 2007-12-11 23:13:57 +00:00
cbiere f5b684cf56 Added missing const-qualifiers. 2007-01-22 01:38:33 +00:00
cbiere 6d8f729825 Added const-qualifiers. 2007-01-21 23:00:08 +00:00
christos 31a62606ea Merge kernel and userland rmd160 and sha2 implementation.
XXX: We still install rmd160.h and sha2.h in /usr/include/crypto, unlike
the other hash functions which get installed in /usr/include for compatibility.
2006-10-27 21:20:48 +00:00
christos 78c43e9064 static comes first 2006-09-03 05:22:36 +00:00
mrg 084c052803 quell GCC 4.1 uninitialised variable warnings.
XXX: we should audit the tree for which old ones are no longer needed
after getting the older compilers out of the tree..
2006-05-10 21:53:14 +00:00
christos 95e1ffb156 merge ktrace-lwp. 2005-12-11 12:16:03 +00:00
elad e0d3e1c5ea RMD160_DIGEST_STRING_LENGTH is 41, including the terminating NUL. 2005-09-24 21:31:53 +00:00
elad b6c7f93fa8 Install rmd160.h to /usr/include/crypto. 2005-09-24 18:34:59 +00:00
elad ad7f55858f RMD160File() gets const char *, add RMD160FileChunk(). 2005-09-24 18:12:35 +00:00
elad 138b399207 Define RMD160_DIGEST_STRING_LENGTH. 2005-09-24 17:39:15 +00:00
elad 45b120e04b Lint warnings. 2005-09-11 16:11:22 +00:00
elad 7bdf56d9b6 Remove stuff inside #if 0, remove __P macro usage, add helper routines
prototypes inside #ifndef _KERNEL.
2005-08-23 16:23:50 +00:00
elad 935cb376b9 Make this usable both in kernel and userland. 2005-08-22 15:33:08 +00:00
elad 4bbe952358 Install sha2.h to /usr/include/crypto. 2005-08-20 15:42:03 +00:00
tron f84cd33e5f Remove unused functions SHA*_End() and SHA*_Data(). 2005-07-21 15:42:41 +00:00
martin 1ec429dfd5 Constify, to make it compile (at least).
XXX - I'm not sure with what args this is called, but my bet is that
there is no chance this code will work on alignment requiring archs.
2005-06-03 11:31:57 +00:00
christos 87de4cecc4 add a missing const 2005-05-31 00:43:56 +00:00
christos 0a86a6b05d sprinkle const 2005-05-30 04:13:14 +00:00
christos 362a4a0bd5 Yes, it was a cool trick >20 years ago to use "0123456789abcdef"[a] to
implement, xtoa(), but I think defining the samestring 50 times is a bit
too much. Defined HEXDIGITS and hexdigits in subr_prf.c and use it...
2005-05-17 04:14:57 +00:00