Diffstat (limited to 'pwmanager/libcrypt/mpi/mpi-cmp.c') (more/less context) (ignore whitespace changes)
-rw-r--r-- | pwmanager/libcrypt/mpi/mpi-cmp.c | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/pwmanager/libcrypt/mpi/mpi-cmp.c b/pwmanager/libcrypt/mpi/mpi-cmp.c new file mode 100644 index 0000000..6036255 --- a/dev/null +++ b/pwmanager/libcrypt/mpi/mpi-cmp.c | |||
@@ -0,0 +1,74 @@ | |||
1 | /* mpi-cmp.c - MPI functions | ||
2 | * Copyright (C) 1998, 1999, 2001, 2002 Free Software Foundation, Inc. | ||
3 | * | ||
4 | * This file is part of Libgcrypt. | ||
5 | * | ||
6 | * Libgcrypt is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU Lesser General Public License as | ||
8 | * published by the Free Software Foundation; either version 2.1 of | ||
9 | * the License, or (at your option) any later version. | ||
10 | * | ||
11 | * Libgcrypt is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU Lesser General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU Lesser General Public | ||
17 | * License along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA | ||
19 | */ | ||
20 | |||
21 | #include <config.h> | ||
22 | #include <stdio.h> | ||
23 | #include <stdlib.h> | ||
24 | #include "mpi-internal.h" | ||
25 | |||
26 | int | ||
27 | gcry_mpi_cmp_ui( gcry_mpi_t u, unsigned long v ) | ||
28 | { | ||
29 | mpi_limb_t limb = v; | ||
30 | |||
31 | _gcry_mpi_normalize( u ); | ||
32 | if( !u->nlimbs && !limb ) | ||
33 | return 0; | ||
34 | if( u->sign ) | ||
35 | return -1; | ||
36 | if( u->nlimbs > 1 ) | ||
37 | return 1; | ||
38 | |||
39 | if( u->d[0] == limb ) | ||
40 | return 0; | ||
41 | else if( u->d[0] > limb ) | ||
42 | return 1; | ||
43 | else | ||
44 | return -1; | ||
45 | } | ||
46 | |||
47 | int | ||
48 | gcry_mpi_cmp( gcry_mpi_t u, gcry_mpi_t v ) | ||
49 | { | ||
50 | mpi_size_t usize, vsize; | ||
51 | int cmp; | ||
52 | |||
53 | _gcry_mpi_normalize( u ); | ||
54 | _gcry_mpi_normalize( v ); | ||
55 | usize = u->nlimbs; | ||
56 | vsize = v->nlimbs; | ||
57 | if( !u->sign && v->sign ) | ||
58 | return 1; | ||
59 | if( u->sign && !v->sign ) | ||
60 | return -1; | ||
61 | if( usize != vsize && !u->sign && !v->sign ) | ||
62 | return usize - vsize; | ||
63 | if( usize != vsize && u->sign && v->sign ) | ||
64 | return vsize + usize; | ||
65 | if( !usize ) | ||
66 | return 0; | ||
67 | if( !(cmp = _gcry_mpih_cmp( u->d, v->d, usize )) ) | ||
68 | return 0; | ||
69 | if( (cmp < 0?1:0) == (u->sign?1:0)) | ||
70 | return 1; | ||
71 | return -1; | ||
72 | } | ||
73 | |||
74 | |||