1/*
2 * Copyright (C) 2008-2012 Free Software Foundation, Inc.
3 *
4 * Author: Nikos Mavrogiannopoulos
5 *
6 * This file is part of GnuTLS.
7 *
8 * The GnuTLS is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; either version 2.1 of
11 * the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>
20 *
21 */
22
23/* This file handles all the internal functions that cope with random data.
24 */
25
26#include <gnutls_int.h>
27#include <gnutls_errors.h>
28#include <random.h>
29
30void *gnutls_rnd_ctx;
31
32int
33_gnutls_rnd_init (void)
34{
35 if (_gnutls_rnd_ops.init != NULL)
36 {
37 if (_gnutls_rnd_ops.init (&gnutls_rnd_ctx) < 0)
38 {
39 gnutls_assert ();
40 return GNUTLS_E_RANDOM_FAILED;
41 }
42 }
43
44 return 0;
45}
46
47void
48_gnutls_rnd_deinit (void)
49{
50 if (_gnutls_rnd_ops.deinit != NULL)
51 {
52 _gnutls_rnd_ops.deinit (gnutls_rnd_ctx);
53 }
54
55 return;
56}
57
58/**
59 * gnutls_rnd:
60 * @level: a security level
61 * @data: place to store random bytes
62 * @len: The requested size
63 *
64 * This function will generate random data and store it to output
65 * buffer.
66 *
67 * Returns: Zero or a negative error code on error.
68 *
69 * Since: 2.12.0
70 **/
71int
72gnutls_rnd (gnutls_rnd_level_t level, void *data, size_t len)
73{
74 return _gnutls_rnd(level, data, len);
75}
76
77/**
78 * gnutls_rnd_refresh:
79 *
80 * This function refreshes the random generator state.
81 * That is the current precise time, CPU usage, and
82 * other values are input into its state.
83 *
84 * On a slower rate input from /dev/urandom is mixed too.
85 *
86 * Since: 3.1.7
87 **/
88void
89gnutls_rnd_refresh ()
90{
91 _gnutls_rnd_refresh();
92}
93