-
+ 83C978461CA2FC606EAB05035DB9A67D600396F013E5CE0DB8CC110D8881E9BE513D540B27DAECC8B0293178D7AB27EE52F5C947A0B9976863B9094F82EBD522mpi/mpi-cmp.c(0 . 0)(1 . 73)
6494 /* mpi-cmp.c - MPI functions
6495 * Copyright (C) 1998, 1999 Free Software Foundation, Inc.
6496 *
6497 * This file is part of GnuPG.
6498 *
6499 * GnuPG is free software; you can redistribute it and/or modify
6500 * it under the terms of the GNU General Public License as published by
6501 * the Free Software Foundation; either version 3 of the License, or
6502 * (at your option) any later version.
6503 *
6504 * GnuPG is distributed in the hope that it will be useful,
6505 * but WITHOUT ANY WARRANTY; without even the implied warranty of
6506 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6507 * GNU General Public License for more details.
6508 *
6509 * You should have received a copy of the GNU General Public License
6510 * along with this program; if not, see <http://www.gnu.org/licenses/>.
6511 */
6512
6513 #include <config.h>
6514 #include <stdio.h>
6515 #include <stdlib.h>
6516 #include "mpi-internal.h"
6517
6518 int
6519 mpi_cmp_ui( MPI u, unsigned long v )
6520 {
6521 mpi_limb_t limb = v;
6522
6523 mpi_normalize( u );
6524 if( !u->nlimbs && !limb )
6525 return 0;
6526 if( u->sign )
6527 return -1;
6528 if( u->nlimbs > 1 )
6529 return 1;
6530
6531 if( u->d[0] == limb )
6532 return 0;
6533 else if( u->d[0] > limb )
6534 return 1;
6535 else
6536 return -1;
6537 }
6538
6539 int
6540 mpi_cmp( MPI u, MPI v )
6541 {
6542 mpi_size_t usize, vsize;
6543 int cmp;
6544
6545 mpi_normalize( u );
6546 mpi_normalize( v );
6547 usize = u->nlimbs;
6548 vsize = v->nlimbs;
6549 if( !u->sign && v->sign )
6550 return 1;
6551 if( u->sign && !v->sign )
6552 return -1;
6553 if( usize != vsize && !u->sign && !v->sign )
6554 return usize - vsize;
6555 if( usize != vsize && u->sign && v->sign )
6556 return vsize + usize;
6557 if( !usize )
6558 return 0;
6559 if( !(cmp=mpihelp_cmp( u->d, v->d, usize )) )
6560 return 0;
6561 if( (cmp < 0?1:0) == (u->sign?1:0))
6562 return 1;
6563 return -1;
6564 }
6565
6566