-vpn should use crc16 from util
authorChristian Grothoff <christian@grothoff.org>
Mon, 2 Jan 2012 10:22:43 +0000 (10:22 +0000)
committerChristian Grothoff <christian@grothoff.org>
Mon, 2 Jan 2012 10:22:43 +0000 (10:22 +0000)
src/vpn/Makefile.am
src/vpn/gnunet-daemon-exit.c
src/vpn/gnunet-daemon-vpn.c
src/vpn/gnunet-vpn-checksum.c [deleted file]
src/vpn/gnunet-vpn-checksum.h [deleted file]

index bdfca7f2f99d00546ba5804ab0a37bf0eb4dffaf..38b37dd65bc3284474a8cb6a420888ef32fafa02 100644 (file)
@@ -33,8 +33,7 @@ gnunet_helper_vpn_SOURCES = \
  gnunet-helper-vpn.c
 
 gnunet_daemon_vpn_SOURCES = \
- gnunet-daemon-vpn.c gnunet-daemon-vpn.h \
- gnunet-vpn-checksum.c gnunet-vpn-checksum.h
+ gnunet-daemon-vpn.c gnunet-daemon-vpn.h 
 gnunet_daemon_vpn_LDADD = \
   $(top_builddir)/src/core/libgnunetcore.la \
   $(top_builddir)/src/statistics/libgnunetstatistics.la \
@@ -45,8 +44,7 @@ gnunet_daemon_vpn_LDADD = \
   $(GN_LIBINTL)
 
 gnunet_daemon_exit_SOURCES = \
- gnunet-daemon-exit.c \
- gnunet-vpn-checksum.c gnunet-vpn-checksum.h
+ gnunet-daemon-exit.c 
 gnunet_daemon_exit_LDADD = \
   $(top_builddir)/src/core/libgnunetcore.la \
   $(top_builddir)/src/statistics/libgnunetstatistics.la \
index ebe3ec61a46160c800b75fc291b77449f2868c00..608646202a913257db18eae6931435022b7fea27 100644 (file)
@@ -835,8 +835,8 @@ prepare_ipv4_packet (size_t len, uint16_t pktlen, void *payload,
     pkt4_tcp->tcp_hdr.crc = 0;
     uint32_t sum = 0;
 
-    sum = calculate_checksum_update (sum, (uint16_t *) &pkt4->ip_hdr.sadr, sizeof (struct in_addr));
-    sum = calculate_checksum_update (sum, (uint16_t *) &pkt4->ip_hdr.dadr, sizeof (struct in_addr));
+    sum = GNUNET_CRYPTO_crc16_step (sum, (uint16_t *) &pkt4->ip_hdr.sadr, sizeof (struct in_addr));
+    sum = GNUNET_CRYPTO_crc16_step (sum, (uint16_t *) &pkt4->ip_hdr.dadr, sizeof (struct in_addr));
 
     tmp = (protocol << 16) | (0xffff & pktlen);
 
@@ -845,16 +845,16 @@ prepare_ipv4_packet (size_t len, uint16_t pktlen, void *payload,
 
     tmp = htonl (tmp);
 
-    sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
+    sum = GNUNET_CRYPTO_crc16_step (sum, (uint16_t *) & tmp, 4);
 
     sum =
-        calculate_checksum_update (sum, (uint16_t *) & pkt4_tcp->tcp_hdr,
+        GNUNET_CRYPTO_crc16_step (sum, (uint16_t *) & pkt4_tcp->tcp_hdr,
                                    pktlen);
-    pkt4_tcp->tcp_hdr.crc = calculate_checksum_end (sum);
+    pkt4_tcp->tcp_hdr.crc = GNUNET_CRYPTO_crc16_finish (sum);
   }
 
   pkt4->ip_hdr.chks =
-      calculate_ip_checksum ((uint16_t *) & pkt4->ip_hdr, 5 * 4);
+      GNUNET_CRYPTO_crc16_n ((uint16_t *) & pkt4->ip_hdr, 5 * 4);
 }
 
 static void
@@ -919,20 +919,20 @@ prepare_ipv6_packet (size_t len, uint16_t pktlen, void *payload,
     uint32_t sum = 0;
 
     sum =
-        calculate_checksum_update (sum, (uint16_t *) & pkt6_udp->ip6_hdr.sadr,
+        GNUNET_CRYPTO_crc16_step (sum, (uint16_t *) & pkt6_udp->ip6_hdr.sadr,
                                    16);
     sum =
-        calculate_checksum_update (sum, (uint16_t *) & pkt6_udp->ip6_hdr.dadr,
+        GNUNET_CRYPTO_crc16_step (sum, (uint16_t *) & pkt6_udp->ip6_hdr.dadr,
                                    16);
     tmp = (htons (pktlen) & 0xffff);
-    sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
+    sum = GNUNET_CRYPTO_crc16_step (sum, (uint16_t *) & tmp, 4);
     tmp = htons (((pkt6_udp->ip6_hdr.nxthdr & 0x00ff)));
-    sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
+    sum = GNUNET_CRYPTO_crc16_step (sum, (uint16_t *) & tmp, 4);
 
     sum =
-        calculate_checksum_update (sum, (uint16_t *) & pkt6_udp->udp_hdr,
+        GNUNET_CRYPTO_crc16_step (sum, (uint16_t *) & pkt6_udp->udp_hdr,
                                    ntohs (pkt6_udp->udp_hdr.len));
-    pkt6_udp->udp_hdr.crc = calculate_checksum_end (sum);
+    pkt6_udp->udp_hdr.crc = GNUNET_CRYPTO_crc16_finish (sum);
   }
   else if (IPPROTO_TCP == protocol)
   {
@@ -944,18 +944,18 @@ prepare_ipv6_packet (size_t len, uint16_t pktlen, void *payload,
     uint32_t sum = 0;
 
     sum =
-        calculate_checksum_update (sum, (uint16_t *) & pkt6->ip6_hdr.sadr, 16);
+        GNUNET_CRYPTO_crc16_step (sum, (uint16_t *) & pkt6->ip6_hdr.sadr, 16);
     sum =
-        calculate_checksum_update (sum, (uint16_t *) & pkt6->ip6_hdr.dadr, 16);
+        GNUNET_CRYPTO_crc16_step (sum, (uint16_t *) & pkt6->ip6_hdr.dadr, 16);
     tmp = htonl (pktlen);
-    sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
+    sum = GNUNET_CRYPTO_crc16_step (sum, (uint16_t *) & tmp, 4);
     tmp = htonl (((pkt6->ip6_hdr.nxthdr & 0x000000ff)));
-    sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
+    sum = GNUNET_CRYPTO_crc16_step (sum, (uint16_t *) & tmp, 4);
 
     sum =
-        calculate_checksum_update (sum, (uint16_t *) & pkt6_tcp->tcp_hdr,
+        GNUNET_CRYPTO_crc16_step (sum, (uint16_t *) & pkt6_tcp->tcp_hdr,
                                    ntohs (pkt6->ip6_hdr.paylgth));
-    pkt6_tcp->tcp_hdr.crc = calculate_checksum_end (sum);
+    pkt6_tcp->tcp_hdr.crc = GNUNET_CRYPTO_crc16_finish (sum);
   }
 }
 
index 35db8af7b8f6aa6335e282805da771732b9659a1..ad6ed5044fb2808a502dc610c0ed9b2ff2bf6714 100644 (file)
@@ -299,18 +299,18 @@ helper_write (void *cls GNUNET_UNUSED,
     pkt->udp_dns.udp_hdr.crc = 0;
     uint32_t sum = 0;
 
-    sum = calculate_checksum_update (sum, (uint16_t *) & pkt->ip6_hdr.sadr, 16);
-    sum = calculate_checksum_update (sum, (uint16_t *) & pkt->ip6_hdr.dadr, 16);
+    sum = GNUNET_CRYPTO_crc16_step (sum, (uint16_t *) & pkt->ip6_hdr.sadr, 16);
+    sum = GNUNET_CRYPTO_crc16_step (sum, (uint16_t *) & pkt->ip6_hdr.dadr, 16);
     uint32_t tmp = (pkt->udp_dns.udp_hdr.len & 0xffff);
 
-    sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
+    sum = GNUNET_CRYPTO_crc16_step (sum, (uint16_t *) & tmp, 4);
     tmp = htons (((pkt->ip6_hdr.nxthdr & 0x00ff)));
-    sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
+    sum = GNUNET_CRYPTO_crc16_step (sum, (uint16_t *) & tmp, 4);
 
     sum =
-        calculate_checksum_update (sum, (uint16_t *) & pkt->udp_dns.udp_hdr,
+        GNUNET_CRYPTO_crc16_step (sum, (uint16_t *) & pkt->udp_dns.udp_hdr,
                                    ntohs (net_len - sizeof (struct ip6_hdr)));
-    pkt->udp_dns.udp_hdr.crc = calculate_checksum_end (sum);
+    pkt->udp_dns.udp_hdr.crc = GNUNET_CRYPTO_crc16_finish (sum);
 
     pkt->ip6_hdr.version = 6;
     pkt->ip6_hdr.paylgth = net_len - sizeof (struct ip6_hdr);
@@ -360,7 +360,7 @@ helper_write (void *cls GNUNET_UNUSED,
     memcpy (&pkt->ip_hdr.dadr, ans->pkt.to, 4);
 
     pkt->ip_hdr.chks =
-        calculate_ip_checksum ((uint16_t *) & pkt->ip_hdr, 5 * 4);
+        GNUNET_CRYPTO_crc16_n ((uint16_t *) & pkt->ip_hdr, 5 * 4);
 
     /* set the udp-header */
     pkt->udp_dns.udp_hdr.spt = htons (53);
@@ -805,7 +805,7 @@ send_icmp4_response (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   response->ip_hdr.tot_lngth = request->ip_hdr.tot_lngth;
 
   response->ip_hdr.chks =
-      calculate_ip_checksum ((uint16_t *) & response->ip_hdr, 20);
+      GNUNET_CRYPTO_crc16_n ((uint16_t *) & response->ip_hdr, 20);
 
   response->icmp_hdr.code = 0;
   response->icmp_hdr.type = 0x0;
@@ -1475,19 +1475,19 @@ receive_udp_back (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel,
     uint32_t sum = 0;
 
     sum =
-        calculate_checksum_update (sum, (uint16_t *) & pkt6->ip6_hdr.sadr, 16);
+        GNUNET_CRYPTO_crc16_step (sum, (uint16_t *) & pkt6->ip6_hdr.sadr, 16);
     sum =
-        calculate_checksum_update (sum, (uint16_t *) & pkt6->ip6_hdr.dadr, 16);
+        GNUNET_CRYPTO_crc16_step (sum, (uint16_t *) & pkt6->ip6_hdr.dadr, 16);
     uint32_t tmp = (pkt6->udp_hdr.len & 0xffff);
 
-    sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
+    sum = GNUNET_CRYPTO_crc16_step (sum, (uint16_t *) & tmp, 4);
     tmp = htons (((pkt6->ip6_hdr.nxthdr & 0x00ff)));
-    sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
+    sum = GNUNET_CRYPTO_crc16_step (sum, (uint16_t *) & tmp, 4);
 
     sum =
-        calculate_checksum_update (sum, (uint16_t *) & pkt6->udp_hdr,
+        GNUNET_CRYPTO_crc16_step (sum, (uint16_t *) & pkt6->udp_hdr,
                                    ntohs (pkt->len));
-    pkt6->udp_hdr.crc = calculate_checksum_end (sum);
+    pkt6->udp_hdr.crc = GNUNET_CRYPTO_crc16_finish (sum);
     
     (void) GNUNET_HELPER_send (helper_handle,
                               &pkt6->shdr,
@@ -1561,7 +1561,7 @@ receive_udp_back (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel,
     pkt4->udp_hdr.crc = 0;      /* Optional for IPv4 */
 
     pkt4->ip_hdr.chks =
-        calculate_ip_checksum ((uint16_t *) & pkt4->ip_hdr, 5 * 4);
+        GNUNET_CRYPTO_crc16_n ((uint16_t *) & pkt4->ip_hdr, 5 * 4);
 
     (void) GNUNET_HELPER_send (helper_handle,
                               &pkt4->shdr,
@@ -1655,18 +1655,18 @@ receive_tcp_back (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel,
     uint32_t tmp;
 
     sum =
-        calculate_checksum_update (sum, (uint16_t *) & pkt6->ip6_hdr.sadr, 16);
+        GNUNET_CRYPTO_crc16_step (sum, (uint16_t *) & pkt6->ip6_hdr.sadr, 16);
     sum =
-        calculate_checksum_update (sum, (uint16_t *) & pkt6->ip6_hdr.dadr, 16);
+        GNUNET_CRYPTO_crc16_step (sum, (uint16_t *) & pkt6->ip6_hdr.dadr, 16);
     tmp = htonl (pktlen);
-    sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
+    sum = GNUNET_CRYPTO_crc16_step (sum, (uint16_t *) & tmp, 4);
     tmp = htonl (((pkt6->ip6_hdr.nxthdr & 0x000000ff)));
-    sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
+    sum = GNUNET_CRYPTO_crc16_step (sum, (uint16_t *) & tmp, 4);
 
     sum =
-        calculate_checksum_update (sum, (uint16_t *) & pkt6->tcp_hdr,
+        GNUNET_CRYPTO_crc16_step (sum, (uint16_t *) & pkt6->tcp_hdr,
                                    ntohs (pkt6->ip6_hdr.paylgth));
-    pkt6->tcp_hdr.crc = calculate_checksum_end (sum);
+    pkt6->tcp_hdr.crc = GNUNET_CRYPTO_crc16_finish (sum);
 
     (void) GNUNET_HELPER_send (helper_handle,
                               &pkt6->shdr,
@@ -1737,20 +1737,20 @@ receive_tcp_back (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel,
     uint32_t sum = 0;
     uint32_t tmp;
 
-    sum = calculate_checksum_update (sum, (uint16_t *) &pkt4->ip_hdr.sadr, 4);
-    sum = calculate_checksum_update (sum, (uint16_t *) &pkt4->ip_hdr.dadr, 4);
+    sum = GNUNET_CRYPTO_crc16_step (sum, (uint16_t *) &pkt4->ip_hdr.sadr, 4);
+    sum = GNUNET_CRYPTO_crc16_step (sum, (uint16_t *) &pkt4->ip_hdr.dadr, 4);
 
     tmp = (0x06 << 16) | (0xffff & pktlen);     // 0x06 for TCP?
 
     tmp = htonl (tmp);
 
-    sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
+    sum = GNUNET_CRYPTO_crc16_step (sum, (uint16_t *) & tmp, 4);
 
-    sum = calculate_checksum_update (sum, (uint16_t *) & pkt4->tcp_hdr, pktlen);
-    pkt4->tcp_hdr.crc = calculate_checksum_end (sum);
+    sum = GNUNET_CRYPTO_crc16_step (sum, (uint16_t *) & pkt4->tcp_hdr, pktlen);
+    pkt4->tcp_hdr.crc = GNUNET_CRYPTO_crc16_finish (sum);
 
     pkt4->ip_hdr.chks =
-        calculate_ip_checksum ((uint16_t *) & pkt4->ip_hdr, 5 * 4);
+        GNUNET_CRYPTO_crc16_n ((uint16_t *) & pkt4->ip_hdr, 5 * 4);
 
     (void) GNUNET_HELPER_send (helper_handle,
                               &pkt4->shdr,
diff --git a/src/vpn/gnunet-vpn-checksum.c b/src/vpn/gnunet-vpn-checksum.c
deleted file mode 100644 (file)
index 0e0e24c..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
-     This file is part of GNUnet.
-     (C) 2010 Christian Grothoff
-
-     GNUnet is free software; you can redistribute it and/or modify
-     it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 3, or (at your
-     option) any later version.
-
-     GNUnet is distributed in the hope that it will be useful, but
-     WITHOUT ANY WARRANTY; without even the implied warranty of
-     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-     General Public License for more details.
-
-     You should have received a copy of the GNU General Public License
-     along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-     Boston, MA 02111-1307, USA.
-*/
-
-/**
- * @file vpn/gnunet-vpn-checksum.c
- * @brief
- * @author Philipp Toelke
- */
-
-#include "gnunet-vpn-checksum.h"
-
-uint32_t
-calculate_checksum_update (uint32_t sum, uint16_t * hdr, short len)
-{
-  for (; len >= 2; len -= 2)
-    sum += *(hdr++);
-  if (len == 1)
-    sum += *((unsigned char *) hdr);
-  return sum;
-}
-
-uint16_t
-calculate_checksum_end (uint32_t sum)
-{
-  while (sum >> 16)
-    sum = (sum >> 16) + (sum & 0xFFFF);
-
-  return ~sum;
-}
-
-/**
- * Calculate the checksum of an IPv4-Header
- */
-uint16_t
-calculate_ip_checksum (uint16_t * hdr, short len)
-{
-  uint32_t sum = calculate_checksum_update (0, hdr, len);
-
-  return calculate_checksum_end (sum);
-}
diff --git a/src/vpn/gnunet-vpn-checksum.h b/src/vpn/gnunet-vpn-checksum.h
deleted file mode 100644 (file)
index 51f0443..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
-     This file is part of GNUnet.
-     (C) 2010 Christian Grothoff
-
-     GNUnet is free software; you can redistribute it and/or modify
-     it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 3, or (at your
-     option) any later version.
-
-     GNUnet is distributed in the hope that it will be useful, but
-     WITHOUT ANY WARRANTY; without even the implied warranty of
-     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-     General Public License for more details.
-
-     You should have received a copy of the GNU General Public License
-     along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-     Boston, MA 02111-1307, USA.
-*/
-#ifndef GNUNET_VPN_CHECKSUM_H
-#define GNUNET_VPN_CHECKSUM_H
-
-#include <platform.h>
-
-uint32_t
-calculate_checksum_update (uint32_t sum, uint16_t * hdr, short len);
-
-uint16_t
-calculate_checksum_end (uint32_t sum);
-
-/**
- * Calculate the checksum of an IPv4-Header
- */
-uint16_t
-calculate_ip_checksum (uint16_t * hdr, short len);
-
-#endif /* end of include guard: GNUNET-VPN-CHECKSUM_H */