-
+ B5713900ED6F31370C3136B3BEBC4A96603A0F319D1E75ABD706219BD6FDD5C5105F9E33275DF06ABD1321552FFC342DCF41C15CC28873FAEE616A0D62974467
eucrypt/mpi/mpih-add1.c
(0 . 0)(1 . 59)
5014 /* mpihelp-add_1.c - MPI helper functions
5015 * Modified by No Such Labs. (C) 2015. See README.
5016 *
5017 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
5018 * SHA256(gnupg-1.4.10.tar.gz):
5019 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
5020 * (C) 1994-2005 Free Software Foundation, Inc.
5021 *
5022 * This program is free software: you can redistribute it and/or modify
5023 * it under the terms of the GNU General Public License as published by
5024 * the Free Software Foundation, either version 3 of the License, or
5025 * (at your option) any later version.
5026 *
5027 * This program is distributed in the hope that it will be useful,
5028 * but WITHOUT ANY WARRANTY; without even the implied warranty of
5029 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5030 * GNU General Public License for more details.
5031 *
5032 * You should have received a copy of the GNU General Public License
5033 * along with this program. If not, see <http://www.gnu.org/licenses/>.
5034 */
5035
5036 #include <stdio.h>
5037 #include <stdlib.h>
5038
5039 #include "knobs.h"
5040 #include "mpi-internal.h"
5041 #include "longlong.h"
5042
5043 mpi_limb_t
5044 mpihelp_add_n( mpi_ptr_t res_ptr, mpi_ptr_t s1_ptr,
5045 mpi_ptr_t s2_ptr, mpi_size_t size)
5046 {
5047 mpi_limb_t x, y, cy;
5048 mpi_size_t j;
5049
5050 /* The loop counter and index J goes from -SIZE to -1. This way
5051 the loop becomes faster. */
5052 j = -size;
5053
5054 /* Offset the base pointers to compensate for the negative indices. */
5055 s1_ptr -= j;
5056 s2_ptr -= j;
5057 res_ptr -= j;
5058
5059 cy = 0;
5060 do {
5061 y = s2_ptr[j];
5062 x = s1_ptr[j];
5063 y += cy; /* add previous carry to one addend */
5064 cy = y < cy; /* get out carry from that addition */
5065 y += x; /* add other addend */
5066 cy += y < x; /* get out carry from that add, combine */
5067 res_ptr[j] = y;
5068 } while( ++j );
5069
5070 return cy;
5071 }
5072