diff --git a/doc/api/next_api_changes/behavior/18193-BKB.rst b/doc/api/next_api_changes/behavior/18193-BKB.rst new file mode 100644 index 000000000000..67cfc79bfa13 --- /dev/null +++ b/doc/api/next_api_changes/behavior/18193-BKB.rst @@ -0,0 +1,10 @@ +ID attribute of XML tags in SVG files now based on SHA256 rather than MD5 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Matplotlib generates unique ID attributes for various tags in SVG files. +Matplotlib previously generated these unique IDs using the first 10 +characters of an MD5 hash. The MD5 hashing algorithm is not available in +Python on systems with Federal Information Processing Standards (FIPS) +enabled. Matplotlib now uses the first 10 characters of an SHA256 hash +instead. SVG files that would otherwise match those saved with earlier +versions of matplotlib, will have different ID attributes. diff --git a/lib/matplotlib/backends/backend_svg.py b/lib/matplotlib/backends/backend_svg.py index dbcbbd225b0c..23e171225717 100644 --- a/lib/matplotlib/backends/backend_svg.py +++ b/lib/matplotlib/backends/backend_svg.py @@ -452,7 +452,7 @@ def _make_id(self, type, content): salt = mpl.rcParams['svg.hashsalt'] if salt is None: salt = str(uuid.uuid4()) - m = hashlib.md5() + m = hashlib.sha256() m.update(salt.encode('utf8')) m.update(str(content).encode('utf8')) return '%s%s' % (type, m.hexdigest()[:10])