-
+ 1F021E754F091EAC1AB7B46306B00849F7160CFA7CD0CC8A6481020B6D42CB12058CD12AC9E2B1D7F730688FBE2D876374EC9D5BB7A5F9D66A42CC9259CF2539mpi/mpih-sub1.c(0 . 0)(1 . 64)
10121 /* mpihelp-add_2.c - MPI helper functions
10122 * Copyright (C) 1994, 1996, 1997, 1998, 2001 Free Software Foundation, Inc.
10123 *
10124 * This file is part of GnuPG.
10125 *
10126 * GnuPG is free software; you can redistribute it and/or modify
10127 * it under the terms of the GNU General Public License as published by
10128 * the Free Software Foundation; either version 3 of the License, or
10129 * (at your option) any later version.
10130 *
10131 * GnuPG is distributed in the hope that it will be useful,
10132 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10133 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10134 * GNU General Public License for more details.
10135 *
10136 * You should have received a copy of the GNU General Public License
10137 * along with this program; if not, see <http://www.gnu.org/licenses/>.
10138 *
10139 * Note: This code is heavily based on the GNU MP Library.
10140 * Actually it's the same code with only minor changes in the
10141 * way the data is stored; this is to support the abstraction
10142 * of an optional secure memory allocation which may be used
10143 * to avoid revealing of sensitive data due to paging etc.
10144 * The GNU MP Library itself is published under the LGPL;
10145 * however I decided to publish this code under the plain GPL.
10146 */
10147
10148 #include <config.h>
10149 #include <stdio.h>
10150 #include <stdlib.h>
10151 #include "mpi-internal.h"
10152 #include "longlong.h"
10153
10154 mpi_limb_t
10155 mpihelp_sub_n( mpi_ptr_t res_ptr, mpi_ptr_t s1_ptr,
10156 mpi_ptr_t s2_ptr, mpi_size_t size)
10157 {
10158 mpi_limb_t x, y, cy;
10159 mpi_size_t j;
10160
10161 /* The loop counter and index J goes from -SIZE to -1. This way
10162 the loop becomes faster. */
10163 j = -size;
10164
10165 /* Offset the base pointers to compensate for the negative indices. */
10166 s1_ptr -= j;
10167 s2_ptr -= j;
10168 res_ptr -= j;
10169
10170 cy = 0;
10171 do {
10172 y = s2_ptr[j];
10173 x = s1_ptr[j];
10174 y += cy; /* add previous carry to subtrahend */
10175 cy = y < cy; /* get out carry from that addition */
10176 y = x - y; /* main subtract */
10177 cy += y > x; /* get out carry from the subtract, combine */
10178 res_ptr[j] = y;
10179 } while( ++j );
10180
10181 return cy;
10182 }
10183
10184