Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Remove md5 usage to prevent issues on FIPS enabled systems (closes #29603) #29608

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/matplotlib/sphinxext/mathmpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,10 @@ def latex2html(node, source):
fontset = node['fontset']
fontsize = node['fontsize']
name = 'math-{}'.format(
hashlib.md5(f'{latex}{fontset}{fontsize}'.encode()).hexdigest()[-10:])
hashlib.sha256(
f'{latex}{fontset}{fontsize}'.encode(),
usedforsecurity=False,
).hexdigest()[-10:])

destdir = Path(setup.app.builder.outdir, '_images', 'mathmpl')
destdir.mkdir(parents=True, exist_ok=True)
Expand Down
12 changes: 5 additions & 7 deletions lib/matplotlib/testing/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,20 @@ def get_cache_dir():


def get_file_hash(path, block_size=2 ** 20):
md5 = hashlib.md5()
sha256 = hashlib.sha256(usedforsecurity=False)
with open(path, 'rb') as fd:
while True:
data = fd.read(block_size)
if not data:
break
md5.update(data)
sha256.update(data)

if Path(path).suffix == '.pdf':
md5.update(str(mpl._get_executable_info("gs").version)
.encode('utf-8'))
sha256.update(str(mpl._get_executable_info("gs").version).encode('utf-8'))
elif Path(path).suffix == '.svg':
md5.update(str(mpl._get_executable_info("inkscape").version)
.encode('utf-8'))
sha256.update(str(mpl._get_executable_info("inkscape").version).encode('utf-8'))

return md5.hexdigest()
return sha256.hexdigest()


class _ConverterError(Exception):
Expand Down
5 changes: 4 additions & 1 deletion lib/matplotlib/texmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,10 @@ def get_basefile(cls, tex, fontsize, dpi=None):
Return a filename based on a hash of the string, fontsize, and dpi.
"""
src = cls._get_tex_source(tex, fontsize) + str(dpi)
filehash = hashlib.md5(src.encode('utf-8')).hexdigest()
filehash = hashlib.sha256(
src.encode('utf-8'),
usedforsecurity=False
).hexdigest()
filepath = Path(cls._texcache)

num_letters, num_levels = 2, 2
Expand Down
Loading