2 * Copyright (C) 2001 Nikos Mavroyanopoulos
4 * This file is part of GNUTLS.
6 * The GNUTLS library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <gnutls_int.h>
23 #include <gnutls_random.h>
24 #include <gnutls_errors.h>
29 # include <sys/types.h>
30 # include <sys/stat.h>
34 /* fills the buffer 'res' with random bytes of 'bytes' long.
35 * level is WEAK, STRONG, or VERY_STRONG (libgcrypt)
37 int _gnutls_get_random(opaque
* res
, int bytes
, int level
)
43 device
= "dev/urandom";
45 fd
= open(device
, O_RDONLY
);
46 if (device
== NULL
|| fd
< 0) {
47 _gnutls_log( "Could not open random device\n");
48 return GNUTLS_E_FILE_ERROR
;
54 #else /* using gcrypt */
55 gcry_randomize( res
, bytes
, level
);