-
+ B98CF2FB49B284C7FFDA191D6E1A336E87BC9D5C302753C04E704DE455793BD9736D6318E1C314FC8CF97BAEBC830EAE998C35382AFB2810126C1CC9BD18BDCE
mpi/mpih-rshift.c
(0 . 0)(1 . 67)
10050 /* mpih-rshift.c - MPI helper functions
10051 * Copyright (C) 1994, 1996, 1998, 1999,
10052 * 2000, 2001 Free Software Foundation, Inc.
10053 *
10054 * This file is part of GNUPG
10055 *
10056 * GNUPG is free software; you can redistribute it and/or modify
10057 * it under the terms of the GNU General Public License as published by
10058 * the Free Software Foundation; either version 3 of the License, or
10059 * (at your option) any later version.
10060 *
10061 * GNUPG is distributed in the hope that it will be useful,
10062 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10063 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10064 * GNU General Public License for more details.
10065 *
10066 * You should have received a copy of the GNU General Public License
10067 * along with this program; if not, see <http://www.gnu.org/licenses/>.
10068 *
10069 * Note: This code is heavily based on the GNU MP Library.
10070 * Actually it's the same code with only minor changes in the
10071 * way the data is stored; this is to support the abstraction
10072 * of an optional secure memory allocation which may be used
10073 * to avoid revealing of sensitive data due to paging etc.
10074 * The GNU MP Library itself is published under the LGPL;
10075 * however I decided to publish this code under the plain GPL.
10076 */
10077
10078 #include <config.h>
10079 #include <stdio.h>
10080 #include <stdlib.h>
10081 #include "mpi-internal.h"
10082
10083
10084 /* Shift U (pointed to by UP and USIZE limbs long) CNT bits to the right
10085 * and store the USIZE least significant limbs of the result at WP.
10086 * The bits shifted out to the right are returned.
10087 *
10088 * Argument constraints:
10089 * 1. 0 < CNT < BITS_PER_MP_LIMB
10090 * 2. If the result is to be written over the input, WP must be <= UP.
10091 */
10092
10093 mpi_limb_t
10094 mpihelp_rshift( mpi_ptr_t wp, mpi_ptr_t up, mpi_size_t usize, unsigned cnt)
10095 {
10096 mpi_limb_t high_limb, low_limb;
10097 unsigned sh_1, sh_2;
10098 mpi_size_t i;
10099 mpi_limb_t retval;
10100
10101 sh_1 = cnt;
10102 wp -= 1;
10103 sh_2 = BITS_PER_MPI_LIMB - sh_1;
10104 high_limb = up[0];
10105 retval = high_limb << sh_2;
10106 low_limb = high_limb;
10107 for( i=1; i < usize; i++) {
10108 high_limb = up[i];
10109 wp[i] = (low_limb >> sh_1) | (high_limb << sh_2);
10110 low_limb = high_limb;
10111 }
10112 wp[i] = low_limb >> sh_1;
10113
10114 return retval;
10115 }
10116