diff --git a/shadowsocks-csharp/Encryption/MbedTLS.cs b/shadowsocks-csharp/Encryption/MbedTLS.cs index d29b26e5..01f8fd37 100644 --- a/shadowsocks-csharp/Encryption/MbedTLS.cs +++ b/shadowsocks-csharp/Encryption/MbedTLS.cs @@ -51,7 +51,7 @@ namespace Shadowsocks.Encryption [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)] public static extern int cipher_setup(IntPtr ctx, IntPtr cipher_info); - // check operation + // XXX: Check operation before using it [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)] public static extern int cipher_setkey(IntPtr ctx, byte[] key, int key_bitlen, int operation); @@ -70,9 +70,6 @@ namespace Shadowsocks.Encryption [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)] public static extern void md5(byte[] input, uint ilen, byte[] output); - [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)] - public static extern void cipher_set_operation_ex(IntPtr ctx, int operation); - [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)] public static extern int cipher_get_size_ex(); } diff --git a/shadowsocks-csharp/Encryption/MbedTLSEncryptor.cs b/shadowsocks-csharp/Encryption/MbedTLSEncryptor.cs index 969b9dd2..0d657f34 100644 --- a/shadowsocks-csharp/Encryption/MbedTLSEncryptor.cs +++ b/shadowsocks-csharp/Encryption/MbedTLSEncryptor.cs @@ -76,8 +76,17 @@ namespace Shadowsocks.Encryption MbedTLS.cipher_init(ctx); if (MbedTLS.cipher_setup( ctx, MbedTLS.cipher_info_from_string( _cipherMbedName ) ) != 0 ) throw new Exception(); - // MbedTLS takes key length by bit - // cipher_setkey() will set the correct key schedule + /* + * MbedTLS takes key length by bit + * cipher_setkey() will set the correct key schedule + * and operation + * + * MBEDTLS_AES_{EN,DE}CRYPT + * == MBEDTLS_BLOWFISH_{EN,DE}CRYPT + * == MBEDTLS_CAMELLIA_{EN,DE}CRYPT + * == MBEDTLS_{EN,DE}CRYPT + * + */ if (MbedTLS.cipher_setkey(ctx, realkey, keyLen * 8, isCipher ? MbedTLS.MBEDTLS_ENCRYPT : MbedTLS.MBEDTLS_DECRYPT) != 0 ) throw new Exception(); if (MbedTLS.cipher_set_iv(ctx, iv, ivLen) != 0) @@ -102,23 +111,6 @@ namespace Shadowsocks.Encryption { ctx = _decryptCtx; } - - if (_cipher == CIPHER_AES - || _cipher == CIPHER_BLOWFISH - || _cipher == CIPHER_CAMELLIA) - { - /* - * operation workaround - * - * MBEDTLS_AES_{EN,DE}CRYPT - * == MBEDTLS_BLOWFISH_{EN,DE}CRYPT - * == MBEDTLS_CAMELLIA_{EN,DE}CRYPT - * == MBEDTLS_{EN,DE}CRYPT - * setter code in C: - * ctx->operation = operation; - */ - MbedTLS.cipher_set_operation_ex(ctx, isCipher ? MbedTLS.MBEDTLS_ENCRYPT : MbedTLS.MBEDTLS_DECRYPT); - } if (MbedTLS.cipher_update(ctx, buf, length, outbuf, ref length) != 0 ) throw new Exception(); } diff --git a/shadowsocks-csharp/Encryption/Sodium.cs b/shadowsocks-csharp/Encryption/Sodium.cs index 3d20bdea..22a7b7a7 100755 --- a/shadowsocks-csharp/Encryption/Sodium.cs +++ b/shadowsocks-csharp/Encryption/Sodium.cs @@ -33,16 +33,16 @@ namespace Shadowsocks.Encryption private static extern IntPtr LoadLibrary(string path); [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)] - public extern static int crypto_stream_salsa20_xor_ic(byte[] c, byte[] m, ulong mlen, byte[] n, ulong ic, byte[] k); + public static extern int crypto_stream_salsa20_xor_ic(byte[] c, byte[] m, ulong mlen, byte[] n, ulong ic, byte[] k); [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)] - public extern static int crypto_stream_chacha20_xor_ic(byte[] c, byte[] m, ulong mlen, byte[] n, ulong ic, byte[] k); + public static extern int crypto_stream_chacha20_xor_ic(byte[] c, byte[] m, ulong mlen, byte[] n, ulong ic, byte[] k); [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)] - public extern static int crypto_stream_chacha20_ietf_xor_ic(byte[] c, byte[] m, ulong mlen, byte[] n, uint ic, byte[] k); + public static extern int crypto_stream_chacha20_ietf_xor_ic(byte[] c, byte[] m, ulong mlen, byte[] n, uint ic, byte[] k); [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)] - public extern static void ss_sha1_hmac_ex(byte[] key, uint keylen, + public static extern void ss_sha1_hmac_ex(byte[] key, uint keylen, byte[] input, int ioff, uint ilen, byte[] output); } diff --git a/shadowsocks-csharp/View/ConfigForm.Designer.cs b/shadowsocks-csharp/View/ConfigForm.Designer.cs index 50207095..e6a15915 100755 --- a/shadowsocks-csharp/View/ConfigForm.Designer.cs +++ b/shadowsocks-csharp/View/ConfigForm.Designer.cs @@ -211,7 +211,7 @@ "bf-cfb", "camellia-128-cfb", "camellia-192-cfb", - "camellia-256-cfb",}); + "camellia-256-cfb"}); this.EncryptionSelect.Location = new System.Drawing.Point(83, 87); this.EncryptionSelect.Name = "EncryptionSelect"; this.EncryptionSelect.Size = new System.Drawing.Size(160, 20);