Apparently you need to do both increase mass and create a magnetic field. Mars already has a slight magnetic field, but it's not strong enough to protect it.
Sending a comet or asteroid into orbit, thus making a moon could help with the magnetic field.