We give a general derivation of Ginsparg-Wilson relations for both Dirac and Majorana fermions in any dimension. These relations encode continuous and discrete chiral, parity and time reversal anomalies and will apply to the various classes of free fermion topological insulators and superconductors (in the framework of a relativistic quantum field theory in Euclidian spacetime). We show how to formulate the exact symmetries of the lattice action and the relevant index theorems for the anomalies.