diff --git a/shadowsocks-csharp/Encrypt/PolarSSL.cs b/shadowsocks-csharp/Encrypt/PolarSSL.cs index 2ccf35ac..ac1592f0 100755 --- a/shadowsocks-csharp/Encrypt/PolarSSL.cs +++ b/shadowsocks-csharp/Encrypt/PolarSSL.cs @@ -23,7 +23,7 @@ namespace Shadowsocks.Encrypt public extern static int aes_setkey_enc(IntPtr ctx, byte[] key, int keysize); [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)] - public extern static int aes_crypt_cfb128(IntPtr ctx, int mode, int length, byte[] iv_off, byte[] iv, byte[] input, byte[] output); + public extern static int aes_crypt_cfb128(IntPtr ctx, int mode, int length, ref int iv_off, byte[] iv, byte[] input, byte[] output); public const int ARC4_CTX_SIZE = 264; @@ -55,7 +55,7 @@ namespace Shadowsocks.Encrypt public extern static int blowfish_setkey(IntPtr ctx, byte[] key, int keysize); [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)] - public extern static int blowfish_crypt_cfb64(IntPtr ctx, int mode, int length, byte[] iv_off, byte[] iv, byte[] input, byte[] output); + public extern static int blowfish_crypt_cfb64(IntPtr ctx, int mode, int length, ref int iv_off, byte[] iv, byte[] input, byte[] output); } } diff --git a/shadowsocks-csharp/Encrypt/PolarSSLEncryptor.cs b/shadowsocks-csharp/Encrypt/PolarSSLEncryptor.cs index c10ae6d4..7b369130 100755 --- a/shadowsocks-csharp/Encrypt/PolarSSLEncryptor.cs +++ b/shadowsocks-csharp/Encrypt/PolarSSLEncryptor.cs @@ -31,8 +31,8 @@ namespace Shadowsocks.Encrypt private IntPtr _decryptCtx = IntPtr.Zero; private byte[] _encryptIV; private byte[] _decryptIV; - private byte[] _encryptIVOffset; - private byte[] _decryptIVOffset; + private int _encryptIVOffset = 0; + private int _decryptIVOffset = 0; private string _method; private int keyLen; private int ivLen; @@ -125,13 +125,11 @@ namespace Shadowsocks.Encrypt if (isCipher) { _encryptIV = new byte[ivLen]; - _encryptIVOffset = new byte[8]; Array.Copy(iv, _encryptIV, ivLen); } else { _decryptIV = new byte[ivLen]; - _decryptIVOffset = new byte[8]; Array.Copy(iv, _decryptIV, ivLen); } } @@ -143,13 +141,11 @@ namespace Shadowsocks.Encrypt if (isCipher) { _encryptIV = new byte[ivLen]; - _encryptIVOffset = new byte[8]; Array.Copy(iv, _encryptIV, ivLen); } else { _decryptIV = new byte[ivLen]; - _decryptIVOffset = new byte[8]; Array.Copy(iv, _decryptIV, ivLen); } } @@ -182,10 +178,10 @@ namespace Shadowsocks.Encrypt switch (_cipher) { case CIPHER_AES: - PolarSSL.aes_crypt_cfb128(_encryptCtx, PolarSSL.AES_ENCRYPT, length, _encryptIVOffset, _encryptIV, buf, tempbuf); + PolarSSL.aes_crypt_cfb128(_encryptCtx, PolarSSL.AES_ENCRYPT, length, ref _encryptIVOffset, _encryptIV, buf, tempbuf); break; case CIPHER_BF: - PolarSSL.blowfish_crypt_cfb64(_encryptCtx, PolarSSL.BLOWFISH_ENCRYPT, length, _encryptIVOffset, _encryptIV, buf, tempbuf); + PolarSSL.blowfish_crypt_cfb64(_encryptCtx, PolarSSL.BLOWFISH_ENCRYPT, length, ref _encryptIVOffset, _encryptIV, buf, tempbuf); break; case CIPHER_RC4: PolarSSL.arc4_crypt(_encryptCtx, length, buf, tempbuf); @@ -206,10 +202,10 @@ namespace Shadowsocks.Encrypt switch (_cipher) { case CIPHER_AES: - PolarSSL.aes_crypt_cfb128(_encryptCtx, PolarSSL.AES_ENCRYPT, length, _encryptIVOffset, _encryptIV, buf, outbuf); + PolarSSL.aes_crypt_cfb128(_encryptCtx, PolarSSL.AES_ENCRYPT, length, ref _encryptIVOffset, _encryptIV, buf, outbuf); break; case CIPHER_BF: - PolarSSL.blowfish_crypt_cfb64(_encryptCtx, PolarSSL.BLOWFISH_ENCRYPT, length, _encryptIVOffset, _encryptIV, buf, outbuf); + PolarSSL.blowfish_crypt_cfb64(_encryptCtx, PolarSSL.BLOWFISH_ENCRYPT, length, ref _encryptIVOffset, _encryptIV, buf, outbuf); break; case CIPHER_RC4: PolarSSL.arc4_crypt(_encryptCtx, length, buf, outbuf); @@ -235,10 +231,10 @@ namespace Shadowsocks.Encrypt switch (_cipher) { case CIPHER_AES: - PolarSSL.aes_crypt_cfb128(_decryptCtx, PolarSSL.AES_DECRYPT, length - ivLen, _decryptIVOffset, _decryptIV, tempbuf, outbuf); + PolarSSL.aes_crypt_cfb128(_decryptCtx, PolarSSL.AES_DECRYPT, length - ivLen, ref _decryptIVOffset, _decryptIV, tempbuf, outbuf); break; case CIPHER_BF: - PolarSSL.blowfish_crypt_cfb64(_decryptCtx, PolarSSL.BLOWFISH_DECRYPT, length - ivLen, _decryptIVOffset, _decryptIV, tempbuf, outbuf); + PolarSSL.blowfish_crypt_cfb64(_decryptCtx, PolarSSL.BLOWFISH_DECRYPT, length - ivLen, ref _decryptIVOffset, _decryptIV, tempbuf, outbuf); break; case CIPHER_RC4: PolarSSL.arc4_crypt(_decryptCtx, length - ivLen, tempbuf, outbuf); @@ -256,10 +252,10 @@ namespace Shadowsocks.Encrypt switch (_cipher) { case CIPHER_AES: - PolarSSL.aes_crypt_cfb128(_decryptCtx, PolarSSL.AES_DECRYPT, length, _decryptIVOffset, _decryptIV, buf, outbuf); + PolarSSL.aes_crypt_cfb128(_decryptCtx, PolarSSL.AES_DECRYPT, length, ref _decryptIVOffset, _decryptIV, buf, outbuf); break; case CIPHER_BF: - PolarSSL.blowfish_crypt_cfb64(_decryptCtx, PolarSSL.BLOWFISH_DECRYPT, length, _decryptIVOffset, _decryptIV, buf, outbuf); + PolarSSL.blowfish_crypt_cfb64(_decryptCtx, PolarSSL.BLOWFISH_DECRYPT, length, ref _decryptIVOffset, _decryptIV, buf, outbuf); break; case CIPHER_RC4: PolarSSL.arc4_crypt(_decryptCtx, length, buf, outbuf);