blob: bd5e9bfa983485e5438dc5a4bd231413fa806d2c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
Index: mpi-1.8.6/mpi.c
===================================================================
--- mpi-1.8.6.orig/mpi.c 2012-04-05 16:26:22.206340007 -0700
+++ mpi-1.8.6/mpi.c 2012-04-09 08:59:09.673643507 -0700
@@ -1960,6 +1960,34 @@
/* }}} */
+unsigned long mp_hash(mp_int *a)
+{
+#if SIZEOF_LONG > MP_DIGIT_SIZE
+ unsigned long hash;
+ int ix;
+
+ if (USED(a) >= 2 * SIZEOF_LONG / MP_DIGIT_SIZE) {
+ unsigned long omega = 0;
+ unsigned long alpha = 0;
+ for (ix = 0; ix < SIZEOF_LONG / MP_DIGIT_SIZE; ix++)
+ omega = (omega << MP_DIGIT_BIT) | DIGIT(a, ix);
+ for (ix = USED(a) - SIZEOF_LONG / MP_DIGIT_SIZE; ix < USED(a); ix++)
+ alpha = (alpha << MP_DIGIT_BIT) | DIGIT(a, ix);
+ hash = alpha + omega;
+ } else {
+ hash = 0;
+
+ for (ix = 0; ix < USED(a); ix++)
+ hash = (hash << MP_DIGIT_BIT) | DIGIT(a, ix);
+ }
+#else
+ mp_digit omega = DIGIT(a, 0);
+ mp_digit alpha = DIGIT(a, USED(a) - 1);
+ unsigned long hash = alpha + omega;
+#endif
+ return SIGN(a) == MP_NEG ? ~hash : hash;
+}
+
/*------------------------------------------------------------------------*/
/* {{{ Number theoretic functions */
Index: mpi-1.8.6/mpi.h
===================================================================
--- mpi-1.8.6.orig/mpi.h 2012-04-05 16:26:22.206340007 -0700
+++ mpi-1.8.6/mpi.h 2012-04-09 08:58:17.100087507 -0700
@@ -165,6 +165,8 @@
int mp_isodd(mp_int *a);
int mp_iseven(mp_int *a);
+unsigned long mp_hash(mp_int *a);
+
/*------------------------------------------------------------------------*/
/* Number theoretic */
|