Skip to content

Commit

Permalink
move polarssl context to unmanaged heap; fix shadowsocks#32
Browse files Browse the repository at this point in the history
  • Loading branch information
clowwindy committed Nov 11, 2014
1 parent bbbde8a commit aa8e655
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 163 deletions.
26 changes: 13 additions & 13 deletions shadowsocks-csharp/Encrypt/PolarSSL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,55 +7,55 @@ namespace Shadowsocks.Encrypt
{
public class PolarSSL
{
const string DLLNAME = "libpolarssl";
const string DLLNAME = "polarssl";

public const int AES_CTX_SIZE = 8 + 4 * 68;
public const int AES_ENCRYPT = 1;
public const int AES_DECRYPT = 0;

[DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
public extern static void aes_init(byte[] ctx);
public extern static void aes_init(IntPtr ctx);

[DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
public extern static void aes_free(byte[] ctx);
public extern static void aes_free(IntPtr ctx);

[DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
public extern static int aes_setkey_enc(byte[] ctx, byte[] key, int keysize);
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(byte[] ctx, int mode, int length, ref int iv_off, byte[] iv, byte[] input, byte[] output);
public extern static int aes_crypt_cfb128(IntPtr ctx, int mode, int length, byte[] iv_off, byte[] iv, byte[] input, byte[] output);


public const int ARC4_CTX_SIZE = 264;

[DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
public extern static void arc4_init(byte[] ctx);
public extern static void arc4_init(IntPtr ctx);

[DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
public extern static void arc4_free(byte[] ctx);
public extern static void arc4_free(IntPtr ctx);

[DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
public extern static void arc4_setup(byte[] ctx, byte[] key, int keysize);
public extern static void arc4_setup(IntPtr ctx, byte[] key, int keysize);

[DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
public extern static int arc4_crypt(byte[] ctx, int length, byte[] input, byte[] output);
public extern static int arc4_crypt(IntPtr ctx, int length, byte[] input, byte[] output);


public const int BLOWFISH_CTX_SIZE = 4168;
public const int BLOWFISH_ENCRYPT = 1;
public const int BLOWFISH_DECRYPT = 0;

[DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
public extern static void blowfish_init(byte[] ctx);
public extern static void blowfish_init(IntPtr ctx);

[DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
public extern static void blowfish_free(byte[] ctx);
public extern static void blowfish_free(IntPtr ctx);

[DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
public extern static int blowfish_setkey(byte[] ctx, byte[] key, int keysize);
public extern static int blowfish_setkey(IntPtr ctx, byte[] key, int keysize);

[DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
public extern static int blowfish_crypt_cfb64(byte[] ctx, int mode, int length, ref int iv_off, byte[] iv, byte[] input, byte[] output);
public extern static int blowfish_crypt_cfb64(IntPtr ctx, int mode, int length, byte[] iv_off, byte[] iv, byte[] input, byte[] output);

}
}
Loading

0 comments on commit aa8e655

Please sign in to comment.