1 /*-
2  * Copyright (c) 2010, 2014
3  *	Thorsten Glaser <tg@mirbsd.org>
4  *
5  * Provided that these terms and disclaimer and all copyright notices
6  * are retained or reproduced in an accompanying document, permission
7  * is granted to deal in this work without restriction, including un-
8  * limited rights to use, publicly perform, distribute, sell, modify,
9  * merge, give away, or sublicence.
10  *
11  * This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to
12  * the utmost extent permitted by applicable law, neither express nor
13  * implied; without malicious intent or gross negligence. In no event
14  * may a licensor, author or contributor be held liable for indirect,
15  * direct, other damage, loss, or other issues arising in any way out
16  * of dealing in the work, even if advised of the possibility of such
17  * damage or existence of a defect, except proven that it results out
18  * of said person's immediate fault when using the work as intended.
19  *-
20  * Implementation of an old OpenBSD API with new arc4random(3).
21  */
22 
23 #include <syskern/libckern.h>
24 #include <stdlib.h>
25 #include "arc4random.h"
26 #include "thread_private.h"
27 
28 __RCSID("$MirOS: src/lib/libc/crypt/arc4random_addrandom.c,v 1.5 2014/03/29 10:35:45 tg Exp $");
29 
30 void
arc4random_addrandom(u_char * dat,int datlen)31 arc4random_addrandom(u_char *dat, int datlen)
32 {
33 	_ARC4_LOCK();
34 	if (!a4state.a4s_initialised)
35 		arc4random_stir_locked(0);
36 	while (datlen >= 256) {
37 		arcfour_ksa(&a4state.cipher, dat, 256);
38 		datlen -= 256;
39 	}
40 	if (datlen)
41 		arcfour_ksa(&a4state.cipher, dat, datlen);
42 	_ARC4_UNLOCK();
43 }
44 __warn_references(arc4random_addrandom, "arc4random_addrandom got deprecated by OpenBSD, use arc4random_pushb_fast instead");
45