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 \
$(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 \
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);
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
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)
{
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);
}
}
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);
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);
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;
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,
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,
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,
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,
+++ /dev/null
-/*
- 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);
-}
+++ /dev/null
-/*
- 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 */