Skip to content

Commit

Permalink
Bump dependencies (#75)
Browse files Browse the repository at this point in the history
* bump dependencies

* clippy fix

* fmt
  • Loading branch information
kigawas authored Nov 16, 2021
1 parent ece2783 commit d52e2c0
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 20 deletions.
1 change: 0 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"rust-analyzer.cargo.features": ["pure"],
"rust-analyzer.cargo.noDefaultFeatures": true,
"rust-analyzer.procMacro.enable": true,
"rust-analyzer.cargo.loadOutDirsFromCheck": true,
"spellright.ignoreFiles": [
"~/.cargo/",
"~/.rustup/",
Expand Down
2 changes: 2 additions & 0 deletions .vscode/spellright.dict
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ typenum
rs
ecc
rt
js
getrandom
19 changes: 10 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.2.1"
# docs
authors = ["Weiliang Li <[email protected]>"]
description = "Elliptic Curve Integrated Encryption Scheme for secp256k1 in Rust"
edition = "2018"
edition = "2021"
keywords = [
"secp256k1",
"crypto",
Expand All @@ -21,8 +21,8 @@ repository = "https://github.com/ecies/rs"

[dependencies]
hkdf = "0.11.0"
secp256k1 = { package = "libsecp256k1", version = "0.6" }
sha2 = "0.9.2"
libsecp256k1 = "0.7.0"
sha2 = "0.9.8"

# openssl aes
openssl = {version = "0.10.32", optional = true}
Expand All @@ -32,10 +32,11 @@ aes-gcm = {version = "0.9.0", optional = true}
typenum = {version = "1.12.0", optional = true}

[target.'cfg(target_arch = "wasm32")'.dependencies]
rand = {version = "0.7.3", features = ["wasm-bindgen"]}
getrandom = {version = "0.2.3", features = ["js"]}
rand = {version = "0.8.4", features = ["getrandom"]}

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
rand = {version = "0.7.3"}
rand = {version = "0.8.4"}

[features]
default = ["openssl"]
Expand All @@ -46,12 +47,12 @@ criterion = "0.3.3"
hex = "0.4.2"

[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
wasm-bindgen-test = "0.3.19"
wasm-bindgen-test = "0.3.28"

[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
futures-util = "0.3.8"
reqwest = "0.11.0"
tokio = {version = "1.0.1", features = ["rt-multi-thread"]}
futures-util = "0.3.17"
reqwest = "0.11.6"
tokio = {version = "1.13.0", features = ["rt-multi-thread"]}

[[bench]]
harness = false
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
//!
//! It's also possible to build to the `wasm32-unknown-unknown` target with the pure Rust backend. Check out [this repo](https://github.com/ecies/rs-wasm) for more details.
pub use secp256k1::{util::FULL_PUBLIC_KEY_SIZE, Error as SecpError, PublicKey, SecretKey};
pub use libsecp256k1::{util::FULL_PUBLIC_KEY_SIZE, Error as SecpError, PublicKey, SecretKey};

/// Constant variables
pub mod consts;
Expand Down
2 changes: 1 addition & 1 deletion src/openssl_aes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ pub fn aes_decrypt(key: &[u8], encrypted_msg: &[u8]) -> Option<Vec<u8>> {
let tag = &encrypted_msg[AES_IV_LENGTH..AES_IV_PLUS_TAG_LENGTH];
let encrypted = &encrypted_msg[AES_IV_PLUS_TAG_LENGTH..];

decrypt_aead(cipher, key, Some(&iv), &EMPTY_BYTES, encrypted, tag).ok()
decrypt_aead(cipher, key, Some(iv), &EMPTY_BYTES, encrypted, tag).ok()
}
16 changes: 8 additions & 8 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use hkdf::Hkdf;
use libsecp256k1::{util::FULL_PUBLIC_KEY_SIZE, Error as SecpError, PublicKey, SecretKey};
use rand::thread_rng;
use secp256k1::{util::FULL_PUBLIC_KEY_SIZE, Error as SecpError, PublicKey, SecretKey};
use sha2::Sha256;

use crate::consts::EMPTY_BYTES;
Expand All @@ -15,25 +15,25 @@ pub use crate::openssl_aes::{aes_decrypt, aes_encrypt};
/// Generate a `(SecretKey, PublicKey)` pair
pub fn generate_keypair() -> (SecretKey, PublicKey) {
let sk = SecretKey::random(&mut thread_rng());
(sk.clone(), PublicKey::from_secret_key(&sk))
(sk, PublicKey::from_secret_key(&sk))
}

/// Calculate a shared AES key of our secret key and peer's public key by hkdf
pub fn encapsulate(sk: &SecretKey, peer_pk: &PublicKey) -> Result<AesKey, SecpError> {
let mut shared_point = peer_pk.clone();
shared_point.tweak_mul_assign(&sk)?;
let mut shared_point = *peer_pk;
shared_point.tweak_mul_assign(sk)?;

let mut master = Vec::with_capacity(FULL_PUBLIC_KEY_SIZE * 2);
master.extend(PublicKey::from_secret_key(&sk).serialize().iter());
master.extend(PublicKey::from_secret_key(sk).serialize().iter());
master.extend(shared_point.serialize().iter());

hkdf_sha256(master.as_slice())
}

/// Calculate a shared AES key of our public key and peer's secret key by hkdf
pub fn decapsulate(pk: &PublicKey, peer_sk: &SecretKey) -> Result<AesKey, SecpError> {
let mut shared_point = pk.clone();
shared_point.tweak_mul_assign(&peer_sk)?;
let mut shared_point = *pk;
shared_point.tweak_mul_assign(peer_sk)?;

let mut master = Vec::with_capacity(FULL_PUBLIC_KEY_SIZE * 2);
master.extend(pk.serialize().iter());
Expand All @@ -55,8 +55,8 @@ fn hkdf_sha256(master: &[u8]) -> Result<AesKey, SecpError> {
pub(crate) mod tests {
use hex::decode;

use libsecp256k1::Error;
use rand::{thread_rng, Rng};
use secp256k1::Error;

use super::*;
use crate::consts::{AES_IV_LENGTH, EMPTY_BYTES};
Expand Down

0 comments on commit d52e2c0

Please sign in to comment.