# How to get the canonical momentum from the velocity when doing a Legendre transform?

For a Lagrangian

$$L=\frac{1}{2}m\dot{q}^2-\frac{1}{2}m\omega^2 q^2$$

the Hamiltonian is defined as

$$H=p\dot{q}-L$$

where $p$ is the canonical momentum, which is defined as $p=\frac{\partial L}{\partial\dot{q}}$. When I calculate this, I get

$$H=\frac{1}{2}m\dot{q}^2+\frac{1}{2}m\omega^2 q^2$$

How can I transform the $m\dot{q}$ into a $p$? I mean, I know that $p=m\dot{q}$, but how is that defined in the formal Legendre transformation?