~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/lib/crypto/mpi/mpi-add.c

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /lib/crypto/mpi/mpi-add.c (Architecture mips) and /lib/crypto/mpi/mpi-add.c (Architecture sparc)


  1 /* mpi-add.c  -  MPI functions                      1 /* mpi-add.c  -  MPI functions
  2  * Copyright (C) 1994, 1996, 1998, 2001, 2002,      2  * Copyright (C) 1994, 1996, 1998, 2001, 2002,
  3  *               2003 Free Software Foundation      3  *               2003 Free Software Foundation, Inc.
  4  *                                                  4  *
  5  * This file is part of Libgcrypt.                  5  * This file is part of Libgcrypt.
  6  *                                                  6  *
  7  * Note: This code is heavily based on the GNU      7  * Note: This code is heavily based on the GNU MP Library.
  8  *       Actually it's the same code with only      8  *       Actually it's the same code with only minor changes in the
  9  *       way the data is stored; this is to su      9  *       way the data is stored; this is to support the abstraction
 10  *       of an optional secure memory allocati     10  *       of an optional secure memory allocation which may be used
 11  *       to avoid revealing of sensitive data      11  *       to avoid revealing of sensitive data due to paging etc.
 12  */                                                12  */
 13                                                    13 
 14 #include "mpi-internal.h"                          14 #include "mpi-internal.h"
 15                                                    15 
 16 int mpi_add(MPI w, MPI u, MPI v)                   16 int mpi_add(MPI w, MPI u, MPI v)
 17 {                                                  17 {
 18         mpi_ptr_t wp, up, vp;                      18         mpi_ptr_t wp, up, vp;
 19         mpi_size_t usize, vsize, wsize;            19         mpi_size_t usize, vsize, wsize;
 20         int usign, vsign, wsign;                   20         int usign, vsign, wsign;
 21         int err;                                   21         int err;
 22                                                    22 
 23         if (u->nlimbs < v->nlimbs) { /* Swap U     23         if (u->nlimbs < v->nlimbs) { /* Swap U and V. */
 24                 usize = v->nlimbs;                 24                 usize = v->nlimbs;
 25                 usign = v->sign;                   25                 usign = v->sign;
 26                 vsize = u->nlimbs;                 26                 vsize = u->nlimbs;
 27                 vsign = u->sign;                   27                 vsign = u->sign;
 28                 wsize = usize + 1;                 28                 wsize = usize + 1;
 29                 err = RESIZE_IF_NEEDED(w, wsiz     29                 err = RESIZE_IF_NEEDED(w, wsize);
 30                 if (err)                           30                 if (err)
 31                         return err;                31                         return err;
 32                 /* These must be after realloc     32                 /* These must be after realloc (u or v may be the same as w).  */
 33                 up = v->d;                         33                 up = v->d;
 34                 vp = u->d;                         34                 vp = u->d;
 35         } else {                                   35         } else {
 36                 usize = u->nlimbs;                 36                 usize = u->nlimbs;
 37                 usign = u->sign;                   37                 usign = u->sign;
 38                 vsize = v->nlimbs;                 38                 vsize = v->nlimbs;
 39                 vsign = v->sign;                   39                 vsign = v->sign;
 40                 wsize = usize + 1;                 40                 wsize = usize + 1;
 41                 err = RESIZE_IF_NEEDED(w, wsiz     41                 err = RESIZE_IF_NEEDED(w, wsize);
 42                 if (err)                           42                 if (err)
 43                         return err;                43                         return err;
 44                 /* These must be after realloc     44                 /* These must be after realloc (u or v may be the same as w).  */
 45                 up = u->d;                         45                 up = u->d;
 46                 vp = v->d;                         46                 vp = v->d;
 47         }                                          47         }
 48         wp = w->d;                                 48         wp = w->d;
 49         wsign = 0;                                 49         wsign = 0;
 50                                                    50 
 51         if (!vsize) {  /* simple */                51         if (!vsize) {  /* simple */
 52                 MPN_COPY(wp, up, usize);           52                 MPN_COPY(wp, up, usize);
 53                 wsize = usize;                     53                 wsize = usize;
 54                 wsign = usign;                     54                 wsign = usign;
 55         } else if (usign != vsign) { /* differ     55         } else if (usign != vsign) { /* different sign */
 56                 /* This test is right since US     56                 /* This test is right since USIZE >= VSIZE */
 57                 if (usize != vsize) {              57                 if (usize != vsize) {
 58                         mpihelp_sub(wp, up, us     58                         mpihelp_sub(wp, up, usize, vp, vsize);
 59                         wsize = usize;             59                         wsize = usize;
 60                         MPN_NORMALIZE(wp, wsiz     60                         MPN_NORMALIZE(wp, wsize);
 61                         wsign = usign;             61                         wsign = usign;
 62                 } else if (mpihelp_cmp(up, vp,     62                 } else if (mpihelp_cmp(up, vp, usize) < 0) {
 63                         mpihelp_sub_n(wp, vp,      63                         mpihelp_sub_n(wp, vp, up, usize);
 64                         wsize = usize;             64                         wsize = usize;
 65                         MPN_NORMALIZE(wp, wsiz     65                         MPN_NORMALIZE(wp, wsize);
 66                         if (!usign)                66                         if (!usign)
 67                                 wsign = 1;         67                                 wsign = 1;
 68                 } else {                           68                 } else {
 69                         mpihelp_sub_n(wp, up,      69                         mpihelp_sub_n(wp, up, vp, usize);
 70                         wsize = usize;             70                         wsize = usize;
 71                         MPN_NORMALIZE(wp, wsiz     71                         MPN_NORMALIZE(wp, wsize);
 72                         if (usign)                 72                         if (usign)
 73                                 wsign = 1;         73                                 wsign = 1;
 74                 }                                  74                 }
 75         } else { /* U and V have same sign. Ad     75         } else { /* U and V have same sign. Add them. */
 76                 mpi_limb_t cy = mpihelp_add(wp     76                 mpi_limb_t cy = mpihelp_add(wp, up, usize, vp, vsize);
 77                 wp[usize] = cy;                    77                 wp[usize] = cy;
 78                 wsize = usize + cy;                78                 wsize = usize + cy;
 79                 if (usign)                         79                 if (usign)
 80                         wsign = 1;                 80                         wsign = 1;
 81         }                                          81         }
 82                                                    82 
 83         w->nlimbs = wsize;                         83         w->nlimbs = wsize;
 84         w->sign = wsign;                           84         w->sign = wsign;
 85         return 0;                                  85         return 0;
 86 }                                                  86 }
 87 EXPORT_SYMBOL_GPL(mpi_add);                        87 EXPORT_SYMBOL_GPL(mpi_add);
 88                                                    88 
 89 int mpi_sub(MPI w, MPI u, MPI v)                   89 int mpi_sub(MPI w, MPI u, MPI v)
 90 {                                                  90 {
 91         int err;                                   91         int err;
 92         MPI vv;                                    92         MPI vv;
 93                                                    93 
 94         vv = mpi_copy(v);                          94         vv = mpi_copy(v);
 95         if (!vv)                                   95         if (!vv)
 96                 return -ENOMEM;                    96                 return -ENOMEM;
 97                                                    97 
 98         vv->sign = !vv->sign;                      98         vv->sign = !vv->sign;
 99         err = mpi_add(w, u, vv);                   99         err = mpi_add(w, u, vv);
100         mpi_free(vv);                             100         mpi_free(vv);
101                                                   101 
102         return err;                               102         return err;
103 }                                                 103 }
104 EXPORT_SYMBOL_GPL(mpi_sub);                       104 EXPORT_SYMBOL_GPL(mpi_sub);
105                                                   105 
106 int mpi_addm(MPI w, MPI u, MPI v, MPI m)          106 int mpi_addm(MPI w, MPI u, MPI v, MPI m)
107 {                                                 107 {
108         return mpi_add(w, u, v) ?:                108         return mpi_add(w, u, v) ?:
109                mpi_mod(w, w, m);                  109                mpi_mod(w, w, m);
110 }                                                 110 }
111 EXPORT_SYMBOL_GPL(mpi_addm);                      111 EXPORT_SYMBOL_GPL(mpi_addm);
112                                                   112 
113 int mpi_subm(MPI w, MPI u, MPI v, MPI m)          113 int mpi_subm(MPI w, MPI u, MPI v, MPI m)
114 {                                                 114 {
115         return mpi_sub(w, u, v) ?:                115         return mpi_sub(w, u, v) ?:
116                mpi_mod(w, w, m);                  116                mpi_mod(w, w, m);
117 }                                                 117 }
118 EXPORT_SYMBOL_GPL(mpi_subm);                      118 EXPORT_SYMBOL_GPL(mpi_subm);
119                                                   119 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php