~ubuntu-branches/ubuntu/vivid/samba/vivid

« back to all changes in this revision

Viewing changes to source4/heimdal/lib/hcrypto/libtommath/bn_mp_exptmod.c

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2011-12-21 13:18:04 UTC
  • mfrom: (0.39.21 sid)
  • Revision ID: package-import@ubuntu.com-20111221131804-xtlr39wx6njehxxr
Tags: 2:3.6.1-3ubuntu1
* Merge from Debian testing.  Remaining changes:
  + debian/patches/VERSION.patch:
    - set SAMBA_VERSION_SUFFIX to Ubuntu.
  + debian/patches/error-trans.fix-276472:
    - Add the translation of Unix Error code -ENOTSUP to NT Error Code
    - NT_STATUS_NOT_SUPPORTED to prevent the Permission denied error.
  + debian/smb.conf:
    - add "(Samba, Ubuntu)" to server string.
    - comment out the default [homes] share, and add a comment about
      "valid users = %S" to show users how to restrict access to
      \\server\username to only username.
    - Set 'usershare allow guests', so that usershare admins are 
      allowed to create public shares in addition to authenticated
      ones.
    - add map to guest = Bad user, maps bad username to guest access.
  + debian/samba-common.config:
    - Do not change priority to high if dhclient3 is installed.
    - Use priority medium instead of high for the workgroup question.
  + debian/control:
    - Don't build against or suggest ctdb.
    - Add dependency on samba-common-bin to samba.
  + Add ufw integration:
    - Created debian/samba.ufw.profile
    - debian/rules, debian/samba.dirs, debian/samba.files: install
      profile
    - debian/control: have samba suggest ufw
  + Add apport hook:
    - Created debian/source_samba.py.
    - debian/rules, debian/samba.dirs, debian/samba-common-bin.files: install
  + Switch to upstart:
    - Add debian/samba.{nmbd,smbd}.upstart.
  + debian/samba.logrotate, debian/samba-common.dhcp, debian/samba.if-up:
    - Make them upstart compatible
  + debian/samba.postinst: 
    - Avoid scary pdbedit warnings on first import.
  + debian/samba-common.postinst: Add more informative error message for
    the case where smb.conf was manually deleted
  + debian/patches/fix-debuglevel-name-conflict.patch: don't use 'debug_level'
    as a global variable name in an NSS module 
  + Dropped:
    - debian/patches/error-trans.fix-276472
    - debian/patches/fix-debuglevel-name-conflict.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <tommath.h>
 
2
#ifdef BN_MP_EXPTMOD_C
 
3
/* LibTomMath, multiple-precision integer library -- Tom St Denis
 
4
 *
 
5
 * LibTomMath is a library that provides multiple-precision
 
6
 * integer arithmetic as well as number theoretic functionality.
 
7
 *
 
8
 * The library was designed directly after the MPI library by
 
9
 * Michael Fromberger but has been written from scratch with
 
10
 * additional optimizations in place.
 
11
 *
 
12
 * The library is free for all purposes without any express
 
13
 * guarantee it works.
 
14
 *
 
15
 * Tom St Denis, tomstdenis@gmail.com, http://libtom.org
 
16
 */
 
17
 
 
18
 
 
19
/* this is a shell function that calls either the normal or Montgomery
 
20
 * exptmod functions.  Originally the call to the montgomery code was
 
21
 * embedded in the normal function but that wasted alot of stack space
 
22
 * for nothing (since 99% of the time the Montgomery code would be called)
 
23
 */
 
24
int mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y)
 
25
{
 
26
  int dr;
 
27
 
 
28
  /* modulus P must be positive */
 
29
  if (P->sign == MP_NEG) {
 
30
     return MP_VAL;
 
31
  }
 
32
 
 
33
  /* if exponent X is negative we have to recurse */
 
34
  if (X->sign == MP_NEG) {
 
35
#ifdef BN_MP_INVMOD_C
 
36
     mp_int tmpG, tmpX;
 
37
     int err;
 
38
 
 
39
     /* first compute 1/G mod P */
 
40
     if ((err = mp_init(&tmpG)) != MP_OKAY) {
 
41
        return err;
 
42
     }
 
43
     if ((err = mp_invmod(G, P, &tmpG)) != MP_OKAY) {
 
44
        mp_clear(&tmpG);
 
45
        return err;
 
46
     }
 
47
 
 
48
     /* now get |X| */
 
49
     if ((err = mp_init(&tmpX)) != MP_OKAY) {
 
50
        mp_clear(&tmpG);
 
51
        return err;
 
52
     }
 
53
     if ((err = mp_abs(X, &tmpX)) != MP_OKAY) {
 
54
        mp_clear_multi(&tmpG, &tmpX, NULL);
 
55
        return err;
 
56
     }
 
57
 
 
58
     /* and now compute (1/G)**|X| instead of G**X [X < 0] */
 
59
     err = mp_exptmod(&tmpG, &tmpX, P, Y);
 
60
     mp_clear_multi(&tmpG, &tmpX, NULL);
 
61
     return err;
 
62
#else 
 
63
     /* no invmod */
 
64
     return MP_VAL;
 
65
#endif
 
66
  }
 
67
 
 
68
/* modified diminished radix reduction */
 
69
#if defined(BN_MP_REDUCE_IS_2K_L_C) && defined(BN_MP_REDUCE_2K_L_C) && defined(BN_S_MP_EXPTMOD_C)
 
70
  if (mp_reduce_is_2k_l(P) == MP_YES) {
 
71
     return s_mp_exptmod(G, X, P, Y, 1);
 
72
  }
 
73
#endif
 
74
 
 
75
#ifdef BN_MP_DR_IS_MODULUS_C
 
76
  /* is it a DR modulus? */
 
77
  dr = mp_dr_is_modulus(P);
 
78
#else
 
79
  /* default to no */
 
80
  dr = 0;
 
81
#endif
 
82
 
 
83
#ifdef BN_MP_REDUCE_IS_2K_C
 
84
  /* if not, is it a unrestricted DR modulus? */
 
85
  if (dr == 0) {
 
86
     dr = mp_reduce_is_2k(P) << 1;
 
87
  }
 
88
#endif
 
89
    
 
90
  /* if the modulus is odd or dr != 0 use the montgomery method */
 
91
#ifdef BN_MP_EXPTMOD_FAST_C
 
92
  if (mp_isodd (P) == 1 || dr !=  0) {
 
93
    return mp_exptmod_fast (G, X, P, Y, dr);
 
94
  } else {
 
95
#endif
 
96
#ifdef BN_S_MP_EXPTMOD_C
 
97
    /* otherwise use the generic Barrett reduction technique */
 
98
    return s_mp_exptmod (G, X, P, Y, 0);
 
99
#else
 
100
    /* no exptmod for evens */
 
101
    return MP_VAL;
 
102
#endif
 
103
#ifdef BN_MP_EXPTMOD_FAST_C
 
104
  }
 
105
#endif
 
106
}
 
107
 
 
108
#endif
 
109
 
 
110
/* $Source: /cvs/libtom/libtommath/bn_mp_exptmod.c,v $ */
 
111
/* $Revision: 1.5 $ */
 
112
/* $Date: 2006/12/28 01:25:13 $ */