~ubuntu-branches/ubuntu/utopic/clamav/utopic-security

« back to all changes in this revision

Viewing changes to libclamav/tomsfastmath/mont/fp_montgomery_calc_normalization.c

  • Committer: Package Import Robot
  • Author(s): Scott Kitterman
  • Date: 2014-02-01 11:06:17 UTC
  • mfrom: (0.35.37 sid)
  • Revision ID: package-import@ubuntu.com-20140201110617-33h2xxk09dep0ui4
Tags: 0.98.1+dfsg-1ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - Drop build-dep on electric-fence (in Universe)
  - Add apparmor profiles for clamd and freshclam along with maintainer
    script changes
  - Add autopkgtest

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* TomsFastMath, a fast ISO C bignum library.
 
2
 * 
 
3
 * This project is meant to fill in where LibTomMath
 
4
 * falls short.  That is speed ;-)
 
5
 *
 
6
 * This project is public domain and free for all purposes.
 
7
 * 
 
8
 * Tom St Denis, tomstdenis@gmail.com
 
9
 */
 
10
#include "bignum_fast.h"
 
11
 
 
12
/* computes a = B**n mod b without division or multiplication useful for
 
13
 * normalizing numbers in a Montgomery system.
 
14
 */
 
15
void fp_montgomery_calc_normalization(fp_int *a, fp_int *b)
 
16
{
 
17
  int     x, bits;
 
18
 
 
19
  /* how many bits of last digit does b use */
 
20
  bits = fp_count_bits (b) % DIGIT_BIT;
 
21
  if (!bits) bits = DIGIT_BIT;
 
22
 
 
23
  /* compute A = B^(n-1) * 2^(bits-1) */
 
24
  if (b->used > 1) {
 
25
     fp_2expt (a, (b->used - 1) * DIGIT_BIT + bits - 1);
 
26
  } else {
 
27
     fp_set(a, 1);
 
28
     bits = 1;
 
29
  }
 
30
 
 
31
  /* now compute C = A * B mod b */
 
32
  for (x = bits - 1; x < (int)DIGIT_BIT; x++) {
 
33
    fp_mul_2 (a, a);
 
34
    if (fp_cmp_mag (a, b) != FP_LT) {
 
35
      s_fp_sub (a, b, a);
 
36
    }
 
37
  }
 
38
}
 
39
 
 
40
 
 
41
/* $Source: /cvs/libtom/tomsfastmath/src/mont/fp_montgomery_calc_normalization.c,v $ */
 
42
/* $Revision: 1.1 $ */
 
43
/* $Date: 2006/12/31 21:25:53 $ */