-
+ FB06EA790BD2B2C18013B3FB51F05A5C1577F45FDD67644E7745C3373FA26FA90DE8F30FD9221E978BA9676423ED1C4C27C0407F22A50E10F216AE9BBF4AC3F3mpi/mpih-add1.c(0 . 0)(1 . 64)
7429 /* mpihelp-add_1.c - MPI helper functions
7430 * Copyright (C) 1994, 1996, 1997, 1998,
7431 * 2000 Free Software Foundation, Inc.
7432 *
7433 * This file is part of GnuPG.
7434 *
7435 * GnuPG is free software; you can redistribute it and/or modify
7436 * it under the terms of the GNU General Public License as published by
7437 * the Free Software Foundation; either version 3 of the License, or
7438 * (at your option) any later version.
7439 *
7440 * GnuPG is distributed in the hope that it will be useful,
7441 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7442 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7443 * GNU General Public License for more details.
7444 *
7445 * You should have received a copy of the GNU General Public License
7446 * along with this program; if not, see <http://www.gnu.org/licenses/>.
7447 *
7448 * Note: This code is heavily based on the GNU MP Library.
7449 * Actually it's the same code with only minor changes in the
7450 * way the data is stored; this is to support the abstraction
7451 * of an optional secure memory allocation which may be used
7452 * to avoid revealing of sensitive data due to paging etc.
7453 * The GNU MP Library itself is published under the LGPL;
7454 * however I decided to publish this code under the plain GPL.
7455 */
7456
7457 #include <config.h>
7458 #include <stdio.h>
7459 #include <stdlib.h>
7460 #include "mpi-internal.h"
7461 #include "longlong.h"
7462
7463 mpi_limb_t
7464 mpihelp_add_n( mpi_ptr_t res_ptr, mpi_ptr_t s1_ptr,
7465 mpi_ptr_t s2_ptr, mpi_size_t size)
7466 {
7467 mpi_limb_t x, y, cy;
7468 mpi_size_t j;
7469
7470 /* The loop counter and index J goes from -SIZE to -1. This way
7471 the loop becomes faster. */
7472 j = -size;
7473
7474 /* Offset the base pointers to compensate for the negative indices. */
7475 s1_ptr -= j;
7476 s2_ptr -= j;
7477 res_ptr -= j;
7478
7479 cy = 0;
7480 do {
7481 y = s2_ptr[j];
7482 x = s1_ptr[j];
7483 y += cy; /* add previous carry to one addend */
7484 cy = y < cy; /* get out carry from that addition */
7485 y += x; /* add other addend */
7486 cy += y < x; /* get out carry from that add, combine */
7487 res_ptr[j] = y;
7488 } while( ++j );
7489
7490 return cy;
7491 }
7492