def op(self, key, iv, enc=1):
        """Initializes a cipher operation, either encrypt or decrypt 
        and returns a CipherOperation object

        Args:
            key (str): the block cipher symmetric key. Length depends on block cipher choice.
            iv (str): an Initialization Vector of up to the block size. (Can be shorter.)
            enc (int): set to 1 to perform encryption, or 0 to perform decryption.

        """
        c_op = CipherOperation(enc)
        _check( len(key) == self.len_key())
        _check( enc in [0,1] )
       
        if not self.gcm:
            _check( len(iv) == self.len_IV())
            _check( _C.EVP_CipherInit_ex(c_op.ctx, 
                self.alg,  _FFI.NULL, key, iv, enc) )

        else:
            

            _check( _C.EVP_CipherInit_ex(c_op.ctx, 
                self.alg,  _FFI.NULL, _FFI.NULL, _FFI.NULL, enc) )

            # assert len(iv) <= self.len_block()

            _check( _C.EVP_CIPHER_CTX_ctrl(c_op.ctx, 
                _C.EVP_CTRL_GCM_SET_IVLEN, len(iv), _FFI.NULL))

            _C.EVP_CIPHER_CTX_ctrl(c_op.ctx, _C.EVP_CTRL_GCM_SET_IV_FIXED, -1, iv);
            _C.EVP_CIPHER_CTX_ctrl(c_op.ctx, _C.EVP_CTRL_GCM_IV_GEN, 0, iv)

            _check( _C.EVP_CipherInit_ex(c_op.ctx, 
                _FFI.NULL,  _FFI.NULL, key, iv, enc) )

        c_op.cipher = self
        return c_op
dataset/ETHPy150Open gdanezis/petlib/petlib/cipher.py/Cipher.op/original