xref: /titanic_44/usr/src/test/libc-tests/tests/random/arc4random.c (revision 9d12795f87b63c2e39e87bff369182edd34677d3)
1*9d12795fSRobert Mustacchi /*
2*9d12795fSRobert Mustacchi  * This file and its contents are supplied under the terms of the
3*9d12795fSRobert Mustacchi  * Common Development and Distribution License ("CDDL"), version 1.0.
4*9d12795fSRobert Mustacchi  * You may only use this file in accordance with the terms of version
5*9d12795fSRobert Mustacchi  * 1.0 of the CDDL.
6*9d12795fSRobert Mustacchi  *
7*9d12795fSRobert Mustacchi  * A full copy of the text of the CDDL should have accompanied this
8*9d12795fSRobert Mustacchi  * source.  A copy of the CDDL is also available via the Internet at
9*9d12795fSRobert Mustacchi  * http://www.illumos.org/license/CDDL.
10*9d12795fSRobert Mustacchi  */
11*9d12795fSRobert Mustacchi 
12*9d12795fSRobert Mustacchi /*
13*9d12795fSRobert Mustacchi  * Copyright (c) 2015, Joyent, Inc.
14*9d12795fSRobert Mustacchi  */
15*9d12795fSRobert Mustacchi 
16*9d12795fSRobert Mustacchi /*
17*9d12795fSRobert Mustacchi  * Basic tests for the arc4random(3C) family of functions. They should always
18*9d12795fSRobert Mustacchi  * succeed, let's make sure these do.
19*9d12795fSRobert Mustacchi  */
20*9d12795fSRobert Mustacchi 
21*9d12795fSRobert Mustacchi #include <stdlib.h>
22*9d12795fSRobert Mustacchi #include <assert.h>
23*9d12795fSRobert Mustacchi #include <errno.h>
24*9d12795fSRobert Mustacchi 
25*9d12795fSRobert Mustacchi int
main(void)26*9d12795fSRobert Mustacchi main(void)
27*9d12795fSRobert Mustacchi {
28*9d12795fSRobert Mustacchi 	uint32_t ret;
29*9d12795fSRobert Mustacchi 	uint8_t buf[32];
30*9d12795fSRobert Mustacchi 
31*9d12795fSRobert Mustacchi 	(void) arc4random();
32*9d12795fSRobert Mustacchi 	ret = arc4random_uniform(100);
33*9d12795fSRobert Mustacchi 	assert(ret < 100);
34*9d12795fSRobert Mustacchi 	ret = arc4random_uniform(200);
35*9d12795fSRobert Mustacchi 	assert(ret < 200);
36*9d12795fSRobert Mustacchi 
37*9d12795fSRobert Mustacchi 	arc4random_buf(buf, sizeof (buf));
38*9d12795fSRobert Mustacchi 
39*9d12795fSRobert Mustacchi 	return (0);
40*9d12795fSRobert Mustacchi }
41