Mercurial > dropbear
comparison random.c @ 320:08b69964e408 agent-client
propagate from branch 'au.asn.ucc.matt.dropbear' (head 138a11bc1e2babcd8b1182e6cb2a85d4e9404b11)
to branch 'au.asn.ucc.matt.dropbear.cli-agent' (head 12b2f59db65e7339d340e95ac67d6d9ddb193c2b)
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Tue, 06 Jun 2006 15:40:09 +0000 |
parents | 79bf1023cf11 36d21680a9d3 |
children | c1e9c81d1d27 |
comparison
equal
deleted
inserted
replaced
297:79bf1023cf11 | 320:08b69964e408 |
---|---|
29 | 29 |
30 static int donerandinit = 0; | 30 static int donerandinit = 0; |
31 | 31 |
32 /* this is used to generate unique output from the same hashpool */ | 32 /* this is used to generate unique output from the same hashpool */ |
33 static uint32_t counter = 0; | 33 static uint32_t counter = 0; |
34 #define MAX_COUNTER 1<<31 /* the max value for the counter, so it won't loop */ | 34 /* the max value for the counter, so it won't integer overflow */ |
35 #define MAX_COUNTER 1<<30 | |
35 | 36 |
36 static unsigned char hashpool[SHA1_HASH_SIZE]; | 37 static unsigned char hashpool[SHA1_HASH_SIZE]; |
37 | 38 |
38 #define INIT_SEED_SIZE 32 /* 256 bits */ | 39 #define INIT_SEED_SIZE 32 /* 256 bits */ |
39 | 40 |
127 unsigned char readbuf[INIT_SEED_SIZE]; | 128 unsigned char readbuf[INIT_SEED_SIZE]; |
128 | 129 |
129 hash_state hs; | 130 hash_state hs; |
130 | 131 |
131 /* initialise so that things won't warn about | 132 /* initialise so that things won't warn about |
132 * hashing an undefined buffer */ | 133 * hashing an undefined buffer */ |
133 if (!donerandinit) { | 134 if (!donerandinit) { |
134 m_burn(hashpool, sizeof(hashpool)); | 135 m_burn(hashpool, sizeof(hashpool)); |
135 } | 136 } |
136 | 137 |
137 /* get the seed data */ | 138 /* get the seed data */ |
150 /* hash the current random pool with some unique identifiers | 151 /* hash the current random pool with some unique identifiers |
151 * for this process and point-in-time. this is used to separate | 152 * for this process and point-in-time. this is used to separate |
152 * the random pools for fork()ed processes. */ | 153 * the random pools for fork()ed processes. */ |
153 void reseedrandom() { | 154 void reseedrandom() { |
154 | 155 |
155 pid_t pid; | 156 pid_t pid; |
156 struct timeval tv; | 157 hash_state hs; |
158 struct timeval tv; | |
157 | 159 |
158 if (!donerandinit) { | 160 if (!donerandinit) { |
159 dropbear_exit("seedrandom not done"); | 161 dropbear_exit("seedrandom not done"); |
160 } | 162 } |
161 | 163 |
162 pid = getpid(); | 164 pid = getpid(); |
163 gettimeofday(&tv, NULL); | 165 gettimeofday(&tv, NULL); |
164 | 166 |
165 hash_state hs; | |
166 unsigned char hash[SHA1_HASH_SIZE]; | |
167 sha1_init(&hs); | 167 sha1_init(&hs); |
168 sha1_process(&hs, (void*)hashpool, sizeof(hashpool)); | 168 sha1_process(&hs, (void*)hashpool, sizeof(hashpool)); |
169 sha1_process(&hs, (void*)&pid, sizeof(pid)); | 169 sha1_process(&hs, (void*)&pid, sizeof(pid)); |
170 sha1_process(&hs, (void*)&tv, sizeof(tv)); | 170 sha1_process(&hs, (void*)&tv, sizeof(tv)); |
171 sha1_done(&hs, hashpool); | 171 sha1_done(&hs, hashpool); |