]>
Commit | Line | Data |
---|---|---|
7f3824c5 JH |
1 | /** |
2 | * @file randomizer.h | |
3 | * | |
32f78c2e | 4 | * @brief Interface of randomizer_t. |
7f3824c5 JH |
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 | ||
021c2322 | 26 | #include <types.h> |
7f3824c5 | 27 | |
59de5086 JH |
28 | |
29 | /** | |
68621281 | 30 | * Device to read real random bytes |
59de5086 | 31 | */ |
68621281 | 32 | #define RANDOM_DEVICE "/dev/random" |
59de5086 JH |
33 | |
34 | /** | |
68621281 | 35 | * Device to read pseudo random bytes |
59de5086 | 36 | */ |
68621281 | 37 | #define PSEUDO_RANDOM_DEVICE "/dev/urandom" |
59de5086 | 38 | |
5796aa16 MW |
39 | typedef struct randomizer_t randomizer_t; |
40 | ||
7f3824c5 | 41 | /** |
32f78c2e | 42 | * @brief Class used to get random and pseudo random values. |
7f3824c5 | 43 | * |
ca4468ad JH |
44 | * @b Constructors: |
45 | * - randomizer_create() | |
df3c59d0 | 46 | * |
32f78c2e | 47 | * @ingroup utils |
7f3824c5 | 48 | */ |
5796aa16 | 49 | struct randomizer_t { |
7f3824c5 JH |
50 | |
51 | /** | |
52 | * @brief Reads a specific number of bytes from random device. | |
53 | * | |
54 | * @param this calling randomizer_t object | |
32f78c2e JH |
55 | * @param bytes number of bytes to read |
56 | * @param[out] buffer pointer to buffer where to write the data in. | |
7f3824c5 | 57 | * Size of buffer has to be at least bytes. |
68621281 | 58 | * @return SUCCESS, or FAILED |
7f3824c5 | 59 | */ |
68621281 | 60 | status_t (*get_random_bytes) (randomizer_t *this, size_t bytes, u_int8_t *buffer); |
7f3824c5 | 61 | |
146e568f | 62 | /** |
32f78c2e | 63 | * @brief Allocates space and writes in random bytes. |
146e568f MW |
64 | * |
65 | * @param this calling randomizer_t object | |
32f78c2e | 66 | * @param bytes number of bytes to allocate |
d048df5c | 67 | * @param[out] chunk chunk which will hold the allocated random bytes |
68621281 | 68 | * @return SUCCESS, or FAILED |
146e568f | 69 | */ |
68621281 | 70 | status_t (*allocate_random_bytes) (randomizer_t *this, size_t bytes, chunk_t *chunk); |
146e568f | 71 | |
7f3824c5 JH |
72 | /** |
73 | * @brief Reads a specific number of bytes from pseudo random device. | |
74 | * | |
75 | * @param this calling randomizer_t object | |
32f78c2e JH |
76 | * @param bytes number of bytes to read |
77 | * @param[out] buffer pointer to buffer where to write the data in. | |
78 | * size of buffer has to be at least bytes. | |
68621281 | 79 | * @return SUCCESS, or FAILED |
7f3824c5 | 80 | */ |
68621281 | 81 | status_t (*get_pseudo_random_bytes) (randomizer_t *this,size_t bytes, u_int8_t *buffer); |
146e568f MW |
82 | |
83 | /** | |
32f78c2e | 84 | * @brief Allocates space and writes in pseudo random bytes. |
146e568f MW |
85 | * |
86 | * @param this calling randomizer_t object | |
32f78c2e | 87 | * @param bytes number of bytes to allocate |
68621281 MW |
88 | * @param[out] chunk chunk which will hold the allocated random bytes |
89 | * @return SUCCESS, or FAILED | |
146e568f | 90 | */ |
68621281 | 91 | status_t (*allocate_pseudo_random_bytes) (randomizer_t *this, size_t bytes, chunk_t *chunk); |
7f3824c5 JH |
92 | |
93 | /** | |
94 | * @brief Destroys a randomizer_t object. | |
95 | * | |
96 | * @param this randomizer_t object to destroy | |
7f3824c5 | 97 | */ |
d048df5c | 98 | void (*destroy) (randomizer_t *this); |
7f3824c5 JH |
99 | }; |
100 | ||
101 | /** | |
68621281 | 102 | * @brief Creates a randomizer_t object. |
7f3824c5 | 103 | * |
68621281 | 104 | * @return created randomizer_t, or |
32f78c2e JH |
105 | * |
106 | * @ingroup utils | |
7f3824c5 JH |
107 | */ |
108 | randomizer_t *randomizer_create(); | |
109 | ||
7f3824c5 | 110 | #endif /*RANDOMIZER_H_*/ |