AES Password Based Key Derivation Iterations
Thank you all for all of the excellent help. I am happy to say that with your help I have found the answer to my initial question and more.
The code below accepts a [string] password, [hex string] salt, [int] key size, and [int] iteration count, and returns a tuple containing the correct key and IV for PBKDF2. OpenSSL PBKDF2 uses 10,000 iterations by default. Leave the salt in the command as double quotes if there is no salt.
Proof:
printf &quot;Today is a good day!&quot; | openssl enc -aes-192-cbc -md sha512 -pbkdf2 -S 436172616d656c73 -k &quot;Sparky&quot; -p
results in:
salt=436172616D656C73
key=37A12300EF8D3442B266B41172154DFE0836803C4257AFB6
iv=E2FC1F1DF27AB4A6F303EDD6537EEE53
The same salt, key, and IV can be obtained by using the code and class below:
from pbkdf2 import kdf
key, iv = kdf.pbkdf2(“Sparky”,”436172616D656C73”,192,10000)
results in:
key=37A12300EF8D3442B266B41172154DFE0836803C4257AFB6
iv=E2FC1F1DF27AB4A6F303EDD6537EEE53
“Sparky” is the password
“436172616D656C73” is the salt
192 is the AES-CBC key size
10,000 is the number of hmac iterations (pbkdf2)
And here is the Python3 code (pbkdf2.py).
Import hashlib
import hmac
class kdf:
def pbkdf2(passwd, salt, size, iterations):


    dictionary = {128:((0,32),(32,64)), 192:((0,48),(48,80)), 256:((0,64),(64,96))}

    k = b = hmac.new(passwd.encode(&quot;utf-8&quot;), bytes.fromhex(salt) + b'\x00\x00\x00\x01' if len(salt) &gt; 0 else b'\x00\x00\x00\x01', hashlib.sha512).digest()

    for i in range(2, iterations + 1):
        b = hmac.new(passwd.encode(&quot;utf-8&quot;), b, hashlib.sha512).digest()
        k = bytes(i ^ j for i, j in zip(k, b))


    key = k.hex()[dictionary.get(size)[0][0]:dictionary.get(size)[0][1]]
    _iv = k.hex()[dictionary.get(size)[1][0]:dictionary.get(size)[1][1]]

    return key,_iv