A fast algorithm for computing the characteristic polynomial of the p-curvature