mpi-genesis~ 1
mpi-genesis~ 2 * Copyright (C) 1994, 1996 Free Software Foundation, Inc.
mpi-genesis~ 3 * Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
mpi-genesis~ 4 *
mpi-genesis~ 5 * This file is part of GnuPG.
mpi-genesis~ 6 *
mpi-genesis~ 7 * GnuPG is free software; you can redistribute it and/or modify
mpi-genesis~ 8 * it under the terms of the GNU General Public License as published by
mpi-genesis~ 9 * the Free Software Foundation; either version 3 of the License, or
mpi-genesis~ 10 * (at your option) any later version.
mpi-genesis~ 11 *
mpi-genesis~ 12 * GnuPG is distributed in the hope that it will be useful,
mpi-genesis~ 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
mpi-genesis~ 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
mpi-genesis~ 15 * GNU General Public License for more details.
mpi-genesis~ 16 *
mpi-genesis~ 17 * You should have received a copy of the GNU General Public License
mpi-genesis~ 18 * along with this program; if not, see <http:
mpi-genesis~ 19 *
mpi-genesis~ 20 * Note: This code is heavily based on the GNU MP Library.
mpi-genesis~ 21 * Actually it's the same code with only minor changes in the
mpi-genesis~ 22 * way the data is stored; this is to support the abstraction
mpi-genesis~ 23 * of an optional secure memory allocation which may be used
mpi-genesis~ 24 * to avoid revealing of sensitive data due to paging etc.
mpi-genesis~ 25 * The GNU MP Library itself is published under the LGPL;
mpi-genesis~ 26 * however I decided to publish this code under the plain GPL.
mpi-genesis~ 27 */
mpi-genesis~ 28
mpi-genesis~ 29 #include <config.h>
mpi-genesis~ 30 #include <stdio.h>
mpi-genesis~ 31 #include <stdlib.h>
mpi-genesis~ 32
mpi-genesis~ 33 #include "mpi-internal.h"
mpi-genesis~ 34
mpi-genesis~ 35
mpi-genesis~ 36 * Compare OP1_PTR/OP1_SIZE with OP2_PTR/OP2_SIZE.
mpi-genesis~ 37 * There are no restrictions on the relative sizes of
mpi-genesis~ 38 * the two arguments.
mpi-genesis~ 39 * Return 1 if OP1 > OP2, 0 if they are equal, and -1 if OP1 < OP2.
mpi-genesis~ 40 */
mpi-genesis~ 41 int
mpi-genesis~ 42 mpihelp_cmp( mpi_ptr_t op1_ptr, mpi_ptr_t op2_ptr, mpi_size_t size )
mpi-genesis~ 43 {
mpi-genesis~ 44 mpi_size_t i;
mpi-genesis~ 45 mpi_limb_t op1_word, op2_word;
mpi-genesis~ 46
mpi-genesis~ 47 for( i = size - 1; i >= 0 ; i--) {
mpi-genesis~ 48 op1_word = op1_ptr[i];
mpi-genesis~ 49 op2_word = op2_ptr[i];
mpi-genesis~ 50 if( op1_word != op2_word )
mpi-genesis~ 51 goto diff;
mpi-genesis~ 52 }
mpi-genesis~ 53 return 0;
mpi-genesis~ 54
mpi-genesis~ 55 diff:
mpi-genesis~ 56
mpi-genesis~ 57 * op2_word - op2_word
mpi-genesis~ 58 * since that expression might give signed overflow. */
mpi-genesis~ 59 return (op1_word > op2_word) ? 1 : -1;
mpi-genesis~ 60 }
mpi-genesis~ 61