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

« back to all changes in this revision

Viewing changes to libtomcrypt/src/pk/dsa/dsa_verify_key.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:
6
6
 * The library is free for all purposes without any express
7
7
 * guarantee it works.
8
8
 *
9
 
 * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
 
9
 * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
10
10
 */
11
11
#include "tomcrypt.h"
12
12
 
25
25
*/
26
26
int dsa_verify_key(dsa_key *key, int *stat)
27
27
{
28
 
   mp_int tmp, tmp2;
 
28
   void   *tmp, *tmp2;
29
29
   int    res, err;
30
30
 
31
31
   LTC_ARGCHK(key  != NULL);
35
35
   *stat = 0;
36
36
 
37
37
   /* first make sure key->q and key->p are prime */
38
 
   if ((err = is_prime(&key->q, &res)) != CRYPT_OK) {
 
38
   if ((err = mp_prime_is_prime(key->q, 8, &res)) != CRYPT_OK) {
39
39
      return err;
40
40
   }
41
41
   if (res == 0) {
42
42
      return CRYPT_OK;
43
43
   }
44
44
 
45
 
 
46
 
   if ((err = is_prime(&key->p, &res)) != CRYPT_OK) {
 
45
   if ((err = mp_prime_is_prime(key->p, 8, &res)) != CRYPT_OK) {
47
46
      return err;
48
47
   }
49
48
   if (res == 0) {
51
50
   }
52
51
 
53
52
   /* now make sure that g is not -1, 0 or 1 and <p */
54
 
   if (mp_cmp_d(&key->g, 0) == MP_EQ || mp_cmp_d(&key->g, 1) == MP_EQ) {
 
53
   if (mp_cmp_d(key->g, 0) == LTC_MP_EQ || mp_cmp_d(key->g, 1) == LTC_MP_EQ) {
55
54
      return CRYPT_OK;
56
55
   }
57
 
   if ((err = mp_init_multi(&tmp, &tmp2, NULL)) != MP_OKAY)               { goto error; }
58
 
   if ((err = mp_sub_d(&key->p, 1, &tmp)) != MP_OKAY)                     { goto error; }
59
 
   if (mp_cmp(&tmp, &key->g) == MP_EQ || mp_cmp(&key->g, &key->p) != MP_LT) {
 
56
   if ((err = mp_init_multi(&tmp, &tmp2, NULL)) != CRYPT_OK)               { return err; }
 
57
   if ((err = mp_sub_d(key->p, 1, tmp)) != CRYPT_OK)                       { goto error; }
 
58
   if (mp_cmp(tmp, key->g) == LTC_MP_EQ || mp_cmp(key->g, key->p) != LTC_MP_LT) {
60
59
      err = CRYPT_OK;
61
 
      goto done;
 
60
      goto error;
62
61
   }
63
62
 
64
63
   /* 1 < y < p-1 */
65
 
   if (!(mp_cmp_d(&key->y, 1) == MP_GT && mp_cmp(&key->y, &tmp) == MP_LT)) {
 
64
   if (!(mp_cmp_d(key->y, 1) == LTC_MP_GT && mp_cmp(key->y, tmp) == LTC_MP_LT)) {
66
65
      err = CRYPT_OK;
67
 
      goto done;
 
66
      goto error;
68
67
   }
69
68
 
70
69
   /* now we have to make sure that g^q = 1, and that p-1/q gives 0 remainder */
71
 
   if ((err = mp_div(&tmp, &key->q, &tmp, &tmp2)) != MP_OKAY)             { goto error; }
72
 
   if (mp_iszero(&tmp2) != MP_YES) {
 
70
   if ((err = mp_div(tmp, key->q, tmp, tmp2)) != CRYPT_OK)             { goto error; }
 
71
   if (mp_iszero(tmp2) != LTC_MP_YES) {
73
72
      err = CRYPT_OK;
74
 
      goto done;
 
73
      goto error;
75
74
   }
76
75
 
77
 
   if ((err = mp_exptmod(&key->g, &key->q, &key->p, &tmp)) != MP_OKAY)    { goto error; }
78
 
   if (mp_cmp_d(&tmp, 1) != MP_EQ) {
 
76
   if ((err = mp_exptmod(key->g, key->q, key->p, tmp)) != CRYPT_OK)    { goto error; }
 
77
   if (mp_cmp_d(tmp, 1) != LTC_MP_EQ) {
79
78
      err = CRYPT_OK;
80
 
      goto done;
 
79
      goto error;
81
80
   }
82
81
 
83
82
   /* now we have to make sure that y^q = 1, this makes sure y \in g^x mod p */
84
 
   if ((err = mp_exptmod(&key->y, &key->q, &key->p, &tmp)) != MP_OKAY)       { goto error; }
85
 
   if (mp_cmp_d(&tmp, 1) != MP_EQ) {
 
83
   if ((err = mp_exptmod(key->y, key->q, key->p, tmp)) != CRYPT_OK)       { goto error; }
 
84
   if (mp_cmp_d(tmp, 1) != LTC_MP_EQ) {
86
85
      err = CRYPT_OK;
87
 
      goto done;
 
86
      goto error;
88
87
   }
89
88
 
90
89
   /* at this point we are out of tests ;-( */
91
90
   err   = CRYPT_OK;
92
91
   *stat = 1;
93
 
   goto done;
94
 
error: err = mpi_to_ltc_error(err);
95
 
done : mp_clear_multi(&tmp, &tmp2, NULL);
 
92
error: 
 
93
   mp_clear_multi(tmp, tmp2, NULL);
96
94
   return err;
97
95
}
98
96
#endif
99
97
 
100
98
/* $Source: /cvs/libtom/libtomcrypt/src/pk/dsa/dsa_verify_key.c,v $ */
101
 
/* $Revision: 1.3 $ */
102
 
/* $Date: 2005/05/05 14:35:59 $ */
 
99
/* $Revision: 1.6 $ */
 
100
/* $Date: 2006/12/04 03:18:43 $ */