fermat.tex 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. \chapter{Fermat's Factorization Algorithm \label{chap:fermat}}
  2. Excluding the trial division, Fermat's method is the oldest known systematic
  3. method for factorizing integers. Even if its algorithmic complexity is not
  4. really among the most efficient, it holds still a practical interest whenever
  5. the two primes are sufficiently close.
  6. Indeed, \cite{DSS2009} \S B.3.6 explicitly reccomends that $|p-q| \geq \sqrt{N}2^{-100}$,
  7. in order to address this kind of threat, for any key of bitlength $1024,\ 2048,\ 3072$.\\
  8. The basic idea is to attempt to write $N$ as a difference of squares,
  9. \begin{align}
  10. \label{eq:fermat_problem}
  11. x^2 - N = y^2
  12. \end{align}
  13. So, we start by $x = \ceil{\sqrt{N}}$ and check that $x^2-N$ is a perfect
  14. square. If it isn't, we iterativelly increment $x$ and check again, until we
  15. find a pair $\angular{x, y}$ satisfying equation \ref{eq:fermat_problem}.
  16. Once found, we claim that $N = pq = (x+y)(x-y)$; it is indeed true that:
  17. \begin{proof}
  18. \label{proof:fermat}
  19. \begin{align*}
  20. x^2 - N = y^2 \\
  21. x^2 - y^2 = N \\
  22. (x+y)(x-y) = N \\
  23. x+y \mid N \ \land \ x-y \mid N
  24. \end{align*}
  25. \end{proof}
  26. As it is straightforward to see, the order of magnitude of this algorithm is
  27. $\bigO{\sqrt{N}}$.
  28. \section{An Implementative Perspective}
  29. At each iteration, the $i-$th state is hold by the pair $\angular{x, x^2}$.\\
  30. The later step, described by $\angular{x+1, (x+1)^2}$ can be computed efficently
  31. considering the square of a binomial: $\angular{x+1, (x^2) + (x \ll 1) + 1}$.
  32. The upperbound, instead, is reached when
  33. $ \Delta = p - q = x + y - x + y = 2y > 2^{-100}\sqrt{N}$.
  34. Algorithm ~\ref{alg:fermat} presents a simple implementation of this
  35. factorization method, taking into account the small aptimizations
  36. aforementioned.
  37. \begin{algorithm}
  38. \caption{Fermat Factorization \label{alg:fermat}}
  39. \begin{algorithmic}[1]
  40. \State $x \gets \floor{\sqrt{N}}$
  41. \State $x^2 \gets xx$
  42. \Repeat
  43. \State $x \gets x+1$
  44. \State $x^2 \gets x^2 + x \ll 1 + 1$
  45. \State $y, rest \gets sqrt(x^2 - N)$
  46. \Until{ $rest \neq 0 \land y < \frac{\sqrt{N}}{2^{101}}$ }
  47. \If{ $rest = 0$ }
  48. \State $p \gets x+y$
  49. \State $q \gets x-y$
  50. \State \Return $p, q$
  51. \Else
  52. \State \Return \textbf{nil}
  53. \EndIf
  54. \end{algorithmic}
  55. \end{algorithm}
  56. \section{Thoughts about parallelization}
  57. During each single iteration, the computational complexity is dominated by the
  58. quare root's $sqrt()$ function, which belongs to the class
  59. \bigO{lg^2 N}, as we saw in section ~\ref{sec:preq:sqrt}.
  60. Even if at first sight might seem plausible to split
  61. As we saw in Chapter ~\ref{chap:preq}, th
  62. %%% Local Variables:
  63. %%% TeX-master: "question_authority.tex"
  64. %%% End: