- Use readonly object as lock
Info from stackoverflow:
If I want to be sure that it will be locked for all threads inside my
application:
The lock object has to be static, if it locks access to static state.
Otherwise it has to be instance, because there's no need to lock state of
one class instance, and prevent other threads to work with another class
instance at the same time.
everyone says that the object has to be "readonly" I didn't found the
reason
Well, it doesn't have to be. This is just a best practice, which helps you
to avoid errors.
Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
- Drop redundant code.
I should read code carefully, mbed TLS will set operation
when invoking mbedtls_cipher_setkey(), the last param
const mbedtls_operation_t operation is what we want.
- minor changes
Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
* Refine encryption
- Add AES-CTR, blowfish and camellia ciphers
aes-256-ctr
aes-192-ctr
aes-128-ctr
bf-cfb
camellia-128-cfb
camellia-192-cfb
camellia-256-cfb
- Merge the previous PolarSSL and MbedTLS
- Switch to MbedTLS's cipher layer functions
- Add workaround to set cipher operation(encrypt/decrypt)
Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
* Add function to get MbedTLS cipher context size
and drop hard-coded ctx sizes
Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
ChaCha20 with an extended (96 bit) nonce and a 32-bit counter has
been implemented as crypto_stream_chacha20_ietf() from LibSodium 1.0.4
Please refer to https://tools.ietf.org/html/rfc7539 for details.
Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
The stock code use class Random to generate IV, the Random is pseudo random number generator. The IV maybe repeat, this will cause shadowsocks-libev closed the sockets with the error message 'invalid password or cipher'. Reference https://github.com/shadowsocks/shadowsocks-libev/issues/389
Solution is use class RNGCryptoServiceProvider to generate IV, of course it's lower performance, but a little bit.