Canonical formalism for relativistic dynamics