-
+ 3222BFC241FA6104936CC585FDA392F220D88031FA0FDF460BB201A3AA7295E6D1DC75007BF53D2E501734D9FAAA31934EED944CE7452A6AA3AFCD3A333D3C13
mpi/mpih-lshift.c
(0 . 0)(1 . 68)
9244 /* mpihelp-lshift.c - MPI helper functions
9245 * Copyright (C) 1994, 1996, 1998, 2001 Free Software Foundation, Inc.
9246 *
9247 * This file is part of GnuPG.
9248 *
9249 * GnuPG is free software; you can redistribute it and/or modify
9250 * it under the terms of the GNU General Public License as published by
9251 * the Free Software Foundation; either version 3 of the License, or
9252 * (at your option) any later version.
9253 *
9254 * GnuPG is distributed in the hope that it will be useful,
9255 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9256 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9257 * GNU General Public License for more details.
9258 *
9259 * You should have received a copy of the GNU General Public License
9260 * along with this program; if not, see <http://www.gnu.org/licenses/>.
9261 *
9262 * Note: This code is heavily based on the GNU MP Library.
9263 * Actually it's the same code with only minor changes in the
9264 * way the data is stored; this is to support the abstraction
9265 * of an optional secure memory allocation which may be used
9266 * to avoid revealing of sensitive data due to paging etc.
9267 * The GNU MP Library itself is published under the LGPL;
9268 * however I decided to publish this code under the plain GPL.
9269 */
9270
9271 #include <config.h>
9272 #include <stdio.h>
9273 #include <stdlib.h>
9274 #include "mpi-internal.h"
9275
9276 /* Shift U (pointed to by UP and USIZE digits long) CNT bits to the left
9277 * and store the USIZE least significant digits of the result at WP.
9278 * Return the bits shifted out from the most significant digit.
9279 *
9280 * Argument constraints:
9281 * 1. 0 < CNT < BITS_PER_MP_LIMB
9282 * 2. If the result is to be written over the input, WP must be >= UP.
9283 */
9284
9285 mpi_limb_t
9286 mpihelp_lshift( mpi_ptr_t wp, mpi_ptr_t up, mpi_size_t usize,
9287 unsigned int cnt)
9288 {
9289 mpi_limb_t high_limb, low_limb;
9290 unsigned sh_1, sh_2;
9291 mpi_size_t i;
9292 mpi_limb_t retval;
9293
9294 sh_1 = cnt;
9295 wp += 1;
9296 sh_2 = BITS_PER_MPI_LIMB - sh_1;
9297 i = usize - 1;
9298 low_limb = up[i];
9299 retval = low_limb >> sh_2;
9300 high_limb = low_limb;
9301 while( --i >= 0 ) {
9302 low_limb = up[i];
9303 wp[i] = (high_limb << sh_1) | (low_limb >> sh_2);
9304 high_limb = low_limb;
9305 }
9306 wp[i] = high_limb << sh_1;
9307
9308 return retval;
9309 }
9310
9311