-
+ E789CEA1E3A670F80F48773AE523B6BA57FA5BDBC170D552037871C9E22F04BC697ED636C9DCC13BDAF1DDC7E86748CEE33CF8519F619E8E6F7F4486A549C881
eucrypt/mpi/mpih-cmp.c
(0 . 0)(1 . 55)
5077 /* mpihelp-sub.c - MPI helper functions
5078 * Modified by No Such Labs. (C) 2015. See README.
5079 *
5080 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
5081 * SHA256(gnupg-1.4.10.tar.gz):
5082 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
5083 * (C) 1994-2005 Free Software Foundation, Inc.
5084 *
5085 * This program is free software: you can redistribute it and/or modify
5086 * it under the terms of the GNU General Public License as published by
5087 * the Free Software Foundation, either version 3 of the License, or
5088 * (at your option) any later version.
5089 *
5090 * This program is distributed in the hope that it will be useful,
5091 * but WITHOUT ANY WARRANTY; without even the implied warranty of
5092 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5093 * GNU General Public License for more details.
5094 *
5095 * You should have received a copy of the GNU General Public License
5096 * along with this program. If not, see <http://www.gnu.org/licenses/>.
5097 */
5098
5099 #include <stdio.h>
5100 #include <stdlib.h>
5101
5102 #include "knobs.h"
5103 #include "mpi-internal.h"
5104
5105 /****************
5106 * Compare OP1_PTR/OP1_SIZE with OP2_PTR/OP2_SIZE.
5107 * There are no restrictions on the relative sizes of
5108 * the two arguments.
5109 * Return 1 if OP1 > OP2, 0 if they are equal, and -1 if OP1 < OP2.
5110 */
5111 int
5112 mpihelp_cmp( mpi_ptr_t op1_ptr, mpi_ptr_t op2_ptr, mpi_size_t size )
5113 {
5114 mpi_size_t i;
5115 mpi_limb_t op1_word, op2_word;
5116
5117 for( i = size - 1; i >= 0 ; i--) {
5118 op1_word = op1_ptr[i];
5119 op2_word = op2_ptr[i];
5120 if( op1_word != op2_word )
5121 goto diff;
5122 }
5123 return 0;
5124
5125 diff:
5126 /* This can *not* be simplified to
5127 * op2_word - op2_word
5128 * since that expression might give signed overflow. */
5129 return (op1_word > op2_word) ? 1 : -1;
5130 }
5131