-
+ B98CF2FB49B284C7FFDA191D6E1A336E87BC9D5C302753C04E704DE455793BD9736D6318E1C314FC8CF97BAEBC830EAE998C35382AFB2810126C1CC9BD18BDCE
mpi/mpih-rshift.c
(0 . 0)(1 . 67)
8906 /* mpih-rshift.c - MPI helper functions
8907 * Copyright (C) 1994, 1996, 1998, 1999,
8908 * 2000, 2001 Free Software Foundation, Inc.
8909 *
8910 * This file is part of GNUPG
8911 *
8912 * GNUPG is free software; you can redistribute it and/or modify
8913 * it under the terms of the GNU General Public License as published by
8914 * the Free Software Foundation; either version 3 of the License, or
8915 * (at your option) any later version.
8916 *
8917 * GNUPG is distributed in the hope that it will be useful,
8918 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8919 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8920 * GNU General Public License for more details.
8921 *
8922 * You should have received a copy of the GNU General Public License
8923 * along with this program; if not, see <http://www.gnu.org/licenses/>.
8924 *
8925 * Note: This code is heavily based on the GNU MP Library.
8926 * Actually it's the same code with only minor changes in the
8927 * way the data is stored; this is to support the abstraction
8928 * of an optional secure memory allocation which may be used
8929 * to avoid revealing of sensitive data due to paging etc.
8930 * The GNU MP Library itself is published under the LGPL;
8931 * however I decided to publish this code under the plain GPL.
8932 */
8933
8934 #include <config.h>
8935 #include <stdio.h>
8936 #include <stdlib.h>
8937 #include "mpi-internal.h"
8938
8939
8940 /* Shift U (pointed to by UP and USIZE limbs long) CNT bits to the right
8941 * and store the USIZE least significant limbs of the result at WP.
8942 * The bits shifted out to the right are returned.
8943 *
8944 * Argument constraints:
8945 * 1. 0 < CNT < BITS_PER_MP_LIMB
8946 * 2. If the result is to be written over the input, WP must be <= UP.
8947 */
8948
8949 mpi_limb_t
8950 mpihelp_rshift( mpi_ptr_t wp, mpi_ptr_t up, mpi_size_t usize, unsigned cnt)
8951 {
8952 mpi_limb_t high_limb, low_limb;
8953 unsigned sh_1, sh_2;
8954 mpi_size_t i;
8955 mpi_limb_t retval;
8956
8957 sh_1 = cnt;
8958 wp -= 1;
8959 sh_2 = BITS_PER_MPI_LIMB - sh_1;
8960 high_limb = up[0];
8961 retval = high_limb << sh_2;
8962 low_limb = high_limb;
8963 for( i=1; i < usize; i++) {
8964 high_limb = up[i];
8965 wp[i] = (low_limb >> sh_1) | (high_limb << sh_2);
8966 low_limb = high_limb;
8967 }
8968 wp[i] = low_limb >> sh_1;
8969
8970 return retval;
8971 }
8972