Mercurial > dropbear
comparison dbrandom.c @ 1511:5916af64acd4 fuzz
merge from main
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sat, 17 Feb 2018 19:29:51 +0800 |
parents | 798854f62430 2d450c1056e3 |
children | 2f64cb3d3007 |
comparison
equal
deleted
inserted
replaced
1457:32f990cc96b1 | 1511:5916af64acd4 |
---|---|
57 static int already_blocked = 0; | 57 static int already_blocked = 0; |
58 int readfd; | 58 int readfd; |
59 unsigned int readcount; | 59 unsigned int readcount; |
60 int ret = DROPBEAR_FAILURE; | 60 int ret = DROPBEAR_FAILURE; |
61 | 61 |
62 #ifdef DROPBEAR_PRNGD_SOCKET | 62 #if DROPBEAR_USE_PRNGD |
63 if (prngd) | 63 if (prngd) |
64 { | 64 { |
65 readfd = connect_unix(filename); | 65 readfd = connect_unix(filename); |
66 } | 66 } |
67 else | 67 else |
105 else | 105 else |
106 { | 106 { |
107 wantread = MIN(sizeof(readbuf), len-readcount); | 107 wantread = MIN(sizeof(readbuf), len-readcount); |
108 } | 108 } |
109 | 109 |
110 #ifdef DROPBEAR_PRNGD_SOCKET | 110 #if DROPBEAR_USE_PRNGD |
111 if (prngd) | 111 if (prngd) |
112 { | 112 { |
113 char egdcmd[2]; | 113 char egdcmd[2]; |
114 egdcmd[0] = 0x02; /* blocking read */ | 114 egdcmd[0] = 0x02; /* blocking read */ |
115 egdcmd[1] = (unsigned char)wantread; | 115 egdcmd[1] = (unsigned char)wantread; |
139 out: | 139 out: |
140 close(readfd); | 140 close(readfd); |
141 return ret; | 141 return ret; |
142 } | 142 } |
143 | 143 |
144 void addrandom(unsigned char * buf, unsigned int len) | 144 void addrandom(const unsigned char * buf, unsigned int len) |
145 { | 145 { |
146 hash_state hs; | 146 hash_state hs; |
147 | 147 |
148 #ifdef DROPBEAR_FUZZ | 148 #ifdef DROPBEAR_FUZZ |
149 if (fuzz.fuzzing || fuzz.recordf) { | 149 if (fuzz.fuzzing || fuzz.recordf) { |
166 #ifdef DROPBEAR_FUZZ | 166 #ifdef DROPBEAR_FUZZ |
167 if (fuzz.fuzzing || fuzz.recordf) { | 167 if (fuzz.fuzzing || fuzz.recordf) { |
168 return; | 168 return; |
169 } | 169 } |
170 #endif | 170 #endif |
171 #ifndef DROPBEAR_PRNGD_SOCKET | 171 #if !DROPBEAR_USE_PRNGD |
172 /* This is opportunistic, don't worry about failure */ | 172 /* This is opportunistic, don't worry about failure */ |
173 unsigned char buf[INIT_SEED_SIZE]; | 173 unsigned char buf[INIT_SEED_SIZE]; |
174 FILE *f = fopen(DROPBEAR_URANDOM_DEV, "w"); | 174 FILE *f = fopen(DROPBEAR_URANDOM_DEV, "w"); |
175 if (!f) { | 175 if (!f) { |
176 return; | 176 return; |
213 sha1_init(&hs); | 213 sha1_init(&hs); |
214 | 214 |
215 /* existing state */ | 215 /* existing state */ |
216 sha1_process(&hs, (void*)hashpool, sizeof(hashpool)); | 216 sha1_process(&hs, (void*)hashpool, sizeof(hashpool)); |
217 | 217 |
218 #ifdef DROPBEAR_PRNGD_SOCKET | 218 #if DROPBEAR_USE_PRNGD |
219 if (process_file(&hs, DROPBEAR_PRNGD_SOCKET, INIT_SEED_SIZE, 1) | 219 if (process_file(&hs, DROPBEAR_PRNGD_SOCKET, INIT_SEED_SIZE, 1) |
220 != DROPBEAR_SUCCESS) { | 220 != DROPBEAR_SUCCESS) { |
221 dropbear_exit("Failure reading random device %s", | 221 dropbear_exit("Failure reading random device %s", |
222 DROPBEAR_PRNGD_SOCKET); | 222 DROPBEAR_PRNGD_SOCKET); |
223 } | 223 } |