|
Line 0
Link Here
|
|
|
1 |
/* $Id: port-linux.c,v 1.11.4.2 2011/02/04 00:43:08 djm Exp $ */ |
| 2 |
|
| 3 |
/* |
| 4 |
* Copyright (c) 2011 Jan F. Chadima <jchadima@redhat.com> |
| 5 |
* |
| 6 |
* Permission to use, copy, modify, and distribute this software for any |
| 7 |
* purpose with or without fee is hereby granted, provided that the above |
| 8 |
* copyright notice and this permission notice appear in all copies. |
| 9 |
* |
| 10 |
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 11 |
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 12 |
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 13 |
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 14 |
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 15 |
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 16 |
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 17 |
*/ |
| 18 |
|
| 19 |
/* |
| 20 |
* Linux-specific portability code - prng support |
| 21 |
*/ |
| 22 |
|
| 23 |
#include "includes.h" |
| 24 |
|
| 25 |
#include <errno.h> |
| 26 |
#include <stdarg.h> |
| 27 |
#include <string.h> |
| 28 |
#include <stdio.h> |
| 29 |
#include <openssl/rand.h> |
| 30 |
|
| 31 |
#include "log.h" |
| 32 |
#include "xmalloc.h" |
| 33 |
#include "servconf.h" |
| 34 |
#include "port-linux.h" |
| 35 |
#include "key.h" |
| 36 |
#include "hostfile.h" |
| 37 |
#include "auth.h" |
| 38 |
|
| 39 |
void |
| 40 |
linux_seed(void) |
| 41 |
{ |
| 42 |
int len; |
| 43 |
char *env = getenv("SSH_USE_STRONG_RNG"); |
| 44 |
char *random = "/dev/random"; |
| 45 |
size_t ienv, randlen = 6; |
| 46 |
|
| 47 |
if (!env || !strcmp(env, "0")) |
| 48 |
random = "/dev/urandom"; |
| 49 |
else if ((ienv = atoi(env)) > 6) |
| 50 |
randlen = ienv; |
| 51 |
|
| 52 |
errno = 0; |
| 53 |
if ((len = RAND_load_file(random, randlen)) != randlen) { |
| 54 |
if (errno) |
| 55 |
fatal ("cannot read from %s, %s", random, strerror(errno)); |
| 56 |
else |
| 57 |
fatal ("EOF reading %s", random); |
| 58 |
} |
| 59 |
} |