2 * Copyright (C) 2012 Tobias Brunner
3 * Copyright (C) 2008 Martin Willi
4 * Hochschule fuer Technik Rapperswil
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25 typedef enum rng_quality_t rng_quality_t
;
26 typedef struct rng_t rng_t
;
31 * Quality of generated random bytes.
34 /** weak randomness, usable for nonces, IVs */
36 /** stronger randomness, usable for session keys */
38 /** true random key material */
43 * enum name for rng_quality_t.
45 extern enum_name_t
*rng_quality_names
;
48 * Generic interface for random number generators.
53 * Generates random bytes and writes them in the buffer.
55 * @param len number of bytes to get
56 * @param buffer pointer where the generated bytes will be written
57 * @return TRUE if bytes successfully written
59 bool (*get_bytes
)(rng_t
*this, size_t len
,
60 u_int8_t
*buffer
) __attribute__((warn_unused_result
));
63 * Generates random bytes and allocate space for them.
65 * @param len number of bytes to get
66 * @param chunk chunk which will hold generated bytes
67 * @return TRUE if allocation succeeded
69 bool (*allocate_bytes
)(rng_t
*this, size_t len
,
70 chunk_t
*chunk
) __attribute__((warn_unused_result
));
73 * Destroys a rng object.
75 void (*destroy
)(rng_t
*this);
79 * Wrapper around rng_t.get_bytes() ensuring that either all bytes or at least
80 * the first byte is not zero.
82 * @param rng rng_t object
83 * @param len number of bytes to get
84 * @param buffer pointer where the generated bytes will be written
85 * @param all TRUE if all bytes have to be non-zero, FALSE for first
86 * @return TRUE if bytes successfully written
88 bool rng_get_bytes_not_zero(rng_t
*rng
, size_t len
, u_int8_t
*buffer
,
89 bool all
) __attribute__((warn_unused_result
));
92 * Wrapper around rng_t.allocate_bytes() ensuring that either all bytes or at
93 * least the first byte is not zero.
95 * @param rng rng_t object
96 * @param len number of bytes to get
97 * @param chunk chunk that stores the generated bytes (allocated)
98 * @param all TRUE if all bytes have to be non-zero, FALSE for first
99 * @return TRUE if bytes successfully written
101 bool rng_allocate_bytes_not_zero(rng_t
*rng
, size_t len
, chunk_t
*chunk
,
102 bool all
) __attribute__((warn_unused_result
));
106 #endif /** RNG_H_ @}*/