-
+ 9225D6FAA31311EA2857E6C9A8AD497846F41ECA0BF07B0EBC7601B05251AF751E68226CE7BB6B9F261FB182A5BE9BB1A05AEE4F222764D2F9CA28BFC59CFA99eucrypt/mpi/mpi-cmp.c(0 . 0)(1 . 77)
3209 /* mpi-cmp.c  -  MPI functions
3210  * Modified by No Such Labs. (C) 2015. See README.
3211  *
3212  * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
3213  * SHA256(gnupg-1.4.10.tar.gz):
3214  *        0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
3215  * (C) 1994-2005 Free Software Foundation, Inc.
3216  *
3217  * This program is free software: you can redistribute it and/or modify
3218  * it under the terms of the GNU General Public License as published by
3219  * the Free Software Foundation, either version 3 of the License, or
3220  * (at your option) any later version.
3221  *
3222  * This program is distributed in the hope that it will be useful,
3223  * but WITHOUT ANY WARRANTY; without even the implied warranty of
3224  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
3225  * GNU General Public License for more details.
3226  *
3227  * You should have received a copy of the GNU General Public License
3228  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
3229  */
3230 
3231 #include <stdio.h>
3232 #include <stdlib.h>
3233 
3234 #include "knobs.h"
3235 #include "mpi-internal.h"
3236 
3237 int
3238 mpi_cmp_ui( MPI u, unsigned long v )
3239 {
3240     mpi_limb_t limb = v;
3241 
3242     mpi_normalize( u );
3243     if( !u->nlimbs && !limb )
3244 	return 0;
3245     if( u->sign )
3246 	return -1;
3247     if( u->nlimbs > 1 )
3248 	return 1;
3249 
3250     if( u->d[0] == limb )
3251 	return 0;
3252     else if( u->d[0] > limb )
3253 	return 1;
3254     else
3255 	return -1;
3256 }
3257 
3258 int
3259 mpi_cmp( MPI u, MPI v )
3260 {
3261     mpi_size_t usize, vsize;
3262     int cmp;
3263 
3264     mpi_normalize( u );
3265     mpi_normalize( v );
3266     usize = u->nlimbs;
3267     vsize = v->nlimbs;
3268     if( !u->sign && v->sign )
3269 	return 1;
3270     if( u->sign && !v->sign )
3271 	return -1;
3272     if( usize != vsize && !u->sign && !v->sign )
3273 	return usize - vsize;
3274     if( usize != vsize && u->sign && v->sign )
3275 	return vsize + usize;
3276     if( !usize )
3277 	return 0;
3278     if( !(cmp=mpihelp_cmp( u->d, v->d, usize )) )
3279 	return 0;
3280     if( (cmp < 0?1:0) == (u->sign?1:0))
3281 	return 1;
3282     return -1;
3283 }
3284 
3285