Made error code consistent with the other text parsing functions.
[gnutls.git] / lib / random.c
blob06b08dba60004d66cee3bfe270cb863ce6236875
1 /*
2 * Copyright (C) 2008-2012 Free Software Foundation, Inc.
4 * Author: Nikos Mavrogiannopoulos
6 * This file is part of GnuTLS.
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 3 of
11 * the License, or (at your option) any later version.
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.
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/>
23 /* This file handles all the internal functions that cope with random data.
26 #include <gnutls_int.h>
27 #include <gnutls_errors.h>
28 #include <random.h>
30 void *gnutls_rnd_ctx;
32 int
33 _gnutls_rnd_init (void)
35 if (_gnutls_rnd_ops.init != NULL)
37 if (_gnutls_rnd_ops.init (&gnutls_rnd_ctx) < 0)
39 gnutls_assert ();
40 return GNUTLS_E_RANDOM_FAILED;
44 return 0;
47 void
48 _gnutls_rnd_deinit (void)
50 if (_gnutls_rnd_ops.deinit != NULL)
52 _gnutls_rnd_ops.deinit (gnutls_rnd_ctx);
55 return;
58 /**
59 * gnutls_rnd:
60 * @level: a security level
61 * @data: place to store random bytes
62 * @len: The requested size
64 * This function will generate random data and store it to output
65 * buffer.
67 * Returns: Zero or a negative error code on error.
69 * Since: 2.12.0
70 **/
71 int
72 gnutls_rnd (gnutls_rnd_level_t level, void *data, size_t len)
74 return _gnutls_rnd(level, data, len);