factor out common parts of decctx and encctx to base_context