-
+ 83C978461CA2FC606EAB05035DB9A67D600396F013E5CE0DB8CC110D8881E9BE513D540B27DAECC8B0293178D7AB27EE52F5C947A0B9976863B9094F82EBD522
mpi/mpi-cmp.c
(0 . 0)(1 . 73)
6569 /* mpi-cmp.c - MPI functions
6570 * Copyright (C) 1998, 1999 Free Software Foundation, Inc.
6571 *
6572 * This file is part of GnuPG.
6573 *
6574 * GnuPG is free software; you can redistribute it and/or modify
6575 * it under the terms of the GNU General Public License as published by
6576 * the Free Software Foundation; either version 3 of the License, or
6577 * (at your option) any later version.
6578 *
6579 * GnuPG is distributed in the hope that it will be useful,
6580 * but WITHOUT ANY WARRANTY; without even the implied warranty of
6581 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6582 * GNU General Public License for more details.
6583 *
6584 * You should have received a copy of the GNU General Public License
6585 * along with this program; if not, see <http://www.gnu.org/licenses/>.
6586 */
6587
6588 #include <config.h>
6589 #include <stdio.h>
6590 #include <stdlib.h>
6591 #include "mpi-internal.h"
6592
6593 int
6594 mpi_cmp_ui( MPI u, unsigned long v )
6595 {
6596 mpi_limb_t limb = v;
6597
6598 mpi_normalize( u );
6599 if( !u->nlimbs && !limb )
6600 return 0;
6601 if( u->sign )
6602 return -1;
6603 if( u->nlimbs > 1 )
6604 return 1;
6605
6606 if( u->d[0] == limb )
6607 return 0;
6608 else if( u->d[0] > limb )
6609 return 1;
6610 else
6611 return -1;
6612 }
6613
6614 int
6615 mpi_cmp( MPI u, MPI v )
6616 {
6617 mpi_size_t usize, vsize;
6618 int cmp;
6619
6620 mpi_normalize( u );
6621 mpi_normalize( v );
6622 usize = u->nlimbs;
6623 vsize = v->nlimbs;
6624 if( !u->sign && v->sign )
6625 return 1;
6626 if( u->sign && !v->sign )
6627 return -1;
6628 if( usize != vsize && !u->sign && !v->sign )
6629 return usize - vsize;
6630 if( usize != vsize && u->sign && v->sign )
6631 return vsize + usize;
6632 if( !usize )
6633 return 0;
6634 if( !(cmp=mpihelp_cmp( u->d, v->d, usize )) )
6635 return 0;
6636 if( (cmp < 0?1:0) == (u->sign?1:0))
6637 return 1;
6638 return -1;
6639 }
6640
6641