08f7af2096cafa07cb4ba26b4eeb985d21343701
[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 * $Id: rng.h 3619 2008-03-19 14:02:52Z martin $
16 */
17
18 /**
19 * @defgroup rng rng
20 * @{ @ingroup crypto
21 */
22
23 #ifndef RNG_H_
24 #define RNG_H_
25
26 typedef enum rng_quality_t rng_quality_t;
27 typedef struct rng_t rng_t;
28
29 #include <library.h>
30
31 /**
32 * Quality of generated random bytes.
33 */
34 enum rng_quality_t {
35 /** weak randomness, usable for nonces, IVs */
36 RNG_WEAK,
37 /** stronger randomness, usable for session keys */
38 RNG_STRONG,
39 /** real random, key material */
40 RNG_REAL,
41 };
42
43 /**
44 * enum name for rng_quality_t.
45 */
46 extern enum_name_t *rng_quality_names;
47
48 /**
49 * Generic interface for random number generators.
50 */
51 struct rng_t {
52
53 /**
54 * Generates random bytes and writes them in the buffer.
55 *
56 * @param len number of bytes to get
57 * @param buffer pointer where the generated bytes will be written
58 */
59 void (*get_bytes) (rng_t *this, u_int len, u_int8_t *buffer);
60
61 /**
62 * Generates random bytes and allocate space for them.
63 *
64 * @param len number of bytes to get
65 * @param chunk chunk which will hold generated bytes
66 */
67 void (*allocate_bytes) (rng_t *this, u_int len, chunk_t *chunk);
68
69 /**
70 * Destroys a rng object.
71 */
72 void (*destroy) (rng_t *this);
73 };
74
75 #endif /*RNG_H_ @} */