From 4faec81139dd3a8921fb0995602f51cc0994239b Mon Sep 17 00:00:00 2001 From: Paul Flynn Date: Wed, 10 Jul 2024 17:32:15 -0400 Subject: [PATCH] Update Rust backend build settings and function Updated the Rust backend build process and removed superfluous code. The Github Actions workflow will now strip the release binary to reduce its size. The build settings for the Rust backend have been optimized in Cargo.toml and updated the version. In addition, unused code for hashing the shared point's x-coordinate in the main.rs file has been removed. --- .github/workflows/rust.yaml | 1 + Cargo.toml | 8 ++++++-- src/main.rs | 10 +--------- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/.github/workflows/rust.yaml b/.github/workflows/rust.yaml index d8b7ac2..404465c 100644 --- a/.github/workflows/rust.yaml +++ b/.github/workflows/rust.yaml @@ -45,6 +45,7 @@ jobs: source $HOME/.cargo/env rustup target add ${{ matrix.target }} cargo build --release --target ${{ matrix.target }} + strip target/${{ matrix.target }}/release/backend-rust - name: Upload artifact uses: actions/upload-artifact@v4 with: diff --git a/Cargo.toml b/Cargo.toml index 247b6d4..c2fc573 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,10 +1,14 @@ [package] name = "backend-rust" -version = "0.5.0" +version = "0.6.0" edition = "2021" +[profile.release] +target-cpu = "native" +opt-level = 3 +lto = true +codegen-units = 1 # cargo flamegraph -#[profile.release] #debug = true [dependencies] diff --git a/src/main.rs b/src/main.rs index bd0aff3..986746d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,7 +16,7 @@ use p256::{elliptic_curve::sec1::ToEncodedPoint, PublicKey, SecretKey}; use p256::ecdh::EphemeralSecret; use rand_core::{OsRng, RngCore}; use serde::{Deserialize, Serialize}; -use sha2::{Digest, Sha256}; +use sha2::Sha256; use tokio::net::TcpListener; use tokio_native_tls::TlsAcceptor; use tokio_tungstenite::accept_async; @@ -478,16 +478,8 @@ fn custom_ecdh( // Extract the x-coordinate as the shared secret let x_coordinate = shared_point.x(); let shared_secret = x_coordinate.to_vec(); - // println!("Raw shared secret: {}", hex::encode(&shared_secret)); - // Hash the x-coordinate using SHA-256 - let mut hasher = Sha256::new(); - hasher.update(x_coordinate); - // let hashed_secret = hasher.finalize().to_vec(); - - // println!("Hashed shared secret: {}", hex::encode(&hashed_secret)); - Ok(shared_secret) }