Browse Source

Changed from MD5 to CRC16

Stephen Downward 1 year ago
parent
commit
4c657a6be3
2 changed files with 8 additions and 6 deletions
  1. 7 5
      ax26/classes.py
  2. 1 1
      setup.py

+ 7 - 5
ax26/classes.py

@ -1,5 +1,5 @@
1 1
import gzip
2
import hashlib
2
import crcmod
3 3
import time
4 4
from threading import Thread
5 5
@ -28,6 +28,8 @@ class Ax26:
28 28
		self.send_timeout_seconds = 10
29 29
		self.receive_timeout_seconds = 10 #Between chunks
30 30
31
		self._crc = crcmod.mkCrcFun(0x18005, rev=False, initCrc=0xFFFF, xorOut=0x0000)
32
31 33
32 34
		read_thread = Thread(target=self._read_thread)#Start reader thread
33 35
		read_thread.daemon = True
@ -91,7 +93,7 @@ class Ax26:
91 93
		if first_byte is not None:
92 94
			recvd_packet = True
93 95
			(chunk, checksum) = first_byte.rsplit(const.CHECKSUM, 1)
94
			if checksum == hashlib.md5(chunk).hexdigest().encode():
96
			if checksum == str(self._crc(chunk)).encode():
95 97
				fulldata += chunk
96 98
				self._write(dest_filter[0], src_filter[0], const.ACK)  # Have to be len of 1 if first_byte not None
97 99
			else:
@ -122,7 +124,7 @@ class Ax26:
122 124
					start_time = time.time()
123 125
			(chunk, checksum) = body.rsplit(const.CHECKSUM, 1)
124 126
			# print(chunk) # DEBUGGING
125
			if checksum == hashlib.md5(chunk).hexdigest().encode():
127
			if checksum == str(self._crc(chunk)).encode():
126 128
				fulldata += chunk
127 129
				# print(chunk)  # DEBUGGING
128 130
				# Request next
@ -138,7 +140,7 @@ class Ax26:
138 140
	def _raw_send_data(self, data, src, dest):  # TODO: PACKET IDs
139 141
140 142
		# 32 for MD5. 3 for byte delimiters
141
		max_data_chunk_length = self.max_packet_length - (len(src) + len(dest) + 35)
143
		max_data_chunk_length = self.max_packet_length - (len(src) + len(dest) + 16)
142 144
143 145
		# print(gzip.compress(data, 9)) # DEBUGGING
144 146
		data = util.escape_data(gzip.compress(data, 9)) + const.DATA_END  # Compress data and add DATA_END byte
@ -152,7 +154,7 @@ class Ax26:
152 154
153 155
			self._k.write(util.format_header(src, dest) + sep_byte +
154 156
						data[0:max_data_chunk_length] + const.CHECKSUM +
155
						  hashlib.md5(data[0:max_data_chunk_length]).hexdigest().encode())
157
						  str(self._crc(data[0:max_data_chunk_length])).encode())
156 158
			sep_byte = const.DATA_CHUNK
157 159
			# print(html[0:packet_length]) #DEBUGGING
158 160
			ack = False  # Wait for client to acknowledge packet, or resend

+ 1 - 1
setup.py

@ -2,7 +2,7 @@ from distutils.core import setup
2 2
setup(
3 3
  name = 'ax26',
4 4
  packages = ['ax26'],
5
  version = '0.25',
5
  version = '0.3',
6 6
  description = 'AX26 Client/Server library in Python.',
7 7
  author = 'Stephen Downward',
8 8
  author_email = 'stephen@stephendownward.ca',