be0198
diff --git a/sphinx/builders/html.py b/sphinx/builders/html.py
be0198
index 8b63352..1a95c77 100644
be0198
--- a/sphinx/builders/html.py
be0198
+++ b/sphinx/builders/html.py
be0198
@@ -14,7 +14,6 @@ import posixpath
be0198
 import re
be0198
 import sys
be0198
 import warnings
be0198
-from hashlib import md5
be0198
 from os import path
be0198
 
be0198
 import docutils
be0198
@@ -40,7 +39,7 @@ from sphinx.highlighting import PygmentsBridge
be0198
 from sphinx.locale import _, __, l_
be0198
 from sphinx.search import js_index
be0198
 from sphinx.theming import HTMLThemeFactory
be0198
-from sphinx.util import jsonimpl, logging, status_iterator
be0198
+from sphinx.util import jsonimpl, logging, status_iterator, md5
be0198
 from sphinx.util.console import bold, darkgreen  # type: ignore
be0198
 from sphinx.util.docutils import is_html5_writer_available, new_document
be0198
 from sphinx.util.fileutil import copy_asset
be0198
diff --git a/sphinx/ext/graphviz.py b/sphinx/ext/graphviz.py
be0198
index 08707b7..9d53a0e 100644
be0198
--- a/sphinx/ext/graphviz.py
be0198
+++ b/sphinx/ext/graphviz.py
be0198
@@ -13,7 +13,6 @@
be0198
 import codecs
be0198
 import posixpath
be0198
 import re
be0198
-from hashlib import sha1
be0198
 from os import path
be0198
 from subprocess import Popen, PIPE
be0198
 
be0198
@@ -25,7 +24,7 @@ from six import text_type
be0198
 import sphinx
be0198
 from sphinx.errors import SphinxError
be0198
 from sphinx.locale import _, __
be0198
-from sphinx.util import logging
be0198
+from sphinx.util import logging, sha1
be0198
 from sphinx.util.i18n import search_image_for_language
be0198
 from sphinx.util.osutil import ensuredir, ENOENT, EPIPE, EINVAL
be0198
 
be0198
diff --git a/sphinx/ext/imgmath.py b/sphinx/ext/imgmath.py
be0198
index 5f9d7a1..23f89ed 100644
be0198
--- a/sphinx/ext/imgmath.py
be0198
+++ b/sphinx/ext/imgmath.py
be0198
@@ -14,7 +14,6 @@ import posixpath
be0198
 import re
be0198
 import shutil
be0198
 import tempfile
be0198
-from hashlib import sha1
be0198
 from os import path
be0198
 from subprocess import Popen, PIPE
be0198
 
be0198
@@ -26,7 +25,7 @@ from sphinx.errors import SphinxError, ExtensionError
be0198
 from sphinx.ext.mathbase import get_node_equation_number
be0198
 from sphinx.ext.mathbase import setup_math as mathbase_setup, wrap_displaymath
be0198
 from sphinx.locale import _
be0198
-from sphinx.util import logging
be0198
+from sphinx.util import logging, sha1
be0198
 from sphinx.util.osutil import ensuredir, ENOENT, cd
be0198
 from sphinx.util.png import read_png_depth, write_png_depth
be0198
 from sphinx.util.pycompat import sys_encoding
be0198
diff --git a/sphinx/ext/inheritance_diagram.py b/sphinx/ext/inheritance_diagram.py
be0198
index 14593ac..9576d07 100644
be0198
--- a/sphinx/ext/inheritance_diagram.py
be0198
+++ b/sphinx/ext/inheritance_diagram.py
be0198
@@ -39,7 +39,6 @@ r"""
be0198
 import inspect
be0198
 import re
be0198
 import sys
be0198
-from hashlib import md5
be0198
 
be0198
 from docutils import nodes
be0198
 from docutils.parsers.rst import Directive, directives
be0198
@@ -50,7 +49,7 @@ import sphinx
be0198
 from sphinx.ext.graphviz import render_dot_html, render_dot_latex, \
be0198
     render_dot_texinfo, figure_wrapper
be0198
 from sphinx.pycode import ModuleAnalyzer
be0198
-from sphinx.util import force_decode
be0198
+from sphinx.util import force_decode, md5
be0198
 
be0198
 if False:
be0198
     # For type annotation
be0198
diff --git a/sphinx/transforms/post_transforms/images.py b/sphinx/transforms/post_transforms/images.py
be0198
index 6dd135e..d1c50bd 100644
be0198
--- a/sphinx/transforms/post_transforms/images.py
be0198
+++ b/sphinx/transforms/post_transforms/images.py
be0198
@@ -10,14 +10,13 @@
be0198
 """
be0198
 
be0198
 import os
be0198
-from hashlib import sha1
be0198
 from math import ceil
be0198
 
be0198
 from docutils import nodes
be0198
 from six import text_type
be0198
 
be0198
 from sphinx.transforms import SphinxTransform
be0198
-from sphinx.util import epoch_to_rfc1123, rfc1123_to_epoch
be0198
+from sphinx.util import epoch_to_rfc1123, rfc1123_to_epoch, sha1
be0198
 from sphinx.util import logging, requests
be0198
 from sphinx.util.images import guess_mimetype, get_image_extension, parse_data_uri
be0198
 from sphinx.util.osutil import ensuredir, movefile
be0198
diff --git a/sphinx/util/__init__.py b/sphinx/util/__init__.py
be0198
index dda3fb0..9c1c441 100644
be0198
--- a/sphinx/util/__init__.py
be0198
+++ b/sphinx/util/__init__.py
be0198
@@ -11,6 +11,7 @@
be0198
 from __future__ import absolute_import
be0198
 
be0198
 import fnmatch
be0198
+import hashlib
be0198
 import os
be0198
 import posixpath
be0198
 import re
be0198
@@ -164,6 +165,32 @@ class FilenameUniqDict(dict):
be0198
         # type: (Set[unicode]) -> None
be0198
         self._existing = state
be0198
 
be0198
+def md5(data=b'', **kwargs):
be0198
+    """Wrapper around hashlib.md5
be0198
+    Attempt call with 'usedforsecurity=False' if we get a ValueError, which happens when
be0198
+    OpenSSL FIPS mode is enabled:
be0198
+    ValueError: error:060800A3:digital envelope routines:EVP_DigestInit_ex:disabled for fips
be0198
+    See: https://github.com/sphinx-doc/sphinx/issues/7611
be0198
+    """
be0198
+
be0198
+    try:
be0198
+        return hashlib.md5(data, **kwargs)  # type: ignore
be0198
+    except ValueError:
be0198
+        return hashlib.md5(data, **kwargs, usedforsecurity=False)  # type: ignore
be0198
+
be0198
+
be0198
+def sha1(data=b'', **kwargs):
be0198
+    """Wrapper around hashlib.sha1
be0198
+    Attempt call with 'usedforsecurity=False' if we get a ValueError
be0198
+    See: https://github.com/sphinx-doc/sphinx/issues/7611
be0198
+    """
be0198
+
be0198
+    try:
be0198
+        return hashlib.sha1(data, **kwargs)  # type: ignore
be0198
+    except ValueError:
be0198
+        return hashlib.sha1(data, **kwargs, usedforsecurity=False)  # type: ignore
be0198
+
be0198
+
be0198
 
be0198
 def copy_static_entry(source, targetdir, builder, context={},
be0198
                       exclude_matchers=(), level=0):