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