Package tlslite :: Package utils :: Module tlshashlib
[hide private]
[frames] | no frames]

Source Code for Module tlslite.utils.tlshashlib

 1  # Author: Hubert Kario (c) 2015 
 2  # see LICENCE file for legal information regarding use of this file 
 3   
 4  """hashlib that handles FIPS mode.""" 
 5   
 6  # Because we are extending the hashlib module, we need to import all its 
 7  # fields to suppport the same uses 
 8  # pylint: disable=unused-wildcard-import, wildcard-import 
 9  from hashlib import * 
10  # pylint: enable=unused-wildcard-import, wildcard-import 
11  import hashlib 
12   
13   
14 -def _fipsFunction(func, *args, **kwargs):
15 """Make hash function support FIPS mode.""" 16 try: 17 return func(*args, **kwargs) 18 except ValueError: 19 return func(*args, usedforsecurity=False, **kwargs)
20 21 22 # redefining the function is exactly what we intend to do 23 # pylint: disable=function-redefined
24 -def md5(*args, **kwargs):
25 """MD5 constructor that works in FIPS mode.""" 26 return _fipsFunction(hashlib.md5, *args, **kwargs)
27 28
29 -def new(*args, **kwargs):
30 """General constructor that works in FIPS mode.""" 31 return _fipsFunction(hashlib.new, *args, **kwargs)
32 # pylint: enable=function-redefined 33