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

« back to all changes in this revision

Viewing changes to moduli.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: moduli.c,v 1.20 2007/02/24 03:30:11 ray Exp $ */
 
1
/* $OpenBSD: moduli.c,v 1.21 2008/06/26 09:19:40 djm Exp $ */
2
2
/*
3
3
 * Copyright 1994 Phil Karn <karn@qualcomm.com>
4
4
 * Copyright 1996-1998, 2003 William Allen Simpson <wsimpson@greendragon.com>
42
42
#include <sys/types.h>
43
43
 
44
44
#include <openssl/bn.h>
 
45
#include <openssl/dh.h>
45
46
 
46
47
#include <stdio.h>
47
48
#include <stdlib.h>
50
51
#include <time.h>
51
52
 
52
53
#include "xmalloc.h"
 
54
#include "dh.h"
53
55
#include "log.h"
54
56
 
55
57
/*
59
61
/* need line long enough for largest moduli plus headers */
60
62
#define QLINESIZE               (100+8192)
61
63
 
62
 
/* Type: decimal.
63
 
 * Specifies the internal structure of the prime modulus.
64
 
 */
65
 
#define QTYPE_UNKNOWN           (0)
66
 
#define QTYPE_UNSTRUCTURED      (1)
67
 
#define QTYPE_SAFE              (2)
68
 
#define QTYPE_SCHNORR           (3)
69
 
#define QTYPE_SOPHIE_GERMAIN    (4)
70
 
#define QTYPE_STRONG            (5)
71
 
 
72
 
/* Tests: decimal (bit field).
73
 
 * Specifies the methods used in checking for primality.
74
 
 * Usually, more than one test is used.
75
 
 */
76
 
#define QTEST_UNTESTED          (0x00)
77
 
#define QTEST_COMPOSITE         (0x01)
78
 
#define QTEST_SIEVE             (0x02)
79
 
#define QTEST_MILLER_RABIN      (0x04)
80
 
#define QTEST_JACOBI            (0x08)
81
 
#define QTEST_ELLIPTIC          (0x10)
82
 
 
83
64
/*
84
65
 * Size: decimal.
85
66
 * Specifies the number of the most significant bit (0 to M).
434
415
                        fatal("BN_set_word failed");
435
416
                if (BN_add(q, q, largebase) == 0)
436
417
                        fatal("BN_add failed");
437
 
                if (qfileout(out, QTYPE_SOPHIE_GERMAIN, QTEST_SIEVE,
438
 
                    largetries, (power - 1) /* MSB */, (0), q) == -1) {
 
418
                if (qfileout(out, MODULI_TYPE_SOPHIE_GERMAIN,
 
419
                    MODULI_TESTS_SIEVE, largetries,
 
420
                    (power - 1) /* MSB */, (0), q) == -1) {
439
421
                        ret = -1;
440
422
                        break;
441
423
                }
507
489
                /* tests */
508
490
                in_tests = strtoul(cp, &cp, 10);
509
491
 
510
 
                if (in_tests & QTEST_COMPOSITE) {
 
492
                if (in_tests & MODULI_TESTS_COMPOSITE) {
511
493
                        debug2("%10u: known composite", count_in);
512
494
                        continue;
513
495
                }
526
508
 
527
509
                /* modulus (hex) */
528
510
                switch (in_type) {
529
 
                case QTYPE_SOPHIE_GERMAIN:
 
511
                case MODULI_TYPE_SOPHIE_GERMAIN:
530
512
                        debug2("%10u: (%u) Sophie-Germain", count_in, in_type);
531
513
                        a = q;
532
514
                        if (BN_hex2bn(&a, cp) == 0)
539
521
                        in_size += 1;
540
522
                        generator_known = 0;
541
523
                        break;
542
 
                case QTYPE_UNSTRUCTURED:
543
 
                case QTYPE_SAFE:
544
 
                case QTYPE_SCHNORR:
545
 
                case QTYPE_STRONG:
546
 
                case QTYPE_UNKNOWN:
 
524
                case MODULI_TYPE_UNSTRUCTURED:
 
525
                case MODULI_TYPE_SAFE:
 
526
                case MODULI_TYPE_SCHNORR:
 
527
                case MODULI_TYPE_STRONG:
 
528
                case MODULI_TYPE_UNKNOWN:
547
529
                        debug2("%10u: (%u)", count_in, in_type);
548
530
                        a = p;
549
531
                        if (BN_hex2bn(&a, cp) == 0)
570
552
                        continue;
571
553
                }
572
554
 
573
 
                if (in_tests & QTEST_MILLER_RABIN)
 
555
                if (in_tests & MODULI_TESTS_MILLER_RABIN)
574
556
                        in_tries += trials;
575
557
                else
576
558
                        in_tries = trials;
644
626
                }
645
627
                debug("%10u: q is almost certainly prime", count_in);
646
628
 
647
 
                if (qfileout(out, QTYPE_SAFE, (in_tests | QTEST_MILLER_RABIN),
 
629
                if (qfileout(out, MODULI_TYPE_SAFE,
 
630
                    in_tests | MODULI_TESTS_MILLER_RABIN,
648
631
                    in_tries, in_size, generator_known, p)) {
649
632
                        res = -1;
650
633
                        break;