summaryrefslogtreecommitdiff
path: root/plugins/MirOTR/Libgcrypt/mpi/mpi-cmp.c
diff options
context:
space:
mode:
authorRené Schümann <white06tiger@gmail.com>2015-03-20 12:32:29 +0000
committerRené Schümann <white06tiger@gmail.com>2015-03-20 12:32:29 +0000
commit539705d58fc39a28388ff18c695dd406f4ffd1d9 (patch)
tree51db7a37a66c09f41734ba5573d972aae9f30d71 /plugins/MirOTR/Libgcrypt/mpi/mpi-cmp.c
parent90171f125f36488dc08f5cfe0b0d4b78d995f08d (diff)
MirOTR: Libgcrypt and Libgpg-error update
Libgcrypt 1.4.6 => 1.6.3 Libgpg-error 1.9 => 1.18 git-svn-id: http://svn.miranda-ng.org/main/trunk@12449 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
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;
}