-
+ 88C8DFD8A7CBBC742FE8E01121C9166DC010BA16554277137ECE7642BB6C9D94183EA6D23F4118D2BCD7A2A31A399A22A7A264EA178C0CE0BD4A2D0BF18F149F
eucrypt/mpi/mpih-sub1.c
(0 . 0)(1 . 60)
6517 /* mpihelp-add_2.c - MPI helper functions
6518 * Modified by No Such Labs. (C) 2015. See README.
6519 *
6520 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
6521 * SHA256(gnupg-1.4.10.tar.gz):
6522 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
6523 * (C) 1994-2005 Free Software Foundation, Inc.
6524 *
6525 * This program is free software: you can redistribute it and/or modify
6526 * it under the terms of the GNU General Public License as published by
6527 * the Free Software Foundation, either version 3 of the License, or
6528 * (at your option) any later version.
6529 *
6530 * This program is distributed in the hope that it will be useful,
6531 * but WITHOUT ANY WARRANTY; without even the implied warranty of
6532 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6533 * GNU General Public License for more details.
6534 *
6535 * You should have received a copy of the GNU General Public License
6536 * along with this program. If not, see <http://www.gnu.org/licenses/>.
6537 */
6538
6539 #include <stdio.h>
6540 #include <stdlib.h>
6541
6542 #include "knobs.h"
6543 #include "mpi-internal.h"
6544 #include "longlong.h"
6545
6546 mpi_limb_t
6547 mpihelp_sub_n( mpi_ptr_t res_ptr, mpi_ptr_t s1_ptr,
6548 mpi_ptr_t s2_ptr, mpi_size_t size)
6549 {
6550 mpi_limb_t x, y, cy;
6551 mpi_size_t j;
6552
6553 /* The loop counter and index J goes from -SIZE to -1. This way
6554 the loop becomes faster. */
6555 j = -size;
6556
6557 /* Offset the base pointers to compensate for the negative indices. */
6558 s1_ptr -= j;
6559 s2_ptr -= j;
6560 res_ptr -= j;
6561
6562 cy = 0;
6563 do {
6564 y = s2_ptr[j];
6565 x = s1_ptr[j];
6566 y += cy; /* add previous carry to subtrahend */
6567 cy = y < cy; /* get out carry from that addition */
6568 y = x - y; /* main subtract */
6569 cy += y > x; /* get out carry from the subtract, combine */
6570 res_ptr[j] = y;
6571 } while( ++j );
6572
6573 return cy;
6574 }
6575
6576