-
+ FB06EA790BD2B2C18013B3FB51F05A5C1577F45FDD67644E7745C3373FA26FA90DE8F30FD9221E978BA9676423ED1C4C27C0407F22A50E10F216AE9BBF4AC3F3
mpi/mpih-add1.c
(0 . 0)(1 . 64)
8573 /* mpihelp-add_1.c - MPI helper functions
8574 * Copyright (C) 1994, 1996, 1997, 1998,
8575 * 2000 Free Software Foundation, Inc.
8576 *
8577 * This file is part of GnuPG.
8578 *
8579 * GnuPG is free software; you can redistribute it and/or modify
8580 * it under the terms of the GNU General Public License as published by
8581 * the Free Software Foundation; either version 3 of the License, or
8582 * (at your option) any later version.
8583 *
8584 * GnuPG is distributed in the hope that it will be useful,
8585 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8586 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8587 * GNU General Public License for more details.
8588 *
8589 * You should have received a copy of the GNU General Public License
8590 * along with this program; if not, see <http://www.gnu.org/licenses/>.
8591 *
8592 * Note: This code is heavily based on the GNU MP Library.
8593 * Actually it's the same code with only minor changes in the
8594 * way the data is stored; this is to support the abstraction
8595 * of an optional secure memory allocation which may be used
8596 * to avoid revealing of sensitive data due to paging etc.
8597 * The GNU MP Library itself is published under the LGPL;
8598 * however I decided to publish this code under the plain GPL.
8599 */
8600
8601 #include <config.h>
8602 #include <stdio.h>
8603 #include <stdlib.h>
8604 #include "mpi-internal.h"
8605 #include "longlong.h"
8606
8607 mpi_limb_t
8608 mpihelp_add_n( mpi_ptr_t res_ptr, mpi_ptr_t s1_ptr,
8609 mpi_ptr_t s2_ptr, mpi_size_t size)
8610 {
8611 mpi_limb_t x, y, cy;
8612 mpi_size_t j;
8613
8614 /* The loop counter and index J goes from -SIZE to -1. This way
8615 the loop becomes faster. */
8616 j = -size;
8617
8618 /* Offset the base pointers to compensate for the negative indices. */
8619 s1_ptr -= j;
8620 s2_ptr -= j;
8621 res_ptr -= j;
8622
8623 cy = 0;
8624 do {
8625 y = s2_ptr[j];
8626 x = s1_ptr[j];
8627 y += cy; /* add previous carry to one addend */
8628 cy = y < cy; /* get out carry from that addition */
8629 y += x; /* add other addend */
8630 cy += y < x; /* get out carry from that add, combine */
8631 res_ptr[j] = y;
8632 } while( ++j );
8633
8634 return cy;
8635 }
8636