~ubuntu-branches/ubuntu/utopic/dropbear/utopic-proposed

« back to all changes in this revision

Viewing changes to libtommath/etc/mersenne.c

  • Committer: Bazaar Package Importer
  • Author(s): Matt Johnston
  • Date: 2005-12-08 19:20:21 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051208192021-nyp9rwnt77nsg6ty
Tags: 0.47-1
* New upstream release.
* SECURITY: Fix incorrect buffer sizing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
  }
19
19
 
20
20
  if ((res = mp_init (&u)) != MP_OKAY) {
21
 
    goto __N;
 
21
    goto LBL_N;
22
22
  }
23
23
 
24
24
  /* n = 2^s - 1 */
25
25
  if ((res = mp_2expt(&n, s)) != MP_OKAY) {
26
 
     goto __MU;
 
26
     goto LBL_MU;
27
27
  }
28
28
  if ((res = mp_sub_d (&n, 1, &n)) != MP_OKAY) {
29
 
    goto __MU;
 
29
    goto LBL_MU;
30
30
  }
31
31
 
32
32
  /* set u=4 */
36
36
  for (k = 1; k <= s - 2; k++) {
37
37
    /* u = u^2 - 2 mod n */
38
38
    if ((res = mp_sqr (&u, &u)) != MP_OKAY) {
39
 
      goto __MU;
 
39
      goto LBL_MU;
40
40
    }
41
41
    if ((res = mp_sub_d (&u, 2, &u)) != MP_OKAY) {
42
 
      goto __MU;
 
42
      goto LBL_MU;
43
43
    }
44
44
 
45
45
    /* make sure u is positive */
46
46
    while (u.sign == MP_NEG) {
47
47
      if ((res = mp_add (&u, &n, &u)) != MP_OKAY) {
48
 
         goto __MU;
 
48
         goto LBL_MU;
49
49
      }
50
50
    }
51
51
 
52
52
    /* reduce */
53
53
    if ((res = mp_reduce_2k (&u, &n, 1)) != MP_OKAY) {
54
 
      goto __MU;
 
54
      goto LBL_MU;
55
55
    }
56
56
  }
57
57
 
62
62
  }
63
63
 
64
64
  res = MP_OKAY;
65
 
__MU:mp_clear (&u);
66
 
__N:mp_clear (&n);
 
65
LBL_MU:mp_clear (&u);
 
66
LBL_N:mp_clear (&n);
67
67
  return res;
68
68
}
69
69