// SPDX-License-Identifier: GPL-2.0-or-later1/* mpihelp-add_1.c - MPI helper functions2* Copyright (C) 1994, 1996, 1997, 1998,3* 2000 Free Software Foundation, Inc.4*5* This file is part of GnuPG.6*7* Note: This code is heavily based on the GNU MP Library.8* Actually it's the same code with only minor changes in the9* way the data is stored; this is to support the abstraction10* of an optional secure memory allocation which may be used11* to avoid revealing of sensitive data due to paging etc.12* The GNU MP Library itself is published under the LGPL;13* however I decided to publish this code under the plain GPL.14*/1516#include "mpi-internal.h"17#include "longlong.h"1819mpi_limb_t20mpihelp_add_n(mpi_ptr_t res_ptr, mpi_ptr_t s1_ptr,21mpi_ptr_t s2_ptr, mpi_size_t size)22{23mpi_limb_t x, y, cy;24mpi_size_t j;2526/* The loop counter and index J goes from -SIZE to -1. This way27the loop becomes faster. */28j = -size;2930/* Offset the base pointers to compensate for the negative indices. */31s1_ptr -= j;32s2_ptr -= j;33res_ptr -= j;3435cy = 0;36do {37y = s2_ptr[j];38x = s1_ptr[j];39y += cy; /* add previous carry to one addend */40cy = y < cy; /* get out carry from that addition */41y += x; /* add other addend */42cy += y < x; /* get out carry from that add, combine */43res_ptr[j] = y;44} while (++j);4546return cy;47}484950