-
+ 88A21583524C37A7FEBB2EEDAF38F0942183A201EE8DF8B9E04A8098E892DD88B7F8566E40CC8BF042D5713E2F78886526CC23DE79C61463E7763685F280C37E
mpi/mpih-cmp.c
(0 . 0)(1 . 61)
8641 /* mpihelp-sub.c - MPI helper functions
8642 * Copyright (C) 1994, 1996 Free Software Foundation, Inc.
8643 * Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
8644 *
8645 * This file is part of GnuPG.
8646 *
8647 * GnuPG is free software; you can redistribute it and/or modify
8648 * it under the terms of the GNU General Public License as published by
8649 * the Free Software Foundation; either version 3 of the License, or
8650 * (at your option) any later version.
8651 *
8652 * GnuPG is distributed in the hope that it will be useful,
8653 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8654 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8655 * GNU General Public License for more details.
8656 *
8657 * You should have received a copy of the GNU General Public License
8658 * along with this program; if not, see <http://www.gnu.org/licenses/>.
8659 *
8660 * Note: This code is heavily based on the GNU MP Library.
8661 * Actually it's the same code with only minor changes in the
8662 * way the data is stored; this is to support the abstraction
8663 * of an optional secure memory allocation which may be used
8664 * to avoid revealing of sensitive data due to paging etc.
8665 * The GNU MP Library itself is published under the LGPL;
8666 * however I decided to publish this code under the plain GPL.
8667 */
8668
8669 #include <config.h>
8670 #include <stdio.h>
8671 #include <stdlib.h>
8672
8673 #include "mpi-internal.h"
8674
8675 /****************
8676 * Compare OP1_PTR/OP1_SIZE with OP2_PTR/OP2_SIZE.
8677 * There are no restrictions on the relative sizes of
8678 * the two arguments.
8679 * Return 1 if OP1 > OP2, 0 if they are equal, and -1 if OP1 < OP2.
8680 */
8681 int
8682 mpihelp_cmp( mpi_ptr_t op1_ptr, mpi_ptr_t op2_ptr, mpi_size_t size )
8683 {
8684 mpi_size_t i;
8685 mpi_limb_t op1_word, op2_word;
8686
8687 for( i = size - 1; i >= 0 ; i--) {
8688 op1_word = op1_ptr[i];
8689 op2_word = op2_ptr[i];
8690 if( op1_word != op2_word )
8691 goto diff;
8692 }
8693 return 0;
8694
8695 diff:
8696 /* This can *not* be simplified to
8697 * op2_word - op2_word
8698 * since that expression might give signed overflow. */
8699 return (op1_word > op2_word) ? 1 : -1;
8700 }
8701