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

« back to all changes in this revision

Viewing changes to libtommath/bn_mp_radix_size.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:
35
35
    return MP_VAL;
36
36
  }
37
37
 
 
38
  if (mp_iszero(a) == MP_YES) {
 
39
     *size = 2;
 
40
    return MP_OKAY;
 
41
  }
 
42
 
 
43
  /* digs is the digit count */
 
44
  digs = 0;
 
45
 
 
46
  /* if it's negative add one for the sign */
 
47
  if (a->sign == MP_NEG) {
 
48
    ++digs;
 
49
  }
 
50
 
38
51
  /* init a copy of the input */
39
52
  if ((res = mp_init_copy (&t, a)) != MP_OKAY) {
40
53
    return res;
41
54
  }
42
55
 
43
 
  /* digs is the digit count */
44
 
  digs = 0;
45
 
 
46
 
  /* if it's negative add one for the sign */
47
 
  if (t.sign == MP_NEG) {
48
 
    ++digs;
49
 
    t.sign = MP_ZPOS;
50
 
  }
 
56
  /* force temp to positive */
 
57
  t.sign = MP_ZPOS; 
51
58
 
52
59
  /* fetch out all of the digits */
53
 
  while (mp_iszero (&t) == 0) {
 
60
  while (mp_iszero (&t) == MP_NO) {
54
61
    if ((res = mp_div_d (&t, (mp_digit) radix, &t, &d)) != MP_OKAY) {
55
62
      mp_clear (&t);
56
63
      return res;