From e938627bcf89f3083a0017eba61f4e0143625ba1 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 20 Dec 2023 07:02:52 +0000 Subject: [PATCH] Validate p in ModularSquareRoot --- nbtheory.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/nbtheory.cpp b/nbtheory.cpp index 7e60be4b6..b17548960 100644 --- a/nbtheory.cpp +++ b/nbtheory.cpp @@ -543,6 +543,9 @@ Integer CRT(const Integer &xp, const Integer &p, const Integer &xq, const Intege Integer ModularSquareRoot(const Integer &a, const Integer &p) { + if (!IsPrime(p)) + throw InvalidArgument("ModularSquareRoot: p must be a prime"); + if (p%4 == 3) return a_exp_b_mod_c(a, (p+1)/4, p);