xref: /titanic_50/usr/src/test/libc-tests/tests/random/arc4random_rekey.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  * This test is designed to fill a buffer with arc4random_buf and ensure that we
18*9d12795fSRobert Mustacchi  * rekey ourselves multiple times during this test. We have a 4 Mb buffer and
19*9d12795fSRobert Mustacchi  * currently we rekey ourselves every ~1.53 Mb. A wrapper script should call
20*9d12795fSRobert Mustacchi  * this with an appropriate bit of D to verify the rekey.
21*9d12795fSRobert Mustacchi  */
22*9d12795fSRobert Mustacchi 
23*9d12795fSRobert Mustacchi #include <stdlib.h>
24*9d12795fSRobert Mustacchi #include <assert.h>
25*9d12795fSRobert Mustacchi #include <errno.h>
26*9d12795fSRobert Mustacchi 
27*9d12795fSRobert Mustacchi #define	NENTS	(4 * 1024 * 1024)
28*9d12795fSRobert Mustacchi 
29*9d12795fSRobert Mustacchi int
main(void)30*9d12795fSRobert Mustacchi main(void)
31*9d12795fSRobert Mustacchi {
32*9d12795fSRobert Mustacchi 	uint8_t *buf;
33*9d12795fSRobert Mustacchi 
34*9d12795fSRobert Mustacchi 	buf = malloc(NENTS);
35*9d12795fSRobert Mustacchi 	assert(buf != NULL);
36*9d12795fSRobert Mustacchi 	arc4random_buf(buf, NENTS);
37*9d12795fSRobert Mustacchi 
38*9d12795fSRobert Mustacchi 	return (0);
39*9d12795fSRobert Mustacchi }
40