-
+ 683F47357B0F57E3DC50AEFC32BDCD8C20E7A9A4C3DC48D3BA9E5715E12836B6CE53B8DFF653BDB86CDD197DAAB9AF7532DEF5BB06D861BDF48F4DC705AC6AA4
mpi/mpih-mul3.c
(0 . 0)(1 . 66)
8305 /* mpihelp-mul_3.c - MPI helper functions
8306 * Copyright (C) 1994, 1996, 1997, 1998, 2001 Free Software Foundation, Inc.
8307 *
8308 * This file is part of GnuPG.
8309 *
8310 * GnuPG is free software; you can redistribute it and/or modify
8311 * it under the terms of the GNU General Public License as published by
8312 * the Free Software Foundation; either version 3 of the License, or
8313 * (at your option) any later version.
8314 *
8315 * GnuPG is distributed in the hope that it will be useful,
8316 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8317 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8318 * GNU General Public License for more details.
8319 *
8320 * You should have received a copy of the GNU General Public License
8321 * along with this program; if not, see <http://www.gnu.org/licenses/>.
8322 *
8323 * Note: This code is heavily based on the GNU MP Library.
8324 * Actually it's the same code with only minor changes in the
8325 * way the data is stored; this is to support the abstraction
8326 * of an optional secure memory allocation which may be used
8327 * to avoid revealing of sensitive data due to paging etc.
8328 * The GNU MP Library itself is published under the LGPL;
8329 * however I decided to publish this code under the plain GPL.
8330 */
8331
8332 #include <config.h>
8333 #include <stdio.h>
8334 #include <stdlib.h>
8335 #include "mpi-internal.h"
8336 #include "longlong.h"
8337
8338
8339 mpi_limb_t
8340 mpihelp_submul_1( mpi_ptr_t res_ptr, mpi_ptr_t s1_ptr,
8341 mpi_size_t s1_size, mpi_limb_t s2_limb)
8342 {
8343 mpi_limb_t cy_limb;
8344 mpi_size_t j;
8345 mpi_limb_t prod_high, prod_low;
8346 mpi_limb_t x;
8347
8348 /* The loop counter and index J goes from -SIZE to -1. This way
8349 * the loop becomes faster. */
8350 j = -s1_size;
8351 res_ptr -= j;
8352 s1_ptr -= j;
8353
8354 cy_limb = 0;
8355 do {
8356 umul_ppmm( prod_high, prod_low, s1_ptr[j], s2_limb);
8357
8358 prod_low += cy_limb;
8359 cy_limb = (prod_low < cy_limb?1:0) + prod_high;
8360
8361 x = res_ptr[j];
8362 prod_low = x - prod_low;
8363 cy_limb += prod_low > x?1:0;
8364 res_ptr[j] = prod_low;
8365 } while( ++j );
8366
8367 return cy_limb;
8368 }
8369
8370