fermat.tex 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. %% it would be nice here to explain that this magic 2^100 is just about wonting
  9. %% the most significant digits to be different.
  10. The basic idea is to attempt to write $N$ as a difference of squares,
  11. \begin{align}
  12. \label{eq:fermat_problem}
  13. x^2 - N = y^2
  14. \end{align}
  15. So, we start by $x = \ceil{\sqrt{N}}$ and check that $x^2-N$ is a perfect
  16. square. If it isn't, we iterativelly increment $x$ and check again, until we
  17. find a pair $\angular{x, y}$ satisfying equation \ref{eq:fermat_problem}.
  18. Once found, we claim that $N = pq = (x+y)(x-y)$; it is indeed true that, if we
  19. decompose $x^2 - y^2$ as difference of squares, then it is immediately clear
  20. that $x+y \mid N \ \land \ x-y \mid N$, and that both are non-trivial
  21. divisors.
  22. \paragraph{Complexity} \cite{riesel} contains a detailed proof for the
  23. complexity of this algorirthm, which is
  24. $\bigO{\frac{(1-k)^2}{2k} \sqrt{N}} \;\;, 0 < k < 1$. We summarize it down
  25. below here to better clarify the limits of this algorithm.
  26. \begin{proof}
  27. Since, once we reach the final step $x_f$ it holds $N = pq = x_f^2 - y_f^2$,
  28. the number of steps required to reach the result is:
  29. \begin{align*}
  30. x_f - \sqrt{N} &= \frac{p + q}{2} - \sqrt{N} \\
  31. &= \frac{p + \frac{N}{p}}{2} - \sqrt{N} \\
  32. &= \frac{(\sqrt{N} - p)^2}{2p}
  33. \end{align*}
  34. If we finally suppose that $p = k\sqrt{N}, \; 0 < k < 1$, then the number of cycles
  35. becomes
  36. $\frac{(1-k)^2}{2k} \sqrt{N}$.
  37. \end{proof}
  38. \begin{remark}
  39. Note that, for the algorithm to be effective, the two primes
  40. \emph{really close} to $\sqrt{N}$. As much as the lowest prime gets near to
  41. one, the ratio $\frac{(1-k)^2}{2k}$ becomes larger, until the actual magnitude
  42. of this factorization method approaches \bigO{N}.
  43. \end{remark}
  44. \section{An Implementation Perspective}
  45. At each iteration, the $i-$th state is hold by the pair $\angular{x, x^2}$.\\
  46. The later step, described by $\angular{x+1, (x+1)^2}$ can be computed efficently
  47. considering the square of a binomial: $\angular{x+1, (x^2) + (x \ll 1) + 1}$.
  48. The upperbound, instead, is reached when
  49. $ \Delta = p - q = x + y - x + y = 2y > 2^{-100}\sqrt{N}$.
  50. Algorithm ~\ref{alg:fermat} presents a simple implementation of this
  51. factorization method, taking into account the small aptimizations
  52. aforementioned.
  53. \paragraph{How to chose the upper limit?} after having explained our interpretation
  54. of NISTS' upperbound limit - the most significat bits story, we ;should report
  55. some practical tets.
  56. \begin{algorithm}
  57. \caption{Fermat Factorization \label{alg:fermat}}
  58. \begin{algorithmic}[1]
  59. \State $x \gets \floor{\sqrt{N}}$
  60. \State $x^2 \gets xx$
  61. \Repeat
  62. \State $x \gets x+1$
  63. \State $x^2 \gets x^2 + x \ll 1 + 1$
  64. \State $y, rest \gets \dsqrt{x^2 - N}$
  65. \Until{ $rest \neq 0 \land y < \frac{\sqrt{N}}{2^{101}}$ }
  66. \If{ $rest = 0$ }
  67. \State $p \gets x+y$
  68. \State $q \gets x-y$
  69. \State \Return $p, q$
  70. \Else
  71. \State \Return \textbf{nil}
  72. \EndIf
  73. \end{algorithmic}
  74. \end{algorithm}
  75. \section{Thoughts about parallelization}
  76. During each single iteration, the computational complexity is dominated by the
  77. quare root's $\dsqrt$ function, which belongs to the class
  78. \bigO{lg^2 N}, as we saw in section ~\ref{sec:preq:sqrt}.
  79. Even if at first sight might seem plausible to split
  80. As we saw in Chapter ~\ref{chap:preq}, th
  81. %%% Local Variables:
  82. %%% TeX-master: "question_authority.tex"
  83. %%% End: