I'm trying to generate an hkdf sha256 key from a master key and a salt. According to https://wiki.openssl.org/index.php/EVP_Key_Derivation it seems openssl has this functionality. Unfortunately, looking through the source code for spacemonkeygo/openssl, I can't find any "EVP_KDF" functions.
I've written my own HKDF function that produces the expected output:
func HKDF(master, salt []byte) ([]byte, error) {
hmac, err := openssl.NewHMAC(salt, openssl.EVP_SHA256)
if err != nil {
return nil, err
}
_, err = hmac.Write(master)
if err != nil {
return nil, err
}
prk, err := hmac.Final()
if err != nil {
return nil, err
}
hmac.Close()
hmac, err = openssl.NewHMAC(prk, openssl.EVP_SHA256)
if err != nil {
return nil, err
}
_, err = hmac.Write([]byte{1})
if err != nil {
return nil, err
}
key, err := hmac.Final()
if err != nil {
return nil, err
}
hmac.Close()
return key, nil
}
This function works, but is only a proof of concept right now. Before I commit to making the function production ready, I thought I'd ask if anyone could point me to a spacemonkeygo/openssl function that already does this.
Thanks!