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