/* This function initializes a 3DES encryption algorithm, i.e. fills the psCipherContext_t structure pointed to by ctx with necessary data.  */
int tls_crypto_3des_init(psCipherContext_t *ctx, const unsigned char *IV, const unsigned char *key, u32 keylen, CRYPTO_MODE cbc)
/* This function initializes a 3DES encryption algorithm, i.e. fills the psCipherContext_t structure pointed to by ctx with necessary data.  */
int tls_crypto_3des_init(psCipherContext_t *ctx, const unsigned char *IV, const unsigned char *key, u32 keylen, CRYPTO_MODE cbc)
{
    unsigned int x;
    if (keylen != DES3_KEY_LEN)
        return ERR_FAILURE;
    memcpy(ctx->des3.key.ek[0], key, keylen);
    ctx->des3.key.ek[1][0] =  cbc;
    ctx->des3.blocklen = DES3_IV_LEN;
	if(IV)
	{
	    for (x = 0; x < ctx->des3.blocklen; x++)
	    {
	        ctx->des3.IV[x] = IV[x];
	    }
	}
    return ERR_CRY_OK;
}