From 7ee43569484af28d8df5bbe8a274b738ec9b0b80 Mon Sep 17 00:00:00 2001 From: "Y. T. Chung" Date: Thu, 31 Aug 2017 22:10:05 +0800 Subject: [PATCH] Bump to v1.6.4, add missing sodium_init() call --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/crypto/sodium.rs | 10 +++++++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2311f231..01598ca0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ [root] name = "shadowsocks-rust" -version = "1.6.3" +version = "1.6.4" dependencies = [ "base64 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "byte_string 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index f29374b2..74685928 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "shadowsocks-rust" -version = "1.6.3" +version = "1.6.4" authors = ["Y. T. CHUNG "] description = "shadowsocks is a fast tunnel proxy that helps you bypass firewalls." repository = "https://github.com/zonyitoo/shadowsocks-rust" diff --git a/src/crypto/sodium.rs b/src/crypto/sodium.rs index 3ed50ba7..296221db 100644 --- a/src/crypto/sodium.rs +++ b/src/crypto/sodium.rs @@ -1,15 +1,19 @@ //! Cipher defined with libsodium +use std::sync::{ONCE_INIT, Once}; + use bytes::{BufMut, BytesMut}; use crypto::{CipherResult, CipherType, StreamCipher}; use libc::c_ulonglong; use libsodium_ffi::{crypto_stream_aes128ctr_xor, crypto_stream_chacha20_ietf_xor_ic, crypto_stream_chacha20_xor_ic, - crypto_stream_salsa20_xor_ic, crypto_stream_xsalsa20_xor_ic}; + crypto_stream_salsa20_xor_ic, crypto_stream_xsalsa20_xor_ic, sodium_init}; use crypto::cipher::Error; +static SODIUM_INIT_FLAG: Once = ONCE_INIT; + /// Cipher provided by Rust-Crypto pub struct SodiumCipher { cipher_type: CipherType, @@ -32,6 +36,10 @@ impl SodiumCipher { _ => panic!("sodium cipher does not support {:?} cipher", t), } + SODIUM_INIT_FLAG.call_once(|| unsafe { + assert_eq!(sodium_init(), 0); + }); + SodiumCipher { cipher_type: t, key: key.to_owned(),