block/qcow2: refactor encryption code