|
Lines 41-49
Link Here
|
| 41 |
|
41 |
|
| 42 |
RCSID("$Id: ssh-rand-helper.c,v 1.13 2003/08/21 23:34:41 djm Exp $"); |
42 |
RCSID("$Id: ssh-rand-helper.c,v 1.13 2003/08/21 23:34:41 djm Exp $"); |
| 43 |
|
43 |
|
| 44 |
/* Number of bytes we write out */ |
|
|
| 45 |
#define OUTPUT_SEED_SIZE 48 |
| 46 |
|
| 47 |
/* Length of on-disk seedfiles */ |
44 |
/* Length of on-disk seedfiles */ |
| 48 |
#define SEED_FILE_SIZE 1024 |
45 |
#define SEED_FILE_SIZE 1024 |
| 49 |
|
46 |
|
|
Lines 174-183
Link Here
|
| 174 |
|
171 |
|
| 175 |
if (connect(fd, (struct sockaddr*)&addr, addr_len) == -1) { |
172 |
if (connect(fd, (struct sockaddr*)&addr, addr_len) == -1) { |
| 176 |
if (tcp_port != 0) { |
173 |
if (tcp_port != 0) { |
| 177 |
error("Couldn't connect to PRNGD port %d: %s", |
174 |
debug("Couldn't connect to PRNGD port %d: %s", |
| 178 |
tcp_port, strerror(errno)); |
175 |
tcp_port, strerror(errno)); |
| 179 |
} else { |
176 |
} else { |
| 180 |
error("Couldn't connect to PRNGD socket \"%s\": %s", |
177 |
debug("Couldn't connect to PRNGD socket \"%s\": %s", |
| 181 |
addr_un->sun_path, strerror(errno)); |
178 |
addr_un->sun_path, strerror(errno)); |
| 182 |
} |
179 |
} |
| 183 |
goto done; |
180 |
goto done; |
|
Lines 749-754
Link Here
|
| 749 |
return cur_cmd < MIN_ENTROPY_SOURCES ? -1 : 0; |
746 |
return cur_cmd < MIN_ENTROPY_SOURCES ? -1 : 0; |
| 750 |
} |
747 |
} |
| 751 |
|
748 |
|
|
|
749 |
void rand_helper(unsigned char *buf, int bytes) |
| 750 |
{ |
| 751 |
struct stat st; |
| 752 |
int rval; |
| 753 |
|
| 754 |
if (!buf) |
| 755 |
return; |
| 756 |
|
| 757 |
#ifdef USE_SEED_FILES |
| 758 |
prng_read_seedfile(); |
| 759 |
#endif |
| 760 |
|
| 761 |
/* |
| 762 |
* Seed the RNG from wherever we can |
| 763 |
*/ |
| 764 |
|
| 765 |
/* Take whatever is on the stack, but don't credit it */ |
| 766 |
RAND_add(buf, bytes, 0); |
| 767 |
|
| 768 |
debug("Seeded RNG with %i bytes from system calls", |
| 769 |
(int)stir_from_system()); |
| 770 |
|
| 771 |
rval = -1; |
| 772 |
#ifdef PRNGD_PORT |
| 773 |
rval = get_random_bytes_prngd(buf, bytes, PRNGD_PORT, NULL); |
| 774 |
#elif defined(PRNGD_SOCKET) |
| 775 |
rval = get_random_bytes_prngd(buf, bytes, 0, PRNGD_SOCKET); |
| 776 |
#endif |
| 777 |
#if defined(PRNGD_PORT) || defined(PRNGD_SOCKET) |
| 778 |
if (rval == -1) |
| 779 |
debug("Entropy collection from PRNGD failed"); |
| 780 |
else |
| 781 |
RAND_add(buf, bytes, bytes); |
| 782 |
#endif |
| 783 |
if ((rval == -1) && (stat(SSH_PRNG_COMMAND_FILE, &st) == 0)) { |
| 784 |
/* Read in collection commands */ |
| 785 |
if (prng_read_commands(SSH_PRNG_COMMAND_FILE) == -1) |
| 786 |
fatal("PRNG initialisation failed -- exiting."); |
| 787 |
debug("Seeded RNG with %i bytes from programs", |
| 788 |
(int)stir_from_programs()); |
| 789 |
} |
| 790 |
|
| 791 |
#ifdef USE_SEED_FILES |
| 792 |
prng_write_seedfile(); |
| 793 |
#endif |
| 794 |
} |
| 795 |
|
| 796 |
#ifndef STATIC_RAND_HELPER |
| 797 |
|
| 752 |
void |
798 |
void |
| 753 |
usage(void) |
799 |
usage(void) |
| 754 |
{ |
800 |
{ |
|
Lines 758-764
Link Here
|
| 758 |
fprintf(stderr, " -x Force output in hexidecimal (for debugging)\n"); |
804 |
fprintf(stderr, " -x Force output in hexidecimal (for debugging)\n"); |
| 759 |
fprintf(stderr, " -X Force output in binary\n"); |
805 |
fprintf(stderr, " -X Force output in binary\n"); |
| 760 |
fprintf(stderr, " -b bytes Number of bytes to output (default %d)\n", |
806 |
fprintf(stderr, " -b bytes Number of bytes to output (default %d)\n", |
| 761 |
OUTPUT_SEED_SIZE); |
807 |
RANDOM_SEED_SIZE); |
| 762 |
} |
808 |
} |
| 763 |
|
809 |
|
| 764 |
int |
810 |
int |
|
Lines 774-780
Link Here
|
| 774 |
|
820 |
|
| 775 |
ll = SYSLOG_LEVEL_INFO; |
821 |
ll = SYSLOG_LEVEL_INFO; |
| 776 |
debug_level = output_hex = 0; |
822 |
debug_level = output_hex = 0; |
| 777 |
bytes = OUTPUT_SEED_SIZE; |
823 |
bytes = RANDOM_SEED_SIZE; |
| 778 |
|
824 |
|
| 779 |
/* Don't write binary data to a tty, unless we are forced to */ |
825 |
/* Don't write binary data to a tty, unless we are forced to */ |
| 780 |
if (isatty(STDOUT_FILENO)) |
826 |
if (isatty(STDOUT_FILENO)) |
|
Lines 806-847
Link Here
|
| 806 |
} |
852 |
} |
| 807 |
|
853 |
|
| 808 |
log_init(argv[0], ll, SYSLOG_FACILITY_USER, 1); |
854 |
log_init(argv[0], ll, SYSLOG_FACILITY_USER, 1); |
| 809 |
|
|
|
| 810 |
#ifdef USE_SEED_FILES |
| 811 |
prng_read_seedfile(); |
| 812 |
#endif |
| 813 |
|
855 |
|
| 814 |
buf = xmalloc(bytes); |
856 |
buf = xmalloc(bytes); |
| 815 |
|
857 |
rand_helper(buf, bytes); |
| 816 |
/* |
|
|
| 817 |
* Seed the RNG from wherever we can |
| 818 |
*/ |
| 819 |
|
| 820 |
/* Take whatever is on the stack, but don't credit it */ |
| 821 |
RAND_add(buf, bytes, 0); |
| 822 |
|
| 823 |
debug("Seeded RNG with %i bytes from system calls", |
| 824 |
(int)stir_from_system()); |
| 825 |
|
| 826 |
#ifdef PRNGD_PORT |
| 827 |
if (get_random_bytes_prngd(buf, bytes, PRNGD_PORT, NULL) == -1) |
| 828 |
fatal("Entropy collection failed"); |
| 829 |
RAND_add(buf, bytes, bytes); |
| 830 |
#elif defined(PRNGD_SOCKET) |
| 831 |
if (get_random_bytes_prngd(buf, bytes, 0, PRNGD_SOCKET) == -1) |
| 832 |
fatal("Entropy collection failed"); |
| 833 |
RAND_add(buf, bytes, bytes); |
| 834 |
#else |
| 835 |
/* Read in collection commands */ |
| 836 |
if (prng_read_commands(SSH_PRNG_COMMAND_FILE) == -1) |
| 837 |
fatal("PRNG initialisation failed -- exiting."); |
| 838 |
debug("Seeded RNG with %i bytes from programs", |
| 839 |
(int)stir_from_programs()); |
| 840 |
#endif |
| 841 |
|
| 842 |
#ifdef USE_SEED_FILES |
| 843 |
prng_write_seedfile(); |
| 844 |
#endif |
| 845 |
|
858 |
|
| 846 |
/* |
859 |
/* |
| 847 |
* Write the seed to stdout |
860 |
* Write the seed to stdout |
|
Lines 865-867
Link Here
|
| 865 |
|
878 |
|
| 866 |
return ret == bytes ? 0 : 1; |
879 |
return ret == bytes ? 0 : 1; |
| 867 |
} |
880 |
} |
|
|
881 |
|
| 882 |
#endif |