-
+ 683F47357B0F57E3DC50AEFC32BDCD8C20E7A9A4C3DC48D3BA9E5715E12836B6CE53B8DFF653BDB86CDD197DAAB9AF7532DEF5BB06D861BDF48F4DC705AC6AA4
mpi/mpih-mul3.c
(0 . 0)(1 . 66)
9980 /* mpihelp-mul_3.c - MPI helper functions
9981 * Copyright (C) 1994, 1996, 1997, 1998, 2001 Free Software Foundation, Inc.
9982 *
9983 * This file is part of GnuPG.
9984 *
9985 * GnuPG is free software; you can redistribute it and/or modify
9986 * it under the terms of the GNU General Public License as published by
9987 * the Free Software Foundation; either version 3 of the License, or
9988 * (at your option) any later version.
9989 *
9990 * GnuPG is distributed in the hope that it will be useful,
9991 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9992 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9993 * GNU General Public License for more details.
9994 *
9995 * You should have received a copy of the GNU General Public License
9996 * along with this program; if not, see <http://www.gnu.org/licenses/>.
9997 *
9998 * Note: This code is heavily based on the GNU MP Library.
9999 * Actually it's the same code with only minor changes in the
10000 * way the data is stored; this is to support the abstraction
10001 * of an optional secure memory allocation which may be used
10002 * to avoid revealing of sensitive data due to paging etc.
10003 * The GNU MP Library itself is published under the LGPL;
10004 * however I decided to publish this code under the plain GPL.
10005 */
10006
10007 #include <config.h>
10008 #include <stdio.h>
10009 #include <stdlib.h>
10010 #include "mpi-internal.h"
10011 #include "longlong.h"
10012
10013
10014 mpi_limb_t
10015 mpihelp_submul_1( mpi_ptr_t res_ptr, mpi_ptr_t s1_ptr,
10016 mpi_size_t s1_size, mpi_limb_t s2_limb)
10017 {
10018 mpi_limb_t cy_limb;
10019 mpi_size_t j;
10020 mpi_limb_t prod_high, prod_low;
10021 mpi_limb_t x;
10022
10023 /* The loop counter and index J goes from -SIZE to -1. This way
10024 * the loop becomes faster. */
10025 j = -s1_size;
10026 res_ptr -= j;
10027 s1_ptr -= j;
10028
10029 cy_limb = 0;
10030 do {
10031 umul_ppmm( prod_high, prod_low, s1_ptr[j], s2_limb);
10032
10033 prod_low += cy_limb;
10034 cy_limb = (prod_low < cy_limb?1:0) + prod_high;
10035
10036 x = res_ptr[j];
10037 prod_low = x - prod_low;
10038 cy_limb += prod_low > x?1:0;
10039 res_ptr[j] = prod_low;
10040 } while( ++j );
10041
10042 return cy_limb;
10043 }
10044
10045