Primes congruent to $1$ mod $4$ are sum of two squares Neukirch mentions in his book on Algebraic Number Theory that the primes $\equiv 1\pmod 4$ are sums of squares, and it is not so obvious (compared to converse). While going for proof of it myself, I came to a problem; there could be similar questions, but I am interested in proceeding one step to complete proof which I was working.
Let $p\equiv 1\pmod 4$, and assume $p$ is odd. Then $4$ divides $(p-1)$, which is order of cyclic group $(\mathbb{Z}/p\mathbb{Z})^{\times}$. This gives that $-1$ is square mod $p$, say $a^2\equiv -1\pmod p$ i.e. $p$ divides $(a^2+1)$ for some integer $a$.
Case 1. $p$ is reducible in $\mathbb{Z}[i]$.
Say $p=(a+bi)(c+di)$ in $\mathbb{Z}[i]$, where factors are non-units.
Then we also have $p=(a-bi)(c-di)$, so $p^2=(a^2+b^2)(c^2+d^2)$.
Thus $a^2+b^2, c^2+d^2\in \{1,p,p^2\}$.
If $a^2+b^2$ is $1$ or $p^2$, then it is easy to see that $a+bi$ or $c+di$ are units (respectively), contradiction.
Thus, $a^2+b^2$ must be $p$, which is what we wanted to prove. But we did it only in one case.
Case 2. $p$ is irreducible in $\mathbb{Z}[i]$.
This case, I was unable to proceed, and I do not know whether we get a contradiction, or not. Any hint for this case?

Here is a simple proof.
Suppose that $p \in \mathbb{Z}$ $\nmid$ $m + i$ or $m - i$ (as it does not divide their imaginary parts), but that $p \mid m^2 + 1$. Then we know that $p$ cannot be prime in the Gaussian integers. Thus, there exists a nontrivial factorization of $p$ in the Gaussian integers, which can have only two factors (since the norm is multiplicative, and $p^2 = N(p)$), there are at most $2$ factors of $p$, so it must be of the form $$p = (x + yi)(x - yi)$$ for some $x,\:y \in \mathbb{Z}$. Therefore, we have that $p = x^2 + y^2$.
If you are interested, you can see a collection of proofs here.
