fermat.tex 4.2 KB

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