Beispiel #1
0
 public void Dispose()
 {
     if (this._handle != null)
     {
         _CIPHER.EVP_CIPHER_CTX_cleanup(this._handle);
         _CIPHER.EVP_CIPHER_CTX_free(this._handle);
     }
     this._handle = null;
 }
Beispiel #2
0
        public CIPHER(CType type, CMode mode, bool encrypt)
        {
            EVP_CIPHER *    cipher = null; // Statically allocated (MT), don't free
            EVP_CIPHER_CTX *handle = null;

            try {
                cipher = (EVP_CIPHER *)_ciphers[new Tuple <CType, CMode>(type, mode)]();
            } catch (KeyNotFoundException) {}

            if (cipher == null)
            {
                goto Bailout;
            }

            if ((handle = _CIPHER.EVP_CIPHER_CTX_new()) == null)
            {
                goto Bailout;
            }
            _CIPHER.EVP_CIPHER_CTX_init(handle);
            if (_CIPHER.EVP_CipherInit_ex(handle, cipher, IntPtr.Zero, null, null, encrypt ? 1 : 0) == 0)
            {
                goto Bailout;
            }
            _CIPHER.EVP_CIPHER_CTX_set_padding(handle, 0);

            this._handle  = handle;
            this._type    = type;
            this._mode    = mode;
            this._encrypt = encrypt;

            return;

Bailout:
            if (handle != null)
            {
                _CIPHER.EVP_CIPHER_CTX_free(handle);
            }
            throw new EVPException();
        }
Beispiel #3
0
 public static extern int EVP_CIPHER_CTX_set_iv_length(EVP_CIPHER_CTX *handle, int length);
Beispiel #4
0
 public static extern int EVP_CIPHER_CTX_block_size(EVP_CIPHER_CTX *handle);
Beispiel #5
0
 public static extern int EVP_CIPHER_CTX_iv_length(EVP_CIPHER_CTX *handle);
Beispiel #6
0
 public static extern void EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *handle);
Beispiel #7
0
 public static extern EVP_CIPHER *EVP_CIPHER_CTX_cipher(EVP_CIPHER_CTX *handle);
Beispiel #8
0
 public static extern int EVP_CipherUpdate(EVP_CIPHER_CTX *handle, byte[] outbuf, ref int outlen, byte[] inbuf, int inlen);
Beispiel #9
0
 public static extern int EVP_CipherUpdate(EVP_CIPHER_CTX *handle, IntPtr outbuf, ref int outlen, IntPtr inbuf, int inlen);
Beispiel #10
0
 public static extern int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *handle, int type, int arg, byte[] ptr);
Beispiel #11
0
 public static extern int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *handle, int type, int arg, IntPtr ptr);
Beispiel #12
0
 public static extern int EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *handle, int padding);
Beispiel #13
0
 public static extern int EVP_CipherInit_ex(EVP_CIPHER_CTX *handle, EVP_CIPHER *cipher, IntPtr engine, byte[] key, byte[] iv, int enc);
Beispiel #14
0
 public static extern void EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *handle);
Beispiel #15
0
 public void Dispose()
 {
     if (this._handle != null) {
         _CIPHER.EVP_CIPHER_CTX_cleanup(this._handle);
         _CIPHER.EVP_CIPHER_CTX_free(this._handle);
     }
     this._handle = null;
 }
Beispiel #16
0
 public static extern int EVP_CipherFinal_ex(EVP_CIPHER_CTX *handle, IntPtr outbuf, ref int outlen);
Beispiel #17
0
        public SCIPHER(SType type, bool encrypt)
        {
            EVP_CIPHER *cipher = null; // Statically allocated (MT), don't free
            EVP_CIPHER_CTX *handle = null;

            try {
                cipher = (EVP_CIPHER*) _ciphers[type]();
            } catch (KeyNotFoundException) {}

            if (cipher == null)
                goto Bailout;

            if ((handle = _CIPHER.EVP_CIPHER_CTX_new()) == null)
                goto Bailout;
            _CIPHER.EVP_CIPHER_CTX_init(handle);
            if (_CIPHER.EVP_CipherInit_ex(handle, cipher, IntPtr.Zero, null, null, encrypt ? 1 : 0) == 0)
                goto Bailout;
            _CIPHER.EVP_CIPHER_CTX_set_padding(handle, 0);

            this._handle  = handle;
            this._type    = type;
            this._encrypt = encrypt;

            return ;

        Bailout:
            if (handle != null)
                _CIPHER.EVP_CIPHER_CTX_free(handle);
            throw new EVPException();
        }
Beispiel #18
0
 public static extern void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *handle);