The lagrangian is L = m/2 xdot^2 - 1/2 k x^2.

p = m x-dot

d/dt(p) = partial of L with respect to x = -kx

The equation of motion is then m x double-dot = ma = -kx.