Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hkdf using sha256 #136

Open
blackheart01 opened this issue Feb 20, 2020 · 0 comments
Open

hkdf using sha256 #136

blackheart01 opened this issue Feb 20, 2020 · 0 comments

Comments

@blackheart01
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant