-
+ 3222BFC241FA6104936CC585FDA392F220D88031FA0FDF460BB201A3AA7295E6D1DC75007BF53D2E501734D9FAAA31934EED944CE7452A6AA3AFCD3A333D3C13
mpi/mpih-lshift.c
(0 . 0)(1 . 68)
8100 /* mpihelp-lshift.c - MPI helper functions
8101 * Copyright (C) 1994, 1996, 1998, 2001 Free Software Foundation, Inc.
8102 *
8103 * This file is part of GnuPG.
8104 *
8105 * GnuPG is free software; you can redistribute it and/or modify
8106 * it under the terms of the GNU General Public License as published by
8107 * the Free Software Foundation; either version 3 of the License, or
8108 * (at your option) any later version.
8109 *
8110 * GnuPG is distributed in the hope that it will be useful,
8111 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8112 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8113 * GNU General Public License for more details.
8114 *
8115 * You should have received a copy of the GNU General Public License
8116 * along with this program; if not, see <http://www.gnu.org/licenses/>.
8117 *
8118 * Note: This code is heavily based on the GNU MP Library.
8119 * Actually it's the same code with only minor changes in the
8120 * way the data is stored; this is to support the abstraction
8121 * of an optional secure memory allocation which may be used
8122 * to avoid revealing of sensitive data due to paging etc.
8123 * The GNU MP Library itself is published under the LGPL;
8124 * however I decided to publish this code under the plain GPL.
8125 */
8126
8127 #include <config.h>
8128 #include <stdio.h>
8129 #include <stdlib.h>
8130 #include "mpi-internal.h"
8131
8132 /* Shift U (pointed to by UP and USIZE digits long) CNT bits to the left
8133 * and store the USIZE least significant digits of the result at WP.
8134 * Return the bits shifted out from the most significant digit.
8135 *
8136 * Argument constraints:
8137 * 1. 0 < CNT < BITS_PER_MP_LIMB
8138 * 2. If the result is to be written over the input, WP must be >= UP.
8139 */
8140
8141 mpi_limb_t
8142 mpihelp_lshift( mpi_ptr_t wp, mpi_ptr_t up, mpi_size_t usize,
8143 unsigned int cnt)
8144 {
8145 mpi_limb_t high_limb, low_limb;
8146 unsigned sh_1, sh_2;
8147 mpi_size_t i;
8148 mpi_limb_t retval;
8149
8150 sh_1 = cnt;
8151 wp += 1;
8152 sh_2 = BITS_PER_MPI_LIMB - sh_1;
8153 i = usize - 1;
8154 low_limb = up[i];
8155 retval = low_limb >> sh_2;
8156 high_limb = low_limb;
8157 while( --i >= 0 ) {
8158 low_limb = up[i];
8159 wp[i] = (high_limb << sh_1) | (low_limb >> sh_2);
8160 high_limb = low_limb;
8161 }
8162 wp[i] = high_limb << sh_1;
8163
8164 return retval;
8165 }
8166
8167