From 4f6fe11c9458f94a9e6844c0eefb70e0242edd96 Mon Sep 17 00:00:00 2001
From: tb <>
Date: Mon, 7 Feb 2022 19:44:23 +0000
Subject: Check for zero modulus in BN_MONT_CTX_set().

From OpenSSL 6a009812, prompted by a report by Guido Vranken

ok beck jsing
---
 src/lib/libcrypto/bn/bn_mont.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/lib/libcrypto/bn/bn_mont.c b/src/lib/libcrypto/bn/bn_mont.c
index 45e312a3a6..e01af702e7 100644
--- a/src/lib/libcrypto/bn/bn_mont.c
+++ b/src/lib/libcrypto/bn/bn_mont.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bn_mont.c,v 1.27 2021/12/04 16:05:46 tb Exp $ */
+/* $OpenBSD: bn_mont.c,v 1.28 2022/02/07 19:44:23 tb Exp $ */
 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
  * All rights reserved.
  *
@@ -369,6 +369,9 @@ BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)
 	int ret = 0;
 	BIGNUM *Ri, *R;
 
+	if (BN_is_zero(mod))
+		return 0;
+
 	BN_CTX_start(ctx);
 	if ((Ri = BN_CTX_get(ctx)) == NULL)
 		goto err;
-- 
cgit v1.2.3-55-g6feb