  In this paper we introduce and study a family $\Phi_k$ of arithmetic
functions generalizing Euler's totient function. These functions are given by
the number of solutions to the equation $\gcd(x_1^2+\ldots +x_k^2, n)=1$ with
$x_1,\ldots,x_k \in {\mathbb{Z}}/n{\mathbb{Z}}$ which, for $k=2,4$ and $8$
coincide, respectively, with the number of units in the rings of Gaussian
integers, quaternions and octonions over ${\mathbb{Z}}/n{\mathbb{Z}}$. We prove
that $\Phi_k$ is multiplicative for every $k$, we obtain an explicit formula
for $\Phi_k(n)$ in terms of the prime-power decomposition of $n$ and derive an
asymptotic formula for $\sum_{n\le x} \Phi_k(n)$. As a tool we investigate the
multiplicative arithmetic function that counts the number of solutions to
$x_1^2+\ldots +x_k^2\equiv \lambda$ (mod $n$) for $\lambda$ coprime to $n$,
thus extending an old result that dealt only with the prime $n$ case.
