I have an application running on Linux which needs to generate derived key with ECDH. I get ephemeral public key and KDF parameter and need to return derived key data.
This will be matched against secret and derived key generated on windows server with ephemeral private key and smart card public key with same KDF parameter. Windows uses BCryptSecretAgreement
and BCryptDeriveKey
APIs.
But the derived data is not matching.
I have an application running on Linux which needs to generate derived key with ECDH. I get ephemeral public key and KDF parameter and need to return derived key data. I am using C_DeriveKey
API to generate the derived data(of type CKO_SECRET_KEY
) in one shot with peer public key, KDF params and private key stored on smart card.
Linux:
CK_ECDH1_DERIVE_PARAMS scdh_params;
memset(&ecdh_parms, 0, sizeof(ecdh_parms));
ecdh_parms.kdf = CKD_SHA256_KDF;
ecdh_parms.ulSharedDataLen = 0;
ecdh_parms.pSharedData = NULL;
ecdh_parms.ulPublicDataLen = buf_size;//peer public key size
ecdh_parms.pPublicData = buf; // peer public key
mech.pParameter = &ecdh_parms;
mech.ulParameterLen = sizeof(ecdh_parms);
rv = p11->C_DeriveKey(session, &mech, privateKey, newkey_template, n_attrs, &newkey);`
This will be matched against secret and derived key generated on windows server with ephemeral private key and smart card public key with same KDF parameter. Windows uses BCryptSecretAgreement
and BCryptDeriveKey
APIs.
But the derived data is not matching.
Also I can derive secret by setting
ecdh_parms.kdf = NULL;
But not able to derive data using secret with C_DeriveKey
API as it is throwing CKR_KEY_HANDLE_INVALID
.
What is the equivalent of BCryptSecretAgreement
and BCryptDeriveKey
in pkcs11? I was thing C_DeriveKey
can do both functionality but it is not working.