-
+ B4153B7F9F829152CA1273195628566628CA4EED54792C61CD58EC4481F83CDED7E0A6DD4E1FB632B10B20314B28A209D2CF1F78A684A64F7A9002B6E00FB2B9
smg_comms/mpi/mpih-lshift.c
(0 . 0)(1 . 64)
6425 /* mpihelp-lshift.c - MPI helper functions
6426 * Modified by No Such Labs. (C) 2015. See README.
6427 *
6428 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
6429 * SHA256(gnupg-1.4.10.tar.gz):
6430 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
6431 * (C) 1994-2005 Free Software Foundation, Inc.
6432 *
6433 * This program is free software: you can redistribute it and/or modify
6434 * it under the terms of the GNU General Public License as published by
6435 * the Free Software Foundation, either version 3 of the License, or
6436 * (at your option) any later version.
6437 *
6438 * This program is distributed in the hope that it will be useful,
6439 * but WITHOUT ANY WARRANTY; without even the implied warranty of
6440 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6441 * GNU General Public License for more details.
6442 *
6443 * You should have received a copy of the GNU General Public License
6444 * along with this program. If not, see <http://www.gnu.org/licenses/>.
6445 */
6446
6447 #include <stdio.h>
6448 #include <stdlib.h>
6449
6450 #include "knobs.h"
6451 #include "mpi-internal.h"
6452
6453 /* Shift U (pointed to by UP and USIZE digits long) CNT bits to the left
6454 * and store the USIZE least significant digits of the result at WP.
6455 * Return the bits shifted out from the most significant digit.
6456 *
6457 * Argument constraints:
6458 * 1. 0 < CNT < BITS_PER_MP_LIMB
6459 * 2. If the result is to be written over the input, WP must be >= UP.
6460 */
6461
6462 mpi_limb_t
6463 mpihelp_lshift( mpi_ptr_t wp, mpi_ptr_t up, mpi_size_t usize,
6464 unsigned int cnt)
6465 {
6466 mpi_limb_t high_limb, low_limb;
6467 unsigned sh_1, sh_2;
6468 mpi_size_t i;
6469 mpi_limb_t retval;
6470
6471 sh_1 = cnt;
6472 wp += 1;
6473 sh_2 = BITS_PER_MPI_LIMB - sh_1;
6474 i = usize - 1;
6475 low_limb = up[i];
6476 retval = low_limb >> sh_2;
6477 high_limb = low_limb;
6478 while( --i >= 0 ) {
6479 low_limb = up[i];
6480 wp[i] = (high_limb << sh_1) | (low_limb >> sh_2);
6481 high_limb = low_limb;
6482 }
6483 wp[i] = high_limb << sh_1;
6484
6485 return retval;
6486 }
6487
6488