raw
mpi-genesis             1 /* mpihelp-lshift.c  -	MPI helper functions
mpi_second_cut 2 * Modified by No Such Labs. (C) 2015. See README.
mpi-genesis 3 *
mpi_second_cut 4 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
mpi_second_cut 5 * SHA256(gnupg-1.4.10.tar.gz):
mpi_second_cut 6 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
mpi_second_cut 7 * (C) 1994-2005 Free Software Foundation, Inc.
mpi-genesis 8 *
mpi_second_cut 9 * This program is free software: you can redistribute it and/or modify
mpi-genesis 10 * it under the terms of the GNU General Public License as published by
mpi_second_cut 11 * the Free Software Foundation, either version 3 of the License, or
mpi-genesis 12 * (at your option) any later version.
mpi-genesis 13 *
mpi_second_cut 14 * This program is distributed in the hope that it will be useful,
mpi-genesis 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
mpi-genesis 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
mpi-genesis 17 * GNU General Public License for more details.
mpi-genesis 18 *
mpi-genesis 19 * You should have received a copy of the GNU General Public License
mpi_second_cut 20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
mpi-genesis 21 */
mpi-genesis 22
mpi-genesis 23 #include <stdio.h>
mpi-genesis 24 #include <stdlib.h>
mpi_second_cut 25
mpi_second_cut 26 #include "knobs.h"
mpi-genesis 27 #include "mpi-internal.h"
mpi-genesis 28
mpi-genesis 29 /* Shift U (pointed to by UP and USIZE digits long) CNT bits to the left
mpi-genesis 30 * and store the USIZE least significant digits of the result at WP.
mpi-genesis 31 * Return the bits shifted out from the most significant digit.
mpi-genesis 32 *
mpi-genesis 33 * Argument constraints:
mpi-genesis 34 * 1. 0 < CNT < BITS_PER_MP_LIMB
mpi-genesis 35 * 2. If the result is to be written over the input, WP must be >= UP.
mpi-genesis 36 */
mpi-genesis 37
mpi-genesis 38 mpi_limb_t
mpi-genesis 39 mpihelp_lshift( mpi_ptr_t wp, mpi_ptr_t up, mpi_size_t usize,
mpi-genesis 40 unsigned int cnt)
mpi-genesis 41 {
mpi-genesis 42 mpi_limb_t high_limb, low_limb;
mpi-genesis 43 unsigned sh_1, sh_2;
mpi-genesis 44 mpi_size_t i;
mpi-genesis 45 mpi_limb_t retval;
mpi-genesis 46
mpi-genesis 47 sh_1 = cnt;
mpi-genesis 48 wp += 1;
mpi-genesis 49 sh_2 = BITS_PER_MPI_LIMB - sh_1;
mpi-genesis 50 i = usize - 1;
mpi-genesis 51 low_limb = up[i];
mpi-genesis 52 retval = low_limb >> sh_2;
mpi-genesis 53 high_limb = low_limb;
mpi-genesis 54 while( --i >= 0 ) {
mpi-genesis 55 low_limb = up[i];
mpi-genesis 56 wp[i] = (high_limb << sh_1) | (low_limb >> sh_2);
mpi-genesis 57 high_limb = low_limb;
mpi-genesis 58 }
mpi-genesis 59 wp[i] = high_limb << sh_1;
mpi-genesis 60
mpi-genesis 61 return retval;
mpi-genesis 62 }
mpi-genesis 63
mpi-genesis 64