fixed typo
[strongswan.git] / src / libstrongswan / utils / randomizer.h
1 /**
2 * @file randomizer.h
3 *
4 * @brief Interface of randomizer_t.
5 *
6 */
7
8 /*
9 * Copyright (C) 2005-2006 Martin Willi
10 * Copyright (C) 2005 Jan Hutter
11 * Hochschule fuer Technik Rapperswil
12 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
17 *
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 * for more details.
22 */
23
24 #ifndef RANDOMIZER_H_
25 #define RANDOMIZER_H_
26
27 typedef struct randomizer_t randomizer_t;
28
29 #include <library.h>
30
31 #ifndef DEV_RANDOM
32 /**
33 * Device to read real random bytes
34 */
35 # define DEV_RANDOM "/dev/random"
36 #endif
37
38 #ifndef DEV_URANDOM
39 /**
40 * Device to read pseudo random bytes
41 */
42 # define DEV_URANDOM "/dev/urandom"
43 #endif
44
45 /**
46 * @brief Class used to get random and pseudo random values.
47 *
48 * @b Constructors:
49 * - randomizer_create()
50 *
51 * @ingroup utils
52 */
53 struct randomizer_t {
54
55 /**
56 * @brief Reads a specific number of bytes from random device.
57 *
58 * @param this calling randomizer_t object
59 * @param bytes number of bytes to read
60 * @param[out] buffer pointer to buffer where to write the data in.
61 * Size of buffer has to be at least bytes.
62 * @return SUCCESS, or FAILED
63 */
64 status_t (*get_random_bytes) (randomizer_t *this, size_t bytes, u_int8_t *buffer);
65
66 /**
67 * @brief Allocates space and writes in random bytes.
68 *
69 * @param this calling randomizer_t object
70 * @param bytes number of bytes to allocate
71 * @param[out] chunk chunk which will hold the allocated random bytes
72 * @return SUCCESS, or FAILED
73 */
74 status_t (*allocate_random_bytes) (randomizer_t *this, size_t bytes, chunk_t *chunk);
75
76 /**
77 * @brief Reads a specific number of bytes from pseudo random device.
78 *
79 * @param this calling randomizer_t object
80 * @param bytes number of bytes to read
81 * @param[out] buffer pointer to buffer where to write the data in.
82 * size of buffer has to be at least bytes.
83 * @return SUCCESS, or FAILED
84 */
85 status_t (*get_pseudo_random_bytes) (randomizer_t *this,size_t bytes, u_int8_t *buffer);
86
87 /**
88 * @brief Allocates space and writes in pseudo random bytes.
89 *
90 * @param this calling randomizer_t object
91 * @param bytes number of bytes to allocate
92 * @param[out] chunk chunk which will hold the allocated random bytes
93 * @return SUCCESS, or FAILED
94 */
95 status_t (*allocate_pseudo_random_bytes) (randomizer_t *this, size_t bytes, chunk_t *chunk);
96
97 /**
98 * @brief Destroys a randomizer_t object.
99 *
100 * @param this randomizer_t object to destroy
101 */
102 void (*destroy) (randomizer_t *this);
103 };
104
105 /**
106 * @brief Creates a randomizer_t object.
107 *
108 * @return created randomizer_t, or
109 *
110 * @ingroup utils
111 */
112 randomizer_t *randomizer_create(void);
113
114 #endif /*RANDOMIZER_H_*/