-
+ FB51D6B55D5E9B7ADA61CE8C50C3958A5D8B38CD1673683437D572EF52469C428A68C2926739EEE75EF379DB77C713F4BD8506B53A7E259E2CE9516E23AC44EF
eucrypt/mpi/mpih-rshift.c
(0 . 0)(1 . 62)
6451 /* mpih-rshift.c - MPI helper functions
6452 * Modified by No Such Labs. (C) 2015. See README.
6453 *
6454 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
6455 * SHA256(gnupg-1.4.10.tar.gz):
6456 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
6457 * (C) 1994-2005 Free Software Foundation, Inc.
6458 *
6459 * This program is free software: you can redistribute it and/or modify
6460 * it under the terms of the GNU General Public License as published by
6461 * the Free Software Foundation, either version 3 of the License, or
6462 * (at your option) any later version.
6463 *
6464 * This program is distributed in the hope that it will be useful,
6465 * but WITHOUT ANY WARRANTY; without even the implied warranty of
6466 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6467 * GNU General Public License for more details.
6468 *
6469 * You should have received a copy of the GNU General Public License
6470 * along with this program. If not, see <http://www.gnu.org/licenses/>.
6471 */
6472
6473 #include <stdio.h>
6474 #include <stdlib.h>
6475
6476 #include "knobs.h"
6477 #include "mpi-internal.h"
6478
6479
6480 /* Shift U (pointed to by UP and USIZE limbs long) CNT bits to the right
6481 * and store the USIZE least significant limbs of the result at WP.
6482 * The bits shifted out to the right are returned.
6483 *
6484 * Argument constraints:
6485 * 1. 0 < CNT < BITS_PER_MP_LIMB
6486 * 2. If the result is to be written over the input, WP must be <= UP.
6487 */
6488
6489 mpi_limb_t
6490 mpihelp_rshift( mpi_ptr_t wp, mpi_ptr_t up, mpi_size_t usize, unsigned cnt)
6491 {
6492 mpi_limb_t high_limb, low_limb;
6493 unsigned sh_1, sh_2;
6494 mpi_size_t i;
6495 mpi_limb_t retval;
6496
6497 sh_1 = cnt;
6498 wp -= 1;
6499 sh_2 = BITS_PER_MPI_LIMB - sh_1;
6500 high_limb = up[0];
6501 retval = high_limb << sh_2;
6502 low_limb = high_limb;
6503 for( i=1; i < usize; i++) {
6504 high_limb = up[i];
6505 wp[i] = (low_limb >> sh_1) | (high_limb << sh_2);
6506 low_limb = high_limb;
6507 }
6508 wp[i] = low_limb >> sh_1;
6509
6510 return retval;
6511 }
6512