Second-order characterization of convex and pseudoconvex functions