~ubuntu-branches/ubuntu/lucid/openssh/lucid

« back to all changes in this revision

Viewing changes to dh.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson
  • Date: 2008-09-30 23:09:58 UTC
  • mfrom: (1.13.3 upstream) (29 hardy)
  • mto: This revision was merged to the branch mainline in revision 43.
  • Revision ID: james.westby@ubuntu.com-20080930230958-o6vsgn8c4mm959s0
Tags: 1:5.1p1-3
* Remove unnecessary ssh-vulnkey output in non-verbose mode when no
  compromised or unknown keys were found (closes: #496495).
* Configure with --disable-strip; dh_strip will deal with stripping
  binaries and will honour DEB_BUILD_OPTIONS (thanks, Bernhard R. Link;
  closes: #498681).
* Fix handling of zero-length server banners (thanks, Tomas Mraz; closes:
  #497026).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $OpenBSD: dh.c,v 1.44 2006/11/07 13:02:07 markus Exp $ */
 
1
/* $OpenBSD: dh.c,v 1.47 2008/06/26 09:19:39 djm Exp $ */
2
2
/*
3
3
 * Copyright (c) 2000 Niels Provos.  All rights reserved.
4
4
 *
46
46
        char *cp, *arg;
47
47
        char *strsize, *gen, *prime;
48
48
        const char *errstr = NULL;
 
49
        long long n;
49
50
 
50
51
        cp = line;
51
52
        if ((arg = strdelim(&cp)) == NULL)
62
63
        arg = strsep(&cp, " "); /* type */
63
64
        if (cp == NULL || *arg == '\0')
64
65
                goto fail;
 
66
        /* Ensure this is a safe prime */
 
67
        n = strtonum(arg, 0, 5, &errstr);
 
68
        if (errstr != NULL || n != MODULI_TYPE_SAFE)
 
69
                goto fail;
65
70
        arg = strsep(&cp, " "); /* tests */
66
71
        if (cp == NULL || *arg == '\0')
67
72
                goto fail;
 
73
        /* Ensure prime has been tested and is not composite */
 
74
        n = strtonum(arg, 0, 0x1f, &errstr);
 
75
        if (errstr != NULL ||
 
76
            (n & MODULI_TESTS_COMPOSITE) || !(n & ~MODULI_TESTS_COMPOSITE))
 
77
                goto fail;
68
78
        arg = strsep(&cp, " "); /* tries */
69
79
        if (cp == NULL || *arg == '\0')
70
80
                goto fail;
 
81
        n = strtonum(arg, 0, 1<<30, &errstr);
 
82
        if (errstr != NULL || n == 0)
 
83
                goto fail;
71
84
        strsize = strsep(&cp, " "); /* size */
72
85
        if (cp == NULL || *strsize == '\0' ||
73
86
            (dhg->size = (u_int)strtonum(strsize, 0, 64*1024, &errstr)) == 0 ||
153
166
        }
154
167
 
155
168
        linenum = 0;
156
 
        which = arc4random() % bestcount;
 
169
        which = arc4random_uniform(bestcount);
157
170
        while (fgets(line, sizeof(line), f)) {
158
171
                if (!parse_prime(linenum, line, &dhg))
159
172
                        continue;
185
198
        BIGNUM *tmp;
186
199
 
187
200
        if (dh_pub->neg) {
188
 
                logit("invalid public DH value: negativ");
 
201
                logit("invalid public DH value: negative");
189
202
                return 0;
190
203
        }
191
204
        if (BN_cmp(dh_pub, BN_value_one()) != 1) {      /* pub_exp <= 1 */
193
206
                return 0;
194
207
        }
195
208
 
196
 
        if ((tmp = BN_new()) == NULL)
197
 
                return (-1);
 
209
        if ((tmp = BN_new()) == NULL) {
 
210
                error("%s: BN_new failed", __func__);
 
211
                return 0;
 
212
        }
198
213
        if (!BN_sub(tmp, dh->p, BN_value_one()) ||
199
214
            BN_cmp(dh_pub, tmp) != -1) {                /* pub_exp > p-2 */
200
215
                BN_clear_free(tmp);