c - How to properly implement HKDF Expand with openssl EVP_KDF - Stack Overflow

admin2025-04-30  0

I am trying to manually get around bitwarden's encryption, and getting wrong results from using openssl according to this page: .php/EVP_Key_Derivation . I want to use openssl to hkdf-expand the "master key" in bitwarden to the "stretched master key."

I discovered that python cryptography library's HKDFExpand produces correct results after finding this project: (lines 133-139), so how can I implement openssl to behave similar to HKDFExpand?

The only changes I have made in the example is remove the salt param and instead add a mode param using

int a = EVP_KDF_HKDF_MODE_EXPAND_ONLY;
*p++ = OSSL_PARAM_construct_int("mode", &a);

also changed the key (censored here) and info params:

*p++ = OSSL_PARAM_construct_octet_string(
      "key", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX=", (size_t)44);

*p++ = OSSL_PARAM_construct_octet_string("info", "enc", (size_t)3);

and the rest is the same just with the error() replaced by printf(). The code works but converting the hex output to b64 shows a different stretched key than on .html and the one generated by that python file

转载请注明原文地址:http://anycun.com/QandA/1746023861a91489.html