| 1913 | | void seedRandom(const string& source) |
| 1914 | | { |
| 1915 | | L<<Logger::Warning<<"Reading random entropy from '"<<source<<"'"<<endl; |
| 1916 | | |
| 1917 | | int fd=open(source.c_str(), O_RDONLY); |
| 1918 | | if(fd < 0) { |
| 1919 | | L<<Logger::Error<<"Unable to open source of random '"<<source<<"': "<<stringerror()<<endl; |
| 1920 | | exit(EXIT_FAILURE); |
| 1921 | | } |
| 1922 | | char seed[16]; |
| 1923 | | int ret; |
| 1924 | | int pos=0; |
| 1925 | | while(pos!=sizeof(seed)) { |
| 1926 | | ret = read(fd, seed+pos, sizeof(seed)-pos); |
| 1927 | | if(ret < 0) { |
| 1928 | | L<<Logger::Error<<"Unable to read random seed from "<<source<<": "<<stringerror()<<endl; |
| 1929 | | close(fd); |
| 1930 | | exit(EXIT_FAILURE); |
| 1931 | | } |
| 1932 | | if(!ret) { |
| 1933 | | L<<Logger::Error<<"Unable to read random seed from "<<source<<": end of file"<<endl; |
| 1934 | | close(fd); |
| 1935 | | exit(EXIT_FAILURE); |
| 1936 | | } |
| 1937 | | pos+=ret; |
| 1938 | | } |
| 1939 | | close(fd); |
| 1940 | | dns_random_init(seed); |
| 1941 | | } |