summaryrefslogtreecommitdiff
path: root/lib/libc/gen/arc4random.c
Commit message (Collapse)AuthorAgeFilesLines
* Return two fixes from previous backout which does not requireAndrey A. Chernov2008-09-091-1/+2
| | | | | | | | | | | | | | | | | | | | review by secteam@ for the reasons mentioned below. 1) Rename /dev/urandom to /dev/random since urandom marked as XXX Deprecated alias in /sys/dev/random/randomdev.c (this is our naming convention and no review by secteam@ required) 2) Set rs_stired flag after forced initialization to prevent double stearing. (this is already in OpenBSD, i.e. they don't have double stearing. It means that this change matches their code path and no additional secteam@ review required) Submitted by: Thorsten Glaser <tg@mirbsd.de> (2) Notes: svn path=/head/; revision=182886
* Restored from previous backing out (because that is OpenBSD way, soAndrey A. Chernov2008-08-031-12/+16
| | | | | | | | | | | | assumed to be reviewd by them): Stir directly from the kernel PRNG, without taking less random pid & time bytes too (when it is possible). The difference with OpenBSD code is that they have KERN_ARND sysctl for that task, while we need to read /dev/random Notes: svn path=/head/; revision=181261
* Per rwatson's request:Andrey A. Chernov2008-07-251-29/+17
| | | | | | | | | | | | | | | "If you don't get a review within a day or two, I would firmly recommend backing out the changes" back out all my changes, i.e. not comes from merging from OpenBSD as unreviewed by secteam@ yet. (OpenBSD changes stays in assumption they are reviewd by OpenBSD) Yes, it means some old bugs returned, like not setted rs_stired = 1 in arc4random_stir(3) causing double stirring. Notes: svn path=/head/; revision=180804
* Fixes based on bde's feedback.Andrey A. Chernov2008-07-221-9/+9
| | | | | | | | | | | | | 1) Unindent and sort variables. 2) Indent struct members. 3) Remove _packed, use guaranteed >128 bytes size and only first 128 bytes from the structure. 4) Reword comment. Obtained from: bde Notes: svn path=/head/; revision=180713
* Change /dev/urandom to /dev/random since urandom marked asAndrey A. Chernov2008-07-221-1/+1
| | | | | | | | XXX Deprecated alias in /sys/dev/random/randomdev.c Notes: svn path=/head/; revision=180700
* In arc4random_uniform() detect simple "power of two" case andAndrey A. Chernov2008-07-221-1/+5
| | | | | | | return just (arc4random() % upper_bound) Notes: svn path=/head/; revision=180690
* Add arc4random_uniform() function (to avoid "modulo bias")Andrey A. Chernov2008-07-221-0/+45
| | | | | | | Obtained from: OpenBSD Notes: svn path=/head/; revision=180688
* Increase initially dropped bytes from 512 to 768 (768 is alsoAndrey A. Chernov2008-07-221-3/+3
| | | | | | | | | | | suggested in the Ilya Mironov's article). 768 taken from another research where it treats as default for RC4-drop(768): http://www.users.zetnet.co.uk/hopwood/crypto/scan/cs.html#RC4-drop Minor style tweak. Notes: svn path=/head/; revision=180687
* 1) Use __packed attr on rdat structure to make it exact 128 bytes.Andrey A. Chernov2008-07-211-10/+17
| | | | | | | | | | | | | 2) Use gettimeofday() and getpid() only if reading from /dev/urandom fails or impossible. 3) Discard N bytes on very first initialization only (i.e. don't discard on re-stir). 4) Reduce N from 1024 to 512 as really suggested in the "(Not So) Random Shuffles of RC4" paper: http://research.microsoft.com/users/mironov/papers/rc4full.pdf Notes: svn path=/head/; revision=180676
* 1) Update copyright notice.Andrey A. Chernov2008-07-211-43/+53
| | | | | | | | | | | | 2) Eliminate "struct arc4_stream *as" arg since only single arg is possible. 3) Set rs.j = rs.i after arc4random key schedule to be more like arc4 stream cipher. Obtained from: OpenBSD Notes: svn path=/head/; revision=180672
* Implement arc4random_buf() functionAndrey A. Chernov2008-07-211-1/+16
| | | | | | | Obtained from: OpenBSD Notes: svn path=/head/; revision=180657
* Decrease arc4_count only when needed and with proper bytes amount.Andrey A. Chernov2008-07-211-1/+2
| | | | | | | Obtained from: OpenBSD Notes: svn path=/head/; revision=180656
* 1) Set stired flag after forced initialization.Andrey A. Chernov2008-07-211-1/+2
| | | | | | | | | | 2) Increase arc4_count to the limit OpenBSD use. Submitted by: Thorsten Glaser <tg@mirbsd.de> (1) Obtained from: OpenBSD (2) Notes: svn path=/head/; revision=180655
* ANSIfy function definitions, reduces diff against OpenBSD.Xin LI2007-05-251-17/+8
| | | | Notes: svn path=/head/; revision=169981
* Automatically re-stir every 400000 callsAndrey A. Chernov2006-10-041-2/+4
| | | | | | | Obtained from: OpenBSD Notes: svn path=/head/; revision=162995
* Add locking so that arc4random(3) functions are all reentrant forBrian Feldman2004-03-241-10/+54
| | | | | | | | | pthreads. Submitted by: Christian S.J. Peron <maneo@bsdpro.com> Notes: svn path=/head/; revision=127373
* Apply style(9).Brian Feldman2004-02-231-2/+6
| | | | | | | | Submitted by: "Christian S.J. Peron" <maneo@bsdpro.com> PR: bin/63283 Notes: svn path=/head/; revision=126180
* style cleanup: Remove duplicate $FreeBSD$ tags.Colin Percival2004-02-101-2/+0
| | | | | | | | | | | These files had tags at the start of the file (incorrect, removed), and after the copyright notices (correct). Approved by: rwatson (mentor) Notes: svn path=/head/; revision=125667
* Discard the first 1024 bytes of output as suggested byDavid Schultz2004-01-201-1/+13
| | | | | | | | | | | http://citeseer.nj.nec.com/fluhrer01weaknesses.html and http://citeseer.nj.nec.com/531224.html . PR: 61126 Submitted by: Jeff Ito <jeffi@rcn.com> Notes: svn path=/head/; revision=124741
* Fix the style of the SCM ID's.David E. O'Brien2002-03-221-2/+5
| | | | | | | I believe have made all of libc .c's as consistent as possible. Notes: svn path=/head/; revision=92986
* Remove _THREAD_SAFE and make libc thread-safe by default byDaniel Eischen2001-01-241-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | adding (weak definitions to) stubs for some of the pthread functions. If the threads library is linked in, the real pthread functions will pulled in. Use the following convention for system calls wrapped by the threads library: __sys_foo - actual system call _foo - weak definition to __sys_foo foo - weak definition to __sys_foo Change all libc uses of system calls wrapped by the threads library from foo to _foo. In order to define the prototypes for _foo(), we introduce namespace.h and un-namespace.h (suggested by bde). All files that need to reference these system calls, should include namespace.h before any standard includes, then include un-namespace.h after the standard includes and before any local includes. <db.h> is an exception and shouldn't be included in between namespace.h and un-namespace.h namespace.h will define foo to _foo, and un-namespace.h will undefine foo. Try to eliminate some of the recursive calls to MT-safe functions in libc/stdio in preparation for adding a mutex to FILE. We have recursive mutexes, but would like to avoid using them if possible. Remove uneeded includes of <errno.h> from a few files. Add $FreeBSD$ to a few files in order to pass commitprep. Approved by: -arch Notes: svn path=/head/; revision=71579
* Simplify sytem call renaming. Instead of _foo() <-- _libc_foo <-- foo(),Jason Evans2000-01-271-3/+3
| | | | | | | | | | | | | | | | | | | | just use _foo() <-- foo(). In the case of a libpthread that doesn't do call conversion (such as linuxthreads and our upcoming libpthread), this is adequate. In the case of libc_r, we still need three names, which are now _thread_sys_foo() <-- _foo() <-- foo(). Convert all internal libc usage of: aio_suspend(), close(), fsync(), msync(), nanosleep(), open(), fcntl(), read(), and write() to _foo() instead of foo(). Remove all internal libc usage of: creat(), pause(), sleep(), system(), tcdrain(), wait(), and waitpid(). Make thread cancellation fully POSIX-compliant. Suggested by: deischen Notes: svn path=/head/; revision=56698
* Add three-tier symbol naming in support of POSIX thread cancellationJason Evans2000-01-121-3/+3
| | | | | | | | | points. For library functions, the pattern is __sleep() <-- _libc_sleep() <-- sleep(). The arrows represent weak aliases. For system calls, the pattern is _read() <-- _libc_read() <-- read(). Notes: svn path=/head/; revision=55837
* $Id$ -> $FreeBSD$Peter Wemm1999-08-281-1/+1
| | | | Notes: svn path=/head/; revision=50476
* Add arc4random() functions from OpenBSD. They are almost same as ourAndrey A. Chernov1997-06-141-0/+172
srandomdev(), but can be used inside libraries. random() can't be used inside libraries because it breaks its possible predictable sequence. arc4random() is true random as designed, so its usage is library-safe. Obtained from: OpenBSD Notes: svn path=/head/; revision=26628