sha3 -> crc32

serve missing packet requests in rust server
This commit is contained in:
Mystikfluu
2023-05-30 17:03:44 +02:00
parent 85386d11fb
commit c1e4b3cd7a
8 changed files with 70 additions and 72 deletions
+1 -1
View File
@@ -63,6 +63,6 @@ macro_rules! big_array {
}
big_array! {
40, 48, 50, 56, 64, 72, 96, 100, 128, 160, 192, 200, 224, 256, 384, 488, 512,
40, 48, 50, 56, 64, 72, 96, 100, 128, 160, 192, 200, 224, 256, 384, 488, 500, 512,
768, 1024, 2048, 4096, 8192, 16384, 32768, 65536,
}
+8 -10
View File
@@ -1,16 +1,16 @@
use bincode::{self, Error, options, Options};
use std::{net::{UdpSocket, SocketAddr}, io::Write};
use serde::{Serialize, Deserialize};
use sha3::{Digest, Sha3_512};
use sha2::Sha512;
use sha2::{Digest, Sha512};
use std::io::{self, BufRead};
use crc32fast;
mod big_array;
use big_array::BigArray;
const MAX_FRAME_PAYLOAD:u16=508;
const MAX_FRAME_PAYLOAD_U:usize=MAX_FRAME_PAYLOAD as usize;
const HEADER_SIZE:u16 = 20;
const HEADER_SIZE:u16 = 8;
const MAX_PAYLOAD:u16 = MAX_FRAME_PAYLOAD - HEADER_SIZE;
const MAX_PAYLOAD_U:usize = MAX_PAYLOAD as usize;
@@ -24,10 +24,10 @@ struct PacketInformation {
#[derive(Serialize, Deserialize)]
struct Packet {
packet_number: u32, //4 bytes
payload_hash: [u8; 16], //16 bytes
payload_hash: [u8; 4], //4 bytes
#[serde(with = "BigArray")]
payload: [u8; MAX_PAYLOAD_U], //488 bytes
} //512 bytes
payload: [u8; MAX_PAYLOAD_U],
} //508 bytes
fn read_stdin(message: String) -> String {
print!("{}", message);
@@ -150,11 +150,9 @@ fn main() {
//println!("Packet {}", p.packet_number);
//check checksum with sum
if p.packet_number != packet_info.packet_numbers - 1 {
let mut hasher = Sha3_512::new();
hasher.update(&p.payload);
let hash = hasher.finalize();
let hash = crc32fast::hash(&p.payload);
if p.payload_hash != hash[..16] {
if p.payload_hash != hash.to_be_bytes() {
continue;
}