~ubuntu-branches/ubuntu/precise/dropbear/precise

« back to all changes in this revision

Viewing changes to random.c

  • Committer: Bazaar Package Importer
  • Author(s): Gerrit Pape
  • Date: 2007-03-02 20:48:18 UTC
  • mfrom: (1.3.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20070302204818-ozmbou2sbyj7dus5
Tags: 0.49-1
* new upstream release, fixes
  * CVE-2007-1099: dropbear dbclient insufficient warning on hostkey
    mismatch (closes: #412899).
  * dbclient uses static "Password:" prompt instead of using the server's
    prompt (closes: #394996).
* debian/control: Suggests: openssh-client, not ssh (closes: #405686);
  Standards-Version: 3.7.2.2.
* debian/README.Debian: ssh -> openssh-server, openssh-client; remove
  'Replacing OpenSSH "sshd" with Dropbear' part, this is simply done by not
  installing the openssh-server package.
* debian/README.runit: runsvstat -> sv status.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
 
32
32
/* this is used to generate unique output from the same hashpool */
33
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
37
static unsigned char hashpool[SHA1_HASH_SIZE];
37
38
 
133
134
        hash_state hs;
134
135
 
135
136
        /* initialise so that things won't warn about
136
 
     * hashing an undefined buffer */
 
137
         * hashing an undefined buffer */
137
138
        if (!donerandinit) {
138
139
                m_burn(hashpool, sizeof(hashpool));
139
140
        }
156
157
 * the random pools for fork()ed processes. */
157
158
void reseedrandom() {
158
159
 
159
 
    pid_t pid;
160
 
    struct timeval tv;
 
160
        pid_t pid;
 
161
        hash_state hs;
 
162
        struct timeval tv;
161
163
 
162
164
        if (!donerandinit) {
163
165
                dropbear_exit("seedrandom not done");
164
166
        }
165
167
 
166
 
    pid = getpid();
167
 
    gettimeofday(&tv, NULL);
 
168
        pid = getpid();
 
169
        gettimeofday(&tv, NULL);
168
170
 
169
 
        hash_state hs;
170
 
        unsigned char hash[SHA1_HASH_SIZE];
171
171
        sha1_init(&hs);
172
172
        sha1_process(&hs, (void*)hashpool, sizeof(hashpool));
173
173
        sha1_process(&hs, (void*)&pid, sizeof(pid));
214
214
 
215
215
        unsigned char *randbuf = NULL;
216
216
        unsigned int len = 0;
217
 
        const char masks[] = {0xff, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f};
 
217
        const unsigned char masks[] = {0xff, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f};
218
218
 
219
219
        const int size_bits = mp_count_bits(max);
220
220
 
234
234
 
235
235
                /* keep regenerating until we get one satisfying
236
236
                 * 0 < rand < max    */
237
 
        } while ( ( (max != NULL) && (mp_cmp(rand, max) != MP_LT) )
238
 
                        || (mp_cmp_d(rand, 0) != MP_GT) );
 
237
        } while (mp_cmp(rand, max) != MP_LT);
239
238
        m_burn(randbuf, len);
240
239
        m_free(randbuf);
241
240
}