summaryrefslogtreecommitdiff
path: root/plugins/MirOTR/Libgcrypt/mpi/mpi-cmp.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/MirOTR/Libgcrypt/mpi/mpi-cmp.c')
-rw-r--r--plugins/MirOTR/Libgcrypt/mpi/mpi-cmp.c63
1 files changed, 40 insertions, 23 deletions
diff --git a/plugins/MirOTR/Libgcrypt/mpi/mpi-cmp.c b/plugins/MirOTR/Libgcrypt/mpi/mpi-cmp.c
index 9dd10830b0..838a7c9240 100644
--- a/plugins/MirOTR/Libgcrypt/mpi/mpi-cmp.c
+++ b/plugins/MirOTR/Libgcrypt/mpi/mpi-cmp.c
@@ -24,7 +24,7 @@
#include "mpi-internal.h"
int
-gcry_mpi_cmp_ui (gcry_mpi_t u, unsigned long v)
+_gcry_mpi_cmp_ui (gcry_mpi_t u, unsigned long v)
{
mpi_limb_t limb = v;
@@ -53,38 +53,55 @@ gcry_mpi_cmp_ui (gcry_mpi_t u, unsigned long v)
return 1;
}
+
int
-gcry_mpi_cmp (gcry_mpi_t u, gcry_mpi_t v)
+_gcry_mpi_cmp (gcry_mpi_t u, gcry_mpi_t v)
{
mpi_size_t usize;
mpi_size_t vsize;
int cmp;
- _gcry_mpi_normalize (u);
- _gcry_mpi_normalize (v);
-
- usize = u->nlimbs;
- vsize = v->nlimbs;
+ if (mpi_is_opaque (u) || mpi_is_opaque (v))
+ {
+ if (mpi_is_opaque (u) && !mpi_is_opaque (v))
+ return -1;
+ if (!mpi_is_opaque (u) && mpi_is_opaque (v))
+ return 1;
+ if (!u->sign && !v->sign)
+ return 0; /* Empty buffers are identical. */
+ if (u->sign < v->sign)
+ return -1;
+ if (u->sign > v->sign)
+ return 1;
+ return memcmp (u->d, v->d, (u->sign+7)/8);
+ }
+ else
+ {
+ _gcry_mpi_normalize (u);
+ _gcry_mpi_normalize (v);
- /* Compare sign bits. */
+ usize = u->nlimbs;
+ vsize = v->nlimbs;
- if (!u->sign && v->sign)
- return 1;
- if (u->sign && !v->sign)
- return -1;
+ /* Compare sign bits. */
- /* U and V are either both positive or both negative. */
+ if (!u->sign && v->sign)
+ return 1;
+ if (u->sign && !v->sign)
+ return -1;
- if( usize != vsize && !u->sign && !v->sign )
- return usize - vsize;
- if( usize != vsize && u->sign && v->sign )
- return vsize + usize;
- if( !usize )
- return 0;
- if( !(cmp = _gcry_mpih_cmp( u->d, v->d, usize )) )
- return 0;
- if( (cmp < 0?1:0) == (u->sign?1:0))
- return 1;
+ /* U and V are either both positive or both negative. */
+ if (usize != vsize && !u->sign && !v->sign)
+ return usize - vsize;
+ if (usize != vsize && u->sign && v->sign)
+ return vsize + usize;
+ if (!usize )
+ return 0;
+ if (!(cmp = _gcry_mpih_cmp (u->d, v->d, usize)))
+ return 0;
+ if ((cmp < 0?1:0) == (u->sign?1:0))
+ return 1;
+ }
return -1;
}