-
+ FB51D6B55D5E9B7ADA61CE8C50C3958A5D8B38CD1673683437D572EF52469C428A68C2926739EEE75EF379DB77C713F4BD8506B53A7E259E2CE9516E23AC44EF
smg_comms/mpi/mpih-rshift.c
(0 . 0)(1 . 62)
7207 /* mpih-rshift.c - MPI helper functions
7208 * Modified by No Such Labs. (C) 2015. See README.
7209 *
7210 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
7211 * SHA256(gnupg-1.4.10.tar.gz):
7212 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
7213 * (C) 1994-2005 Free Software Foundation, Inc.
7214 *
7215 * This program is free software: you can redistribute it and/or modify
7216 * it under the terms of the GNU General Public License as published by
7217 * the Free Software Foundation, either version 3 of the License, or
7218 * (at your option) any later version.
7219 *
7220 * This program is distributed in the hope that it will be useful,
7221 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7222 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7223 * GNU General Public License for more details.
7224 *
7225 * You should have received a copy of the GNU General Public License
7226 * along with this program. If not, see <http://www.gnu.org/licenses/>.
7227 */
7228
7229 #include <stdio.h>
7230 #include <stdlib.h>
7231
7232 #include "knobs.h"
7233 #include "mpi-internal.h"
7234
7235
7236 /* Shift U (pointed to by UP and USIZE limbs long) CNT bits to the right
7237 * and store the USIZE least significant limbs of the result at WP.
7238 * The bits shifted out to the right are returned.
7239 *
7240 * Argument constraints:
7241 * 1. 0 < CNT < BITS_PER_MP_LIMB
7242 * 2. If the result is to be written over the input, WP must be <= UP.
7243 */
7244
7245 mpi_limb_t
7246 mpihelp_rshift( mpi_ptr_t wp, mpi_ptr_t up, mpi_size_t usize, unsigned cnt)
7247 {
7248 mpi_limb_t high_limb, low_limb;
7249 unsigned sh_1, sh_2;
7250 mpi_size_t i;
7251 mpi_limb_t retval;
7252
7253 sh_1 = cnt;
7254 wp -= 1;
7255 sh_2 = BITS_PER_MPI_LIMB - sh_1;
7256 high_limb = up[0];
7257 retval = high_limb << sh_2;
7258 low_limb = high_limb;
7259 for( i=1; i < usize; i++) {
7260 high_limb = up[i];
7261 wp[i] = (low_limb >> sh_1) | (high_limb << sh_2);
7262 low_limb = high_limb;
7263 }
7264 wp[i] = low_limb >> sh_1;
7265
7266 return retval;
7267 }
7268