On the Origin of Pulsar and Magnetar Magnetic Fields