- randomizer_t written and tested
[strongswan.git] / Source / charon / utils / randomizer.h
1 /**
2 * @file randomizer.h
3 *
4 * @brief Class used to get random and pseudo random values
5 *
6 */
7
8 /*
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
21 */
22
23 #ifndef RANDOMIZER_H_
24 #define RANDOMIZER_H_
25
26 #include "../types.h"
27
28 /**
29 * Object representing an randomizer
30 *
31 * This class is thread save as file system read calls are thread save...
32 */
33 typedef struct randomizer_s randomizer_t;
34
35 struct randomizer_s {
36
37 /**
38 * @brief Reads a specific number of bytes from random device.
39 *
40 * @param this calling randomizer_t object
41 * @param bytes Number of bytes to read
42 * @param[out] buffer Pointer to buffer where to write the data in.
43 * Size of buffer has to be at least bytes.
44 * @return
45 * - SUCCESS
46 * - FAILED
47 */
48 status_t (*get_random_bytes) (randomizer_t *this,size_t bytes, u_int8_t *buffer);
49
50 /**
51 * @brief Reads a specific number of bytes from pseudo random device.
52 *
53 * @param this calling randomizer_t object
54 * @param bytes Number of bytes to read
55 * @param[out] buffer Pointer to buffer where to write the data in.
56 * Size of buffer has to be at least bytes.
57 * @return
58 * - SUCCESS
59 * - FAILED
60 */
61 status_t (*get_pseudo_random_bytes) (randomizer_t *this,size_t bytes, u_int8_t *buffer);
62
63
64 /**
65 * @brief Destroys a randomizer_t object.
66 *
67 * @param this randomizer_t object to destroy
68 * @return
69 * SUCCESS in any case
70 */
71 status_t (*destroy) (randomizer_t *this);
72 };
73
74 /**
75 * @brief Create an randomizer_t object
76 *
77 * @return
78 * - created randomizer_t, or
79 * - NULL if failed
80 */
81 randomizer_t *randomizer_create();
82
83 /**
84 * @brief Create an randomizer_t object with specific random device names
85 *
86 * @param random_dev_name Device name for random values, etc /dev/random
87 * @param prandom_dev_name Device name for pseudo random values, etc /dev/urandom
88 * @return
89 * - created randomizer_t, or
90 * - NULL if failed
91 */
92 randomizer_t *randomizer_create_on_devices(char * random_dev_name,char * prandom_dev_name);
93
94 #endif /*RANDOMIZER_H_*/