# Buggy code
def _new_serial(ca_name, CN):
    """
    Return a serial number in hex using md5sum, based upon the ca_name and
    CN values

    ca_name
        name of the CA
    CN
        common name in the request
    """
    hashnum = int(
        hashlib.md5("{0}_{1}_{2}".format(ca_name, CN, int(time.time()))).hexdigest(), 16
    )
    log.debug("Hashnum: {0}".format(hashnum))

    # record the hash somewhere
    cachedir = __opts__["cachedir"]
    log.debug("cachedir: {0}".format(cachedir))
    serial_file = "{0}/{1}.serial".format(cachedir, ca_name)
    with salt.utils.fopen(serial_file, "a+") as ofile:
        ofile.write(str(hashnum))

    return hashnum


# Traceback (ValueError)
[root@minion-fips ~]# salt-call state.sls httpd
[INFO    ] Loading fresh modules for state activity
[ERROR   ] An un-handled exception was caught by salt's global exception handler:
ValueError: error:060800A3:digital envelope routines:EVP_DigestInit_ex:disabled for fips
Traceback (most recent call last):
File "/usr/bin/salt-call", line 11, in <module>
salt_call()
File "/usr/lib/python2.6/site-packages/salt/scripts.py", line 82, in salt_call
client.run()
File "/usr/lib/python2.6/site-packages/salt/cli/__init__.py", line 314, in run
caller.run()
File "/usr/lib/python2.6/site-packages/salt/cli/caller.py", line 142, in run
ret = self.call()
File "/usr/lib/python2.6/site-packages/salt/cli/caller.py", line 80, in call
ret['return'] = func(*args, **kwargs)
File "/usr/lib/python2.6/site-packages/salt/modules/state.py", line 372, in sls
high_, errors = st_.render_highstate({saltenv: mods})
File "/usr/lib/python2.6/site-packages/salt/state.py", line 2375, in render_highstate
state, errors = self.render_state(sls, saltenv, mods, matches)
File "/usr/lib/python2.6/site-packages/salt/state.py", line 2084, in render_state
state_data = self.client.get_state(sls, saltenv)
File "/usr/lib/python2.6/site-packages/salt/fileclient.py", line 413, in get_state
dest = self.cache_file(path, saltenv)
File "/usr/lib/python2.6/site-packages/salt/fileclient.py", line 143, in cache_file
return self.get_url(path, '', True, saltenv)
File "/usr/lib/python2.6/site-packages/salt/fileclient.py", line 503, in get_url
return self.get_file(url, dest, makedirs, saltenv)
File "/usr/lib/python2.6/site-packages/salt/fileclient.py", line 894, in get_file
hash_local = self.hash_file(dest2check, saltenv)
File "/usr/lib/python2.6/site-packages/salt/fileclient.py", line 1100, in hash_file
path, form='md5', chunk_size=4096)
File "/usr/lib/python2.6/site-packages/salt/utils/__init__.py", line 1437, in get_hash
hash_obj = hash_type()
ValueError: error:060800A3:digital envelope routines:EVP_DigestInit_ex:disabled for fips

# Fixed code
def _new_serial(ca_name, CN):
    """
    Return a serial number in hex using md5sum, based upon the ca_name and
    CN values

    ca_name
        name of the CA
    CN
        common name in the request
    """
    opts_hash_type = __opts__.get("hash_type", "md5")
    hash_type = getattr(hashlib, opts_hash_type)
    hashnum = int(
        hashtype("{0}_{1}_{2}".format(ca_name, CN, int(time.time()))).hexdigest(), 16
    )
    log.debug("Hashnum: {0}".format(hashnum))

    # record the hash somewhere
    cachedir = __opts__["cachedir"]
    log.debug("cachedir: {0}".format(cachedir))
    serial_file = "{0}/{1}.serial".format(cachedir, ca_name)
    with salt.utils.fopen(serial_file, "a+") as ofile:
        ofile.write(str(hashnum))

    return hashnum