We describe deterministic and probabilistic algorithms to determine whether or not a given monic irreducible polynomial
H
∈
Z
[
X
]
H\in \mathbb {Z}[X]
is a Hilbert class polynomial, and if so, which one. These algorithms can be used to determine whether a given algebraic integer is the
j
j
-invariant of an elliptic curve with complex multiplication (CM), and if so, the associated CM discriminant. More generally, given an elliptic curve
E
E
over a number field, one can use them to compute the endomorphism ring of
E
E
. Our algorithms admit simple implementations that are asymptotically and practically faster than previous approaches.