36ef52bb498e04507ed50cb1dcfe523bfbc49b02
[strongswan.git] / src / libstrongswan / crypto / rngs / rng.h
1 /*
2 * Copyright (C) 2008 Martin Willi
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 /**
17 * @defgroup rng rng
18 * @{ @ingroup crypto
19 */
20
21 #ifndef RNG_H_
22 #define RNG_H_
23
24 typedef enum rng_quality_t rng_quality_t;
25 typedef struct rng_t rng_t;
26
27 #include <library.h>
28
29 /**
30 * Quality of generated random bytes.
31 */
32 enum rng_quality_t {
33 /** weak randomness, usable for nonces, IVs */
34 RNG_WEAK,
35 /** stronger randomness, usable for session keys */
36 RNG_STRONG,
37 /** true random key material */
38 RNG_TRUE,
39 };
40
41 /**
42 * enum name for rng_quality_t.
43 */
44 extern enum_name_t *rng_quality_names;
45
46 /**
47 * Generic interface for random number generators.
48 */
49 struct rng_t {
50
51 /**
52 * Generates random bytes and writes them in the buffer.
53 *
54 * @param len number of bytes to get
55 * @param buffer pointer where the generated bytes will be written
56 */
57 void (*get_bytes) (rng_t *this, size_t len, u_int8_t *buffer);
58
59 /**
60 * Generates random bytes and allocate space for them.
61 *
62 * @param len number of bytes to get
63 * @param chunk chunk which will hold generated bytes
64 */
65 void (*allocate_bytes) (rng_t *this, size_t len, chunk_t *chunk);
66
67 /**
68 * Destroys a rng object.
69 */
70 void (*destroy) (rng_t *this);
71 };
72
73 #endif /** RNG_H_ @}*/