An algebraic criterion for the choosability of graphs