~ubuntu-branches/ubuntu/trusty/xulrunner/trusty

« back to all changes in this revision

Viewing changes to security/nss-fips/lib/freebl/mpi/mulsqr.c

  • Committer: Bazaar Package Importer
  • Author(s): Devid Antonio Filoni
  • Date: 2008-08-25 13:04:18 UTC
  • mfrom: (1.1.12 upstream)
  • Revision ID: james.westby@ubuntu.com-20080825130418-ck1i2ms384tzb9m0
Tags: 1.8.1.16+nobinonly-0ubuntu1
* New upstream release (taken from upstream CVS), LP: #254618.
* Fix MFSA 2008-35, MFSA 2008-34, MFSA 2008-33, MFSA 2008-32, MFSA 2008-31,
  MFSA 2008-30, MFSA 2008-29, MFSA 2008-28, MFSA 2008-27, MFSA 2008-25,
  MFSA 2008-24, MFSA 2008-23, MFSA 2008-22, MFSA 2008-21, MFSA 2008-26 also
  known as CVE-2008-2933, CVE-2008-2785, CVE-2008-2811, CVE-2008-2810,
  CVE-2008-2809, CVE-2008-2808, CVE-2008-2807, CVE-2008-2806, CVE-2008-2805,
  CVE-2008-2803, CVE-2008-2802, CVE-2008-2801, CVE-2008-2800, CVE-2008-2798.
* Drop 89_bz419350_attachment_306066 patch, merged upstream.
* Bump Standards-Version to 3.8.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Test whether to include squaring code given the current settings
 
3
 *
 
4
 * ***** BEGIN LICENSE BLOCK *****
 
5
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 
6
 *
 
7
 * The contents of this file are subject to the Mozilla Public License Version
 
8
 * 1.1 (the "License"); you may not use this file except in compliance with
 
9
 * the License. You may obtain a copy of the License at
 
10
 * http://www.mozilla.org/MPL/
 
11
 *
 
12
 * Software distributed under the License is distributed on an "AS IS" basis,
 
13
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 
14
 * for the specific language governing rights and limitations under the
 
15
 * License.
 
16
 *
 
17
 * The Original Code is the MPI Arbitrary Precision Integer Arithmetic library.
 
18
 *
 
19
 * The Initial Developer of the Original Code is
 
20
 * Michael J. Fromberger.
 
21
 * Portions created by the Initial Developer are Copyright (C) 1997
 
22
 * the Initial Developer. All Rights Reserved.
 
23
 *
 
24
 * Contributor(s):
 
25
 *
 
26
 * Alternatively, the contents of this file may be used under the terms of
 
27
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 
28
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 
29
 * in which case the provisions of the GPL or the LGPL are applicable instead
 
30
 * of those above. If you wish to allow use of your version of this file only
 
31
 * under the terms of either the GPL or the LGPL, and not to allow others to
 
32
 * use your version of this file under the terms of the MPL, indicate your
 
33
 * decision by deleting the provisions above and replace them with the notice
 
34
 * and other provisions required by the GPL or the LGPL. If you do not delete
 
35
 * the provisions above, a recipient may use your version of this file under
 
36
 * the terms of any one of the MPL, the GPL or the LGPL.
 
37
 *
 
38
 * ***** END LICENSE BLOCK ***** */
 
39
 
 
40
#include <stdio.h>
 
41
#include <stdlib.h>
 
42
#include <limits.h>
 
43
#include <time.h>
 
44
 
 
45
#define MP_SQUARE 1  /* make sure squaring code is included */
 
46
 
 
47
#include "mpi.h"
 
48
#include "mpprime.h"
 
49
 
 
50
int main(int argc, char *argv[])
 
51
{
 
52
  int           ntests, prec, ix;
 
53
  unsigned int  seed;
 
54
  clock_t       start, stop;
 
55
  double        multime, sqrtime;
 
56
  mp_int        a, c;
 
57
 
 
58
  seed = (unsigned int)time(NULL);
 
59
 
 
60
  if(argc < 3) {
 
61
    fprintf(stderr, "Usage: %s <ntests> <nbits>\n", argv[0]);
 
62
    return 1;
 
63
  }
 
64
 
 
65
  if((ntests = abs(atoi(argv[1]))) == 0) {
 
66
    fprintf(stderr, "%s: must request at least 1 test.\n", argv[0]);
 
67
    return 1;
 
68
  }
 
69
  if((prec = abs(atoi(argv[2]))) < CHAR_BIT) {
 
70
    fprintf(stderr, "%s: must request at least %d bits.\n", argv[0],
 
71
            CHAR_BIT);
 
72
    return 1;
 
73
  }
 
74
 
 
75
  prec = (prec + (DIGIT_BIT - 1)) / DIGIT_BIT;
 
76
 
 
77
  mp_init_size(&a, prec);
 
78
  mp_init_size(&c, 2 * prec);
 
79
 
 
80
  /* Test multiplication by self */
 
81
  srand(seed);
 
82
  start = clock();
 
83
  for(ix = 0; ix < ntests; ix++) {
 
84
    mpp_random_size(&a, prec);
 
85
    mp_mul(&a, &a, &c);
 
86
  }
 
87
  stop = clock();
 
88
 
 
89
  multime = (double)(stop - start) / CLOCKS_PER_SEC;
 
90
 
 
91
  /* Test squaring */
 
92
  srand(seed);
 
93
  start = clock();
 
94
  for(ix = 0; ix < ntests; ix++) {
 
95
    mpp_random_size(&a, prec);
 
96
    mp_sqr(&a, &c);
 
97
  }
 
98
  stop = clock();
 
99
 
 
100
  sqrtime = (double)(stop - start) / CLOCKS_PER_SEC;
 
101
 
 
102
  printf("Multiply: %.4f\n", multime);
 
103
  printf("Square:   %.4f\n", sqrtime);
 
104
  if(multime < sqrtime) {
 
105
    printf("Speedup:  %.1f%%\n", 100.0 * (1.0 - multime / sqrtime));
 
106
    printf("Prefer:   multiply\n");
 
107
  } else {
 
108
    printf("Speedup:  %.1f%%\n", 100.0 * (1.0 - sqrtime / multime));
 
109
    printf("Prefer:   square\n");
 
110
  }
 
111
 
 
112
  mp_clear(&a); mp_clear(&c);
 
113
  return 0;
 
114
 
 
115
}