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

« back to all changes in this revision

Viewing changes to security/nss-fips/lib/freebl/mpi/utils/invmod.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
 *  invmod.c
 
3
 *
 
4
 *  Compute modular inverses
 
5
 *
 
6
 * ***** BEGIN LICENSE BLOCK *****
 
7
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 
8
 *
 
9
 * The contents of this file are subject to the Mozilla Public License Version
 
10
 * 1.1 (the "License"); you may not use this file except in compliance with
 
11
 * the License. You may obtain a copy of the License at
 
12
 * http://www.mozilla.org/MPL/
 
13
 *
 
14
 * Software distributed under the License is distributed on an "AS IS" basis,
 
15
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 
16
 * for the specific language governing rights and limitations under the
 
17
 * License.
 
18
 *
 
19
 * The Original Code is the MPI Arbitrary Precision Integer Arithmetic library.
 
20
 *
 
21
 * The Initial Developer of the Original Code is
 
22
 * Michael J. Fromberger.
 
23
 * Portions created by the Initial Developer are Copyright (C) 1997
 
24
 * the Initial Developer. All Rights Reserved.
 
25
 *
 
26
 * Contributor(s):
 
27
 *
 
28
 * Alternatively, the contents of this file may be used under the terms of
 
29
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 
30
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 
31
 * in which case the provisions of the GPL or the LGPL are applicable instead
 
32
 * of those above. If you wish to allow use of your version of this file only
 
33
 * under the terms of either the GPL or the LGPL, and not to allow others to
 
34
 * use your version of this file under the terms of the MPL, indicate your
 
35
 * decision by deleting the provisions above and replace them with the notice
 
36
 * and other provisions required by the GPL or the LGPL. If you do not delete
 
37
 * the provisions above, a recipient may use your version of this file under
 
38
 * the terms of any one of the MPL, the GPL or the LGPL.
 
39
 *
 
40
 * ***** END LICENSE BLOCK ***** */
 
41
/* $Id: invmod.c,v 1.3 2004/04/27 23:04:37 gerv%gerv.net Exp $ */
 
42
 
 
43
#include <stdio.h>
 
44
#include <stdlib.h>
 
45
 
 
46
#include "mpi.h"
 
47
 
 
48
int main(int argc, char *argv[])
 
49
{
 
50
  mp_int    a, m;
 
51
  mp_err    res;
 
52
  char     *buf;
 
53
  int       len, out = 0;
 
54
 
 
55
  if(argc < 3) {
 
56
    fprintf(stderr, "Usage: %s <a> <m>\n", argv[0]);
 
57
    return 1;
 
58
  }
 
59
 
 
60
  mp_init(&a); mp_init(&m);
 
61
  mp_read_radix(&a, argv[1], 10);
 
62
  mp_read_radix(&m, argv[2], 10);
 
63
 
 
64
  if(mp_cmp(&a, &m) > 0)
 
65
    mp_mod(&a, &m, &a);
 
66
 
 
67
  switch((res = mp_invmod(&a, &m, &a))) {
 
68
  case MP_OKAY:
 
69
    len = mp_radix_size(&a, 10);
 
70
    buf = malloc(len);
 
71
 
 
72
    mp_toradix(&a, buf, 10);
 
73
    printf("%s\n", buf);
 
74
    free(buf);
 
75
    break;
 
76
 
 
77
  case MP_UNDEF:
 
78
    printf("No inverse\n");
 
79
    out = 1;
 
80
    break;
 
81
 
 
82
  default:
 
83
    printf("error: %s (%d)\n", mp_strerror(res), res);
 
84
    out = 2;
 
85
    break;
 
86
  }
 
87
 
 
88
  mp_clear(&a);
 
89
  mp_clear(&m);
 
90
 
 
91
  return out;
 
92
}