{
  "id": "2025/2083",
  "url": "https://opencryptology.org/2025/2083",
  "original_url": "https://eprint.iacr.org/2025/2083",
  "title": "Improvements to Lucas-sequence modular square roots and primality testing",
  "authors": [
    "Mike Hamburg"
  ],
  "affiliations": null,
  "abstract": "Lucas sequences are a helpful tool in mathematical and cryptographic calculations, providing in particular an efficient way to exponentiate in a quotient ring $R[x]/(x^2 - Px + Q)$.  As with exponentiation in other finite rings and fields, we can use the periodic nature of these sequences to find roots of polynomials.  Since they behave differently in the ring $\\mathbb{Z}/N$ depending on whether $N$ is prime, Lucas sequences are also useful for primality testing.  In this paper, we discuss improvements to Lucas-sequence algorithms for square roots and heuristic primality testing.\n\nOur first application is modular square roots.  It is straightforward to take square roots modulo primes $p\\equiv \\{3,5,7\\}$ mod 8.  When $p\\equiv 1$ mod 8, and especially when $p-1$ is divisible by many powers of 2, Müller's algorithm and Kim-Koo-Kwon are attractive options.  Both of these use Lucas sequences.  Here we show how to simplify and speed up Kim-Koo-Kwon.  We also show a variant on Müller's algorithm which works even when $p\\equiv 3$ mod 4, which would be useful if $p$ were secret.\n\nOur second application is heuristic primality testing.  The Baillie-PSW primality test combines a strong Fermat test with a strong Lucas test.  The recent Baillie-Fiori-Wagstaff variant strengthens Baillie-PSW.  Here we show an improved variant, $\\mathtt{SuperBFPSW}$, which is stronger than Baillie-Fiori-Wagstaff, but also faster than the original Baillie-PSW.",
  "category": "Implementation",
  "license": {
    "code": "CC BY",
    "url": "https://creativecommons.org/licenses/by/4.0/",
    "label": "CC BY 4.0",
    "attribution": "“Improvements to Lucas-sequence modular square roots and primality testing” by Mike Hamburg, Cryptology ePrint Archive, Paper 2025/2083, https://eprint.iacr.org/2025/2083. Licensed under CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/).",
    "retroactive": false,
    "redistribute_verbatim_only": false,
    "non_commercial": false
  },
  "dates": {
    "submitted": "2025-11-11T10:06:55Z",
    "updated": "2026-09-12T14:23:16Z",
    "withdrawn": null
  },
  "withdrawn": false,
  "withdrawn_on": null,
  "pdf": {
    "url": "https://opencryptology.org/2025/2083.pdf",
    "sha256": "789fd1bfad248b063afe2bc2ce54e5221c1f19949e053158fab7db35c6e9cf50",
    "size": 510249,
    "source": "upload",
    "source_date": "2026-11-14T03:47:35.544Z",
    "maybe_stale": false,
    "newer_on_eprint": null,
    "eprint_size": null,
    "withdrawn": false
  },
  "versions": [
    {
      "url": "https://opencryptology.org/2025/2083/versions/20261114T034735Z.pdf",
      "captured_at": "2026-11-14T03:47:35.544Z",
      "label": "copy captured 2026-11-14",
      "source": "upload",
      "source_url": null,
      "size": 510249,
      "sha256": "789fd1bfad248b063afe2bc2ce54e5221c1f19949e053158fab7db35c6e9cf50",
      "is_default_pdf": true
    },
    {
      "url": "https://opencryptology.org/2025/2083/versions/20260428T172000Z.pdf",
      "captured_at": "2026-04-28T17:20:00Z",
      "label": "copy captured 2026-04-28",
      "source": "github-mirror",
      "source_url": "https://raw.githubusercontent.com/arturo-kong/IACR-eprint-mirror/master/2025/2083.pdf",
      "size": 508501,
      "sha256": "e10276f6c21bee27e84a2d58620756b1cbd8ed3dbece15752ab54296a1d1c51d",
      "is_default_pdf": false
    }
  ],
  "other_sources": [
    {
      "kind": "github-mirror",
      "url": "https://raw.githubusercontent.com/arturo-kong/IACR-eprint-mirror/master/2025/2083.pdf",
      "captured_at": "2026-04-28T17:20:00Z",
      "size": 508501
    },
    {
      "kind": "wayback",
      "url": "https://web.archive.org/web/20251114034121id_/https://eprint.iacr.org/2025/2083.pdf",
      "captured_at": "2025-11-14T03:41:21Z",
      "size": 497033
    }
  ],
  "bibtex": "@misc{cryptoeprint:2025/2083,\n      author = {Mike Hamburg},\n      title = {Improvements to Lucas-sequence modular square roots and primality testing},\n      howpublished = {Cryptology {ePrint} Archive, Paper 2025/2083},\n      year = {2025},\n      url = {https://eprint.iacr.org/2025/2083}\n}"
}
