// SPDX-License-Identifier: GPL-2.0-or-later1/* mpihelp-lshift.c - MPI helper functions2* Copyright (C) 1994, 1996, 1998, 2001 Free Software Foundation, Inc.3*4* This file is part of GnuPG.5*6* Note: This code is heavily based on the GNU MP Library.7* Actually it's the same code with only minor changes in the8* way the data is stored; this is to support the abstraction9* of an optional secure memory allocation which may be used10* to avoid revealing of sensitive data due to paging etc.11* The GNU MP Library itself is published under the LGPL;12* however I decided to publish this code under the plain GPL.13*/1415#include "mpi-internal.h"1617/* Shift U (pointed to by UP and USIZE digits long) CNT bits to the left18* and store the USIZE least significant digits of the result at WP.19* Return the bits shifted out from the most significant digit.20*21* Argument constraints:22* 1. 0 < CNT < BITS_PER_MP_LIMB23* 2. If the result is to be written over the input, WP must be >= UP.24*/2526mpi_limb_t27mpihelp_lshift(mpi_ptr_t wp, mpi_ptr_t up, mpi_size_t usize, unsigned int cnt)28{29mpi_limb_t high_limb, low_limb;30unsigned sh_1, sh_2;31mpi_size_t i;32mpi_limb_t retval;3334sh_1 = cnt;35wp += 1;36sh_2 = BITS_PER_MPI_LIMB - sh_1;37i = usize - 1;38low_limb = up[i];39retval = low_limb >> sh_2;40high_limb = low_limb;41while (--i >= 0) {42low_limb = up[i];43wp[i] = (high_limb << sh_1) | (low_limb >> sh_2);44high_limb = low_limb;45}46wp[i] = high_limb << sh_1;4748return retval;49}505152