raw
ch1_mpi                 1 /* mpi-scan.c  -  MPI functions
ch1_mpi 2 * Modified by No Such Labs. (C) 2015. See README.
ch1_mpi 3 * Modified by S.MG 2017 (removed code that is not used by eucrypt and at the same time so ugly it needs rewrite anyway)
ch1_mpi 4 *
ch1_mpi 5 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
ch1_mpi 6 * SHA256(gnupg-1.4.10.tar.gz):
ch1_mpi 7 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
ch1_mpi 8 * (C) 1994-2005 Free Software Foundation, Inc.
ch1_mpi 9 *
ch1_mpi 10 * This program is free software: you can redistribute it and/or modify
ch1_mpi 11 * it under the terms of the GNU General Public License as published by
ch1_mpi 12 * the Free Software Foundation, either version 3 of the License, or
ch1_mpi 13 * (at your option) any later version.
ch1_mpi 14 *
ch1_mpi 15 * This program is distributed in the hope that it will be useful,
ch1_mpi 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ch1_mpi 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ch1_mpi 18 * GNU General Public License for more details.
ch1_mpi 19 *
ch1_mpi 20 * You should have received a copy of the GNU General Public License
ch1_mpi 21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
ch1_mpi 22 */
ch1_mpi 23
ch1_mpi 24 #include <stdio.h>
ch1_mpi 25 #include <stdlib.h>
ch1_mpi 26
ch1_mpi 27 #include "knobs.h"
ch1_mpi 28 #include "mpi-internal.h"
ch1_mpi 29 #include "longlong.h"
ch1_mpi 30
ch1_mpi 31
ch1_mpi 32 /****************
ch1_mpi 33 * Count the number of zerobits at the low end of A
ch1_mpi 34 * This is used currently by eucrypt's primality tests.
ch1_mpi 35 */
ch1_mpi 36 unsigned int
ch1_mpi 37 mpi_trailing_zeros( MPI a )
ch1_mpi 38 {
ch1_mpi 39 unsigned n, count = 0;
ch1_mpi 40
ch1_mpi 41 for(n=0; n < a->nlimbs; n++ ) {
ch1_mpi 42 if( a->d[n] ) {
ch1_mpi 43 unsigned nn;
ch1_mpi 44 mpi_limb_t alimb = a->d[n];
ch1_mpi 45
ch1_mpi 46 count_trailing_zeros( nn, alimb );
ch1_mpi 47 count += nn;
ch1_mpi 48 break;
ch1_mpi 49 }
ch1_mpi 50 count += BITS_PER_MPI_LIMB;
ch1_mpi 51 }
ch1_mpi 52 return count;
ch1_mpi 53
ch1_mpi 54 }
ch1_mpi 55
ch1_mpi 56