2 * Copyright (c) 2008-2012 Zmanda, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 2 as published
6 * by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 * Contact information: Zmanda Inc, 465 S. Mathilda Ave., Suite 300
18 * Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
26 /* A very simple, thread-safe PRNG. This is intended for use in generating
27 * reproducable bytestreams for testing purposes. It is *not*
28 * cryptographically secure! */
35 /* Initialize and seed the PRNG
37 * @param state: pointer to PRNG state
38 * @param seed: initial value
41 simpleprng_state_t *state,
44 /* Get a seed that will reproduce the PRNG's current state
46 * @param state: pointer to PRNG state
49 guint32 simpleprng_get_seed(
50 simpleprng_state_t *state);
52 /* Get a random guint32
54 * @param state: pointer to PRNG state
55 * @returns: random integer
57 guint32 simpleprng_rand(
58 simpleprng_state_t *state);
62 * @param state: pointer to PRNG state
63 * @returns: random integer
65 /* use the high-order bytes, as they're "more random" */
66 #define simpleprng_rand_byte(state) \
67 ((guint8)(simpleprng_rand((state)) >> 24))
69 /* Fill the given buffer with a sequence of bytes
71 * @param state: pointer to PRNG state
72 * @param buf: buffer to fill
73 * @param len: number of bytes to write
75 void simpleprng_fill_buffer(
76 simpleprng_state_t *state,
80 /* Verify that a buffer matches the values from the PRNG.
82 * @param state: pointer to PRNG state
83 * @param buf: buffer to verify
84 * @param len: number of bytes to verify
85 * @returns: true if all bytes match
87 gboolean simpleprng_verify_buffer(
88 simpleprng_state_t *state,
92 #endif /* SIMPLEPRNG_H */