-
+ 1F021E754F091EAC1AB7B46306B00849F7160CFA7CD0CC8A6481020B6D42CB12058CD12AC9E2B1D7F730688FBE2D876374EC9D5BB7A5F9D66A42CC9259CF2539
mpi/mpih-sub1.c
(0 . 0)(1 . 64)
8977 /* mpihelp-add_2.c - MPI helper functions
8978 * Copyright (C) 1994, 1996, 1997, 1998, 2001 Free Software Foundation, Inc.
8979 *
8980 * This file is part of GnuPG.
8981 *
8982 * GnuPG is free software; you can redistribute it and/or modify
8983 * it under the terms of the GNU General Public License as published by
8984 * the Free Software Foundation; either version 3 of the License, or
8985 * (at your option) any later version.
8986 *
8987 * GnuPG is distributed in the hope that it will be useful,
8988 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8989 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8990 * GNU General Public License for more details.
8991 *
8992 * You should have received a copy of the GNU General Public License
8993 * along with this program; if not, see <http://www.gnu.org/licenses/>.
8994 *
8995 * Note: This code is heavily based on the GNU MP Library.
8996 * Actually it's the same code with only minor changes in the
8997 * way the data is stored; this is to support the abstraction
8998 * of an optional secure memory allocation which may be used
8999 * to avoid revealing of sensitive data due to paging etc.
9000 * The GNU MP Library itself is published under the LGPL;
9001 * however I decided to publish this code under the plain GPL.
9002 */
9003
9004 #include <config.h>
9005 #include <stdio.h>
9006 #include <stdlib.h>
9007 #include "mpi-internal.h"
9008 #include "longlong.h"
9009
9010 mpi_limb_t
9011 mpihelp_sub_n( mpi_ptr_t res_ptr, mpi_ptr_t s1_ptr,
9012 mpi_ptr_t s2_ptr, mpi_size_t size)
9013 {
9014 mpi_limb_t x, y, cy;
9015 mpi_size_t j;
9016
9017 /* The loop counter and index J goes from -SIZE to -1. This way
9018 the loop becomes faster. */
9019 j = -size;
9020
9021 /* Offset the base pointers to compensate for the negative indices. */
9022 s1_ptr -= j;
9023 s2_ptr -= j;
9024 res_ptr -= j;
9025
9026 cy = 0;
9027 do {
9028 y = s2_ptr[j];
9029 x = s1_ptr[j];
9030 y += cy; /* add previous carry to subtrahend */
9031 cy = y < cy; /* get out carry from that addition */
9032 y = x - y; /* main subtract */
9033 cy += y > x; /* get out carry from the subtract, combine */
9034 res_ptr[j] = y;
9035 } while( ++j );
9036
9037 return cy;
9038 }
9039
9040