blob: d3eedf764b92f46ebf5b6e34882f21623813e5a9 [file] [log] [blame]
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -05001/*
2 Copyright (C) 2006-2013 Werner Dittmann
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#ifndef _ZRTPRANDOM_H_
19#define _ZRTPRANDOM_H_
20
21/**
22 * @file ZrtpCommon.h
23 * @brief ZRTP standalone random number generator
24 * @defgroup GNU_ZRTP The GNU ZRTP C++ implementation
25 * @{
26 */
27
28#include <string.h>
29#if !(defined(_WIN32) || defined(_WIN64))
30#include <unistd.h>
31#endif
32#include <stdint.h>
33#include <sys/types.h>
34
35#ifdef __cplusplus
36class ZrtpRandom {
37public:
38 /**
39 * @brief This method adds entropy to the PRNG.
40 *
41 * An application may seed some entropy data to the PRNG. If the @c buffer is
42 * @c NULL or the @c length is zero then the method adds at least some system
43 * entropy.
44 *
45 * @param buffer some entropy data to add
46 *
47 * @param length length of entropy data in bytes
48 *
49 * @return on success: number of entropy bytes added, on failure: -1. Number of
50 * bytes added may be bigger then @c length because of added system
51 * entropy.
52 */
53 static int addEntropy(const uint8_t *buffer, uint32_t length);
54
55 /**
56 * @brief Get some random data.
57 *
58 * @param buffer that will contain the random data
59 *
60 * @param length how many bytes of random data to generate
61 *
62 * @return the number of generated random data bytes
63 */
64 static int getRandomData(uint8_t *buffer, uint32_t length);
65
66private:
67 static void initialize();
68 static size_t getSystemSeed(uint8_t *seed, size_t length);
69
70};
71#endif
72
73#ifdef __cplusplus
74extern "C"
75{
76#endif
77
78int zrtp_AddEntropy(const uint8_t *buffer, uint32_t length);
79
80int zrtp_getRandomData(uint8_t *buffer, uint32_t length);
81
82#ifdef __cplusplus
83}
84#endif
85
86#endif /* ZRTPRANDOM */