Ab initio calculation of the elastic constants of magnesium