aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-04-06 14:37:07 +0200
committerChristian Grothoff <christian@grothoff.org>2019-04-06 14:37:07 +0200
commitc57caa206c761424b73e900978edff0a1b8fca50 (patch)
tree66641306c9a1d196dfe9f82c863bada50fb86187 /src/util
parentc0d08bbdeed4523cf89bf55b64ce2c16476c3e26 (diff)
downloadgnunet-c57caa206c761424b73e900978edff0a1b8fca50.tar.gz
gnunet-c57caa206c761424b73e900978edff0a1b8fca50.zip
introduce GNUNET_memcmp() and GNUNET_is_zero()
Diffstat (limited to 'src/util')
-rw-r--r--src/util/crypto_ecc.c23
-rw-r--r--src/util/service.c8
-rw-r--r--src/util/test_peer.c37
3 files changed, 23 insertions, 45 deletions
diff --git a/src/util/crypto_ecc.c b/src/util/crypto_ecc.c
index cf40522d6..339180dff 100644
--- a/src/util/crypto_ecc.c
+++ b/src/util/crypto_ecc.c
@@ -11,7 +11,7 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
@@ -763,23 +763,6 @@ GNUNET_CRYPTO_ecdsa_key_get_anonymous ()
763 763
764 764
765/** 765/**
766 * Compare two Peer Identities.
767 *
768 * @param first first peer identity
769 * @param second second peer identity
770 * @return bigger than 0 if first > second,
771 * 0 if they are the same
772 * smaller than 0 if second > first
773 */
774int
775GNUNET_CRYPTO_cmp_peer_identity (const struct GNUNET_PeerIdentity *first,
776 const struct GNUNET_PeerIdentity *second)
777{
778 return memcmp (first, second, sizeof (struct GNUNET_PeerIdentity));
779}
780
781
782/**
783 * Convert the data specified in the given purpose argument to an 766 * Convert the data specified in the given purpose argument to an
784 * S-expression suitable for signature operations. 767 * S-expression suitable for signature operations.
785 * 768 *
@@ -795,7 +778,7 @@ data_to_eddsa_value (const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose)
795/* SEE #5398 */ 778/* SEE #5398 */
796#if 1 779#if 1
797 struct GNUNET_HashCode hc; 780 struct GNUNET_HashCode hc;
798 781
799 GNUNET_CRYPTO_hash (purpose, 782 GNUNET_CRYPTO_hash (purpose,
800 ntohl (purpose->size), 783 ntohl (purpose->size),
801 &hc); 784 &hc);
@@ -823,7 +806,7 @@ data_to_eddsa_value (const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose)
823 rc); 806 rc);
824 return NULL; 807 return NULL;
825 } 808 }
826#endif 809#endif
827 return data; 810 return data;
828} 811}
829 812
diff --git a/src/util/service.c b/src/util/service.c
index b2e3e89cc..4fd16f93d 100644
--- a/src/util/service.c
+++ b/src/util/service.c
@@ -473,18 +473,12 @@ check_ipv6_listed (const struct GNUNET_STRINGS_IPv6NetworkPolicy *list,
473{ 473{
474 unsigned int i; 474 unsigned int i;
475 unsigned int j; 475 unsigned int j;
476 struct in6_addr zero;
477 476
478 if (NULL == list) 477 if (NULL == list)
479 return GNUNET_NO; 478 return GNUNET_NO;
480 memset (&zero,
481 0,
482 sizeof (struct in6_addr));
483 i = 0; 479 i = 0;
484NEXT: 480NEXT:
485 while (0 != memcmp (&zero, 481 while (0 != GNUNET_is_zero (&list[i].network))
486 &list[i].network,
487 sizeof (struct in6_addr)))
488 { 482 {
489 for (j = 0; j < sizeof (struct in6_addr) / sizeof (int); j++) 483 for (j = 0; j < sizeof (struct in6_addr) / sizeof (int); j++)
490 if (((((int *) ip)[j] & ((int *) &list[i].netmask)[j])) != 484 if (((((int *) ip)[j] & ((int *) &list[i].netmask)[j])) !=
diff --git a/src/util/test_peer.c b/src/util/test_peer.c
index 9fbedb15c..248836b4c 100644
--- a/src/util/test_peer.c
+++ b/src/util/test_peer.c
@@ -11,7 +11,7 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
@@ -38,15 +38,15 @@ static struct GNUNET_PeerIdentity pidArr[NUMBER_OF_PEERS];
38static void 38static void
39generatePeerIdList () 39generatePeerIdList ()
40{ 40{
41 int i; 41 for (unsigned int i = 0; i < NUMBER_OF_PEERS; i++)
42
43 for (i = 0; i < NUMBER_OF_PEERS; i++)
44 { 42 {
45 gcry_randomize (&pidArr[i], 43 gcry_randomize (&pidArr[i],
46 sizeof (struct GNUNET_PeerIdentity), 44 sizeof (struct GNUNET_PeerIdentity),
47 GCRY_STRONG_RANDOM); 45 GCRY_STRONG_RANDOM);
48 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 46 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
49 "Peer %d: %s\n", i, GNUNET_i2s (&pidArr[i])); 47 "Peer %u: %s\n",
48 i,
49 GNUNET_i2s (&pidArr[i]));
50 } 50 }
51} 51}
52 52
@@ -54,15 +54,13 @@ generatePeerIdList ()
54static int 54static int
55check () 55check ()
56{ 56{
57 int i;
58 GNUNET_PEER_Id pid; 57 GNUNET_PEER_Id pid;
59 struct GNUNET_PeerIdentity res; 58 struct GNUNET_PeerIdentity res;
60 struct GNUNET_PeerIdentity zero;
61 GNUNET_PEER_Id ids[] = { 1, 2, 3 }; 59 GNUNET_PEER_Id ids[] = { 1, 2, 3 };
62 60
63 GNUNET_assert (0 == GNUNET_PEER_intern (NULL)); 61 GNUNET_assert (0 == GNUNET_PEER_intern (NULL));
64 /* Insert Peers into PeerEntry table and hashmap */ 62 /* Insert Peers into PeerEntry table and hashmap */
65 for (i = 0; i < NUMBER_OF_PEERS; i++) 63 for (unsigned int i = 0; i < NUMBER_OF_PEERS; i++)
66 { 64 {
67 pid = GNUNET_PEER_intern (&pidArr[i]); 65 pid = GNUNET_PEER_intern (&pidArr[i]);
68 if (pid != (i + 1)) 66 if (pid != (i + 1))
@@ -73,7 +71,7 @@ check ()
73 } 71 }
74 72
75 /* Referencing the first 3 peers once again */ 73 /* Referencing the first 3 peers once again */
76 for (i = 0; i < 3; i++) 74 for (unsigned int i = 0; i < 3; i++)
77 { 75 {
78 pid = GNUNET_PEER_intern (&pidArr[i]); 76 pid = GNUNET_PEER_intern (&pidArr[i]);
79 if (pid != (i + 1)) 77 if (pid != (i + 1))
@@ -87,25 +85,28 @@ check ()
87 GNUNET_PEER_decrement_rcs (ids, 3); 85 GNUNET_PEER_decrement_rcs (ids, 3);
88 86
89 /* re-referencing the first 3 peers using the change_rc function */ 87 /* re-referencing the first 3 peers using the change_rc function */
90 for (i = 1; i <= 3; i++) 88 for (unsigned int i = 1; i <= 3; i++)
91 GNUNET_PEER_change_rc (i, 1); 89 GNUNET_PEER_change_rc (i, 1);
92 90
93 /* Removing the second Peer from the PeerEntry hash map */ 91 /* Removing the second Peer from the PeerEntry hash map */
94 GNUNET_PEER_change_rc (2, -2); 92 GNUNET_PEER_change_rc (2, -2);
95 93
96 /* convert the pid of the first PeerEntry into that of the third */ 94 /* convert the pid of the first PeerEntry into that of the third */
97 GNUNET_PEER_resolve (1, &res); 95 GNUNET_PEER_resolve (1,
98 GNUNET_assert (0 == memcmp (&res, &pidArr[0], sizeof (res))); 96 &res);
97 GNUNET_assert (0 ==
98 GNUNET_memcmp (&res,
99 &pidArr[0]));
99 100
100 /* 101 /*
101 * Attempt to convert pid = 0 (which is reserved) 102 * Attempt to convert pid = 0 (which is reserved)
102 * into a peer identity object, the peer identity memory 103 * into a peer identity object, the peer identity memory
103 * is expected to be set to zero 104 * is expected to be set to zero
104 */ 105 */
105 memset (&zero, 0, sizeof (struct GNUNET_PeerIdentity));
106 GNUNET_log_skip (1, GNUNET_YES); 106 GNUNET_log_skip (1, GNUNET_YES);
107 GNUNET_PEER_resolve (0, &res); 107 GNUNET_PEER_resolve (0, &res);
108 GNUNET_assert (0 == memcmp (&res, &zero, sizeof (res))); 108 GNUNET_assert (0 ==
109 GNUNET_is_zero (&res));
109 110
110 /* Removing peer entries 1 and 3 from table using the list decrement function */ 111 /* Removing peer entries 1 and 3 from table using the list decrement function */
111 /* If count = 0, nothing should be done whatsoever */ 112 /* If count = 0, nothing should be done whatsoever */
@@ -122,10 +123,10 @@ check ()
122int 123int
123main () 124main ()
124{ 125{
125 unsigned int i; 126 GNUNET_log_setup ("test-peer",
126 127 "ERROR",
127 GNUNET_log_setup ("test-peer", "ERROR", NULL); 128 NULL);
128 for (i = 0; i < 1; i++) 129 for (unsigned int i = 0; i < 1; i++)
129 { 130 {
130 generatePeerIdList (); 131 generatePeerIdList ();
131 if (0 != check ()) 132 if (0 != check ())