-
+ B4153B7F9F829152CA1273195628566628CA4EED54792C61CD58EC4481F83CDED7E0A6DD4E1FB632B10B20314B28A209D2CF1F78A684A64F7A9002B6E00FB2B9
eucrypt/mpi/mpih-lshift.c
(0 . 0)(1 . 64)
5669 /* mpihelp-lshift.c - MPI helper functions
5670 * Modified by No Such Labs. (C) 2015. See README.
5671 *
5672 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
5673 * SHA256(gnupg-1.4.10.tar.gz):
5674 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
5675 * (C) 1994-2005 Free Software Foundation, Inc.
5676 *
5677 * This program is free software: you can redistribute it and/or modify
5678 * it under the terms of the GNU General Public License as published by
5679 * the Free Software Foundation, either version 3 of the License, or
5680 * (at your option) any later version.
5681 *
5682 * This program is distributed in the hope that it will be useful,
5683 * but WITHOUT ANY WARRANTY; without even the implied warranty of
5684 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5685 * GNU General Public License for more details.
5686 *
5687 * You should have received a copy of the GNU General Public License
5688 * along with this program. If not, see <http://www.gnu.org/licenses/>.
5689 */
5690
5691 #include <stdio.h>
5692 #include <stdlib.h>
5693
5694 #include "knobs.h"
5695 #include "mpi-internal.h"
5696
5697 /* Shift U (pointed to by UP and USIZE digits long) CNT bits to the left
5698 * and store the USIZE least significant digits of the result at WP.
5699 * Return the bits shifted out from the most significant digit.
5700 *
5701 * Argument constraints:
5702 * 1. 0 < CNT < BITS_PER_MP_LIMB
5703 * 2. If the result is to be written over the input, WP must be >= UP.
5704 */
5705
5706 mpi_limb_t
5707 mpihelp_lshift( mpi_ptr_t wp, mpi_ptr_t up, mpi_size_t usize,
5708 unsigned int cnt)
5709 {
5710 mpi_limb_t high_limb, low_limb;
5711 unsigned sh_1, sh_2;
5712 mpi_size_t i;
5713 mpi_limb_t retval;
5714
5715 sh_1 = cnt;
5716 wp += 1;
5717 sh_2 = BITS_PER_MPI_LIMB - sh_1;
5718 i = usize - 1;
5719 low_limb = up[i];
5720 retval = low_limb >> sh_2;
5721 high_limb = low_limb;
5722 while( --i >= 0 ) {
5723 low_limb = up[i];
5724 wp[i] = (high_limb << sh_1) | (low_limb >> sh_2);
5725 high_limb = low_limb;
5726 }
5727 wp[i] = high_limb << sh_1;
5728
5729 return retval;
5730 }
5731
5732