One may quickly compute a representation of a prime $\rm\:p\equiv 1\ (mod\ 4)\:$ as a sum of two squares by employing the Euclidean GCD algorithm in $\rm\mathbb Z[\:i\:]\:$ and an algorithm for computing square roots $\rm\:(mod\ p)\:$.
THEOREM $\ $ Let $\rm\ \: c = \sqrt{-1}\ \:(mod\ p)\ $ and $\rm\ gcd(p,\:i-c)\: = \: a+b\:i\ $.$\ $ Then $\rm\ p = a^2 + b^2\:$.
Proof $\ $ We shall show: $\:$(1)$\ $ Representing $\rm\: p\:$ as a sum of squares is equivalent to finding a proper splitting $\rm\: p = \alpha\:\beta\ $ in $\rm\: \mathbb Z[\:i\:]\:$. $\ $(2)$\ $ Since $\rm\: \mathbb Z[\:i\:]\:$ has a Euclidean algorithm, a proper splitting of $\rm\: p\:$ can be computed by GCD with a suitable splitting of some multiple of $\rm\: p\ $. (3)$\ \:$ A suitable splitting of some multiple of $\rm\: p\:$ arises by factoring $\rm\ \: x^2+1\ \ (mod\ p\:)\:$,$\ $ i.e.$\ $ by computing $\rm\ \ \sqrt{-1}\ \ (mod\ p\:)\:$. $\:$ Below are the proofs.
(1) $\:$ If $\rm\:\alpha|p\ $ properly then, conjugating, $\rm\:\alpha'|p\ $ properly. Multiplying them yields $\rm\:\alpha\:\alpha'|p^2\:$ properly in $\:\mathbb Z\:$. But in $\rm\mathbb{Z}\:$ the only proper factor$>0$ of $\rm\:p^2\:$ is $\rm\: p\:$, thus $\rm\: p = \alpha\:\alpha' = (a+b\:i)(a-b\:i) = a^2 + b^2\:$.
(2) $\ $ If $\rm\ p\ \gamma \:=\: \alpha\:\beta\ $ and $\rm\:p\:$ does not divide $\rm\:\alpha\:$ nor $\rm\:\beta\:$,$\ $ then $\rm\: gcd(\alpha,p)\:$ is a $\:$ proper$\ $ factor of $\rm\:p\ $.
Else $\rm\ gcd(\alpha,p) = p\:$ or $1$. If the gcd is $\rm p$ then $\rm\: p\:|\:\alpha\:$ contra hypothesis. Otherwise, if $\rm\ gcd(\alpha,p)=1\ $ then by Euclid's Lemma, $\rm\ \alpha\:|\:p\:\gamma \ \Rightarrow\ \alpha\:|\:\gamma\:$,$\ $ so $\rm\ \gamma/\alpha = \beta/p\ \Rightarrow\ p\:|\:\beta\:$,$\ $ again contra hypothesis. Note: generally, in rings, GCDs are unique only up to unit multiples. Here the units are $\rm\ i^n = \pm 1,\:\pm i\:$.
(3) $\rm\ \ x^2 + 1 \ =\ (x-c)\:(x+c) + p\ f(x)\ $ in $\rm\mathbb\ Z[x]\ \: \Rightarrow\: -p\ f(i)\ =\ (i-c)\:(i+c)\ $ in $\rm\mathbb\ Z[\:i\:]\ \ $ by evaluation at $\rm\: x = i\:$. This splitting is suitable to split $\rm\:p\:$ by (2) since $\rm\:p\:$ doesn't divide $\rm\: i\pm c\ \:$ in $\rm\ \: Z[\:i\:]\:$.
REMARK $\ $ There are many variations on the Euclidean algorithm in $\rm\mathbb \ Z[\:i\:]\ $ that are employed in practice, e.g. employing continued fractions, binary quadratic forms, etc. Also, there are also at least a few algorithms for computing sqrts $\rm\:(mod\ p)\:$, e.g. by factoring polynomials $\rm\:(mod\ p)\:$, by elliptic curves (Schoof), and and algorithm of Tonelli and Shanks. For much further information see Henri Cohen's book "A course in computational algebraic number theory". Here is an excerpt on the beautiful algorithm of Cornacchia:
