// SPDX-License-Identifier: GPL-2.0-or-later1/* mpihelp-sub.c - MPI helper functions2* Copyright (C) 1994, 1996 Free Software Foundation, Inc.3* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.4*5* This file is part of GnuPG.6*7* Note: This code is heavily based on the GNU MP Library.8* Actually it's the same code with only minor changes in the9* way the data is stored; this is to support the abstraction10* of an optional secure memory allocation which may be used11* to avoid revealing of sensitive data due to paging etc.12* The GNU MP Library itself is published under the LGPL;13* however I decided to publish this code under the plain GPL.14*/1516#include "mpi-internal.h"1718/****************19* Compare OP1_PTR/OP1_SIZE with OP2_PTR/OP2_SIZE.20* There are no restrictions on the relative sizes of21* the two arguments.22* Return 1 if OP1 > OP2, 0 if they are equal, and -1 if OP1 < OP2.23*/24int mpihelp_cmp(mpi_ptr_t op1_ptr, mpi_ptr_t op2_ptr, mpi_size_t size)25{26mpi_size_t i;27mpi_limb_t op1_word, op2_word;2829for (i = size - 1; i >= 0; i--) {30op1_word = op1_ptr[i];31op2_word = op2_ptr[i];32if (op1_word != op2_word)33goto diff;34}35return 0;3637diff:38/* This can *not* be simplified to39* op2_word - op2_word40* since that expression might give signed overflow. */41return (op1_word > op2_word) ? 1 : -1;42}434445