-
+ 9225D6FAA31311EA2857E6C9A8AD497846F41ECA0BF07B0EBC7601B05251AF751E68226CE7BB6B9F261FB182A5BE9BB1A05AEE4F222764D2F9CA28BFC59CFA99
smg_comms/mpi/mpi-cmp.c
(0 . 0)(1 . 77)
3948 /* mpi-cmp.c - MPI functions
3949 * Modified by No Such Labs. (C) 2015. See README.
3950 *
3951 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
3952 * SHA256(gnupg-1.4.10.tar.gz):
3953 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
3954 * (C) 1994-2005 Free Software Foundation, Inc.
3955 *
3956 * This program is free software: you can redistribute it and/or modify
3957 * it under the terms of the GNU General Public License as published by
3958 * the Free Software Foundation, either version 3 of the License, or
3959 * (at your option) any later version.
3960 *
3961 * This program is distributed in the hope that it will be useful,
3962 * but WITHOUT ANY WARRANTY; without even the implied warranty of
3963 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3964 * GNU General Public License for more details.
3965 *
3966 * You should have received a copy of the GNU General Public License
3967 * along with this program. If not, see <http://www.gnu.org/licenses/>.
3968 */
3969
3970 #include <stdio.h>
3971 #include <stdlib.h>
3972
3973 #include "knobs.h"
3974 #include "mpi-internal.h"
3975
3976 int
3977 mpi_cmp_ui( MPI u, unsigned long v )
3978 {
3979 mpi_limb_t limb = v;
3980
3981 mpi_normalize( u );
3982 if( !u->nlimbs && !limb )
3983 return 0;
3984 if( u->sign )
3985 return -1;
3986 if( u->nlimbs > 1 )
3987 return 1;
3988
3989 if( u->d[0] == limb )
3990 return 0;
3991 else if( u->d[0] > limb )
3992 return 1;
3993 else
3994 return -1;
3995 }
3996
3997 int
3998 mpi_cmp( MPI u, MPI v )
3999 {
4000 mpi_size_t usize, vsize;
4001 int cmp;
4002
4003 mpi_normalize( u );
4004 mpi_normalize( v );
4005 usize = u->nlimbs;
4006 vsize = v->nlimbs;
4007 if( !u->sign && v->sign )
4008 return 1;
4009 if( u->sign && !v->sign )
4010 return -1;
4011 if( usize != vsize && !u->sign && !v->sign )
4012 return usize - vsize;
4013 if( usize != vsize && u->sign && v->sign )
4014 return vsize + usize;
4015 if( !usize )
4016 return 0;
4017 if( !(cmp=mpihelp_cmp( u->d, v->d, usize )) )
4018 return 0;
4019 if( (cmp < 0?1:0) == (u->sign?1:0))
4020 return 1;
4021 return -1;
4022 }
4023
4024