-
+ 88A21583524C37A7FEBB2EEDAF38F0942183A201EE8DF8B9E04A8098E892DD88B7F8566E40CC8BF042D5713E2F78886526CC23DE79C61463E7763685F280C37Empi/mpih-cmp.c(0 . 0)(1 . 61)
7497 /* mpihelp-sub.c - MPI helper functions
7498 * Copyright (C) 1994, 1996 Free Software Foundation, Inc.
7499 * Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
7500 *
7501 * This file is part of GnuPG.
7502 *
7503 * GnuPG is free software; you can redistribute it and/or modify
7504 * it under the terms of the GNU General Public License as published by
7505 * the Free Software Foundation; either version 3 of the License, or
7506 * (at your option) any later version.
7507 *
7508 * GnuPG is distributed in the hope that it will be useful,
7509 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7510 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7511 * GNU General Public License for more details.
7512 *
7513 * You should have received a copy of the GNU General Public License
7514 * along with this program; if not, see <http://www.gnu.org/licenses/>.
7515 *
7516 * Note: This code is heavily based on the GNU MP Library.
7517 * Actually it's the same code with only minor changes in the
7518 * way the data is stored; this is to support the abstraction
7519 * of an optional secure memory allocation which may be used
7520 * to avoid revealing of sensitive data due to paging etc.
7521 * The GNU MP Library itself is published under the LGPL;
7522 * however I decided to publish this code under the plain GPL.
7523 */
7524
7525 #include <config.h>
7526 #include <stdio.h>
7527 #include <stdlib.h>
7528
7529 #include "mpi-internal.h"
7530
7531 /****************
7532 * Compare OP1_PTR/OP1_SIZE with OP2_PTR/OP2_SIZE.
7533 * There are no restrictions on the relative sizes of
7534 * the two arguments.
7535 * Return 1 if OP1 > OP2, 0 if they are equal, and -1 if OP1 < OP2.
7536 */
7537 int
7538 mpihelp_cmp( mpi_ptr_t op1_ptr, mpi_ptr_t op2_ptr, mpi_size_t size )
7539 {
7540 mpi_size_t i;
7541 mpi_limb_t op1_word, op2_word;
7542
7543 for( i = size - 1; i >= 0 ; i--) {
7544 op1_word = op1_ptr[i];
7545 op2_word = op2_ptr[i];
7546 if( op1_word != op2_word )
7547 goto diff;
7548 }
7549 return 0;
7550
7551 diff:
7552 /* This can *not* be simplified to
7553 * op2_word - op2_word
7554 * since that expression might give signed overflow. */
7555 return (op1_word > op2_word) ? 1 : -1;
7556 }
7557