establish that every prime number p of the form $ 8k + 1$ or $8k +3$ can be written as $ p = a^2 + 2b^2$ for some choice of integers a and b. The question is:
Establish that every prime number p of the form $ 8k + 1$ or $8k +3$ can be written as $ p = a^2 + 2b^2$ for some choice of integers a and b.
And the Hint says:
Mimic the proof of theorem 13.2, which is given below:



 

My trial is:
For the case: $p = 8k + 1$
I used the theorem that says the Legendre symbol $(2/p) = 1$ if $p \equiv 1 \pmod 8$ 
And I end up after using Thue lemma that $$2x_{0}^2 \equiv y_{0}^2,$$
But this will lead to $p = 2a^2 - b^2$ which is not the required, could anyone help me in fixing this please? 
I feel that I need the Legendre symbol $(2/p) = 1$ if $p \equiv 1 \pmod 8$ to be  $(- 2/p) = 1$ if $p \equiv 1 \pmod 8$ instead, but How can I do this ?
What about the second case when $p \equiv 3 \pmod 8$?
 A: Since the Legendre symbol is multiplicative we have:
$$\left(\frac{-2}{p}\right)=\left(\frac{2}{p}\right)\left(\frac{-1}{p}\right)$$
The first one is equal to $1$ iff $p \equiv 1,7 \pmod{8}$ and the second iff $p \equiv 1 \pmod{4}$. So they are both one when $p \equiv 1 \pmod{8}$ and both $-1$ when $p \equiv 3 \pmod{8}$. In both cases their product is one which means that $-2$ is a quadratic residue mod $p$ i.e. there exists an integer $a$ such that:
$$a^2 \equiv -2 \pmod{p}$$ Now you mimic the given proof and everything should work out well.
A: Comment:An experimental approach; following conditions cover a set of these types of primes:
For $8k+1$:
Let $k=k_1+2$  ⇒ $p=8(k_1+2)+1=8k_1+8+8+1=2[4(k_1+1)]+3^2$
If $k_1+1=c^2$ then we have:
$p=3^2+2\times (2c)^2$
Examples; $k_1=3$  ⇒ $p=41=3^2+2 (2\times 2)^2=3^2+2\times 4^2$
$k_1=15$  ⇒ $c^2=15+1=4^2$  ⇒ $p=137=3^2+2\times 8^2$
For $p=8k+3$ it can be seen that:
$p=8k+3 ≡ c^2k^2 \mod 3^2$;
Type 1: $p=(3d)^2 +2(ck)^2$
Type 2: $p=(ck)^2 +2(3d)^2$
apart from ck=1 or $(3d)^0=1$ we have following values for ck and 3d:
$ck=1, 5^2, 7^2, 11^2,     (2n+1)^2$; $2n+1 ≠ 3 t$
$3d = 3, 9, 15, . . .(2n+1)3$ 
Examples:
$p=8\times 52+3=419=9^2+2\times 13^2$
$p=8\times 58+3=467=15^2 +2\times 11^2$
In both cases $p≡ c^2k^2 \mod 3^2$
