sha3 -> crc32
serve missing packet requests in rust server
This commit is contained in:
Generated
+10
-20
@@ -41,6 +41,15 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crc32fast"
|
||||
version = "1.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crypto-common"
|
||||
version = "0.1.6"
|
||||
@@ -77,18 +86,9 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"bincode",
|
||||
"byteorder",
|
||||
"crc32fast",
|
||||
"serde",
|
||||
"sha2",
|
||||
"sha3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "keccak"
|
||||
version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8f6d5ed8676d904364de097082f4e7d240b571b67989ced0240f08b7f966f940"
|
||||
dependencies = [
|
||||
"cpufeatures",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -146,16 +146,6 @@ dependencies = [
|
||||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sha3"
|
||||
version = "0.10.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "75872d278a8f37ef87fa0ddbda7802605cb18344497949862c0d4dcb291eba60"
|
||||
dependencies = [
|
||||
"digest",
|
||||
"keccak",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.16"
|
||||
|
||||
@@ -9,8 +9,8 @@ edition = "2021"
|
||||
bincode = "1.3.3"
|
||||
serde = { version = "1.0.163", features = ["serde_derive"], default-features = false }
|
||||
byteorder = { default-features = false, version = "1.4.3" }
|
||||
sha3 = { default-features = false, version = "0.10.8" }
|
||||
sha2 = { default-features = false, version = "0.10.6" }
|
||||
crc32fast = { default-features = false, version = "1.3.2" }
|
||||
|
||||
[profile.release]
|
||||
lto = true # Enable link-time optimization
|
||||
|
||||
@@ -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
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user