I want to wrap a private key out of a HSM, using an external EC key pair (master key) and then verify that I can recover it.
The wrapping occurs as follows:
- Generate a secret AES key in the HSM, using the public part of the EC master key, the private part of the internal key pair and the derivation mechanism
CKM_ECDH1_DERIVE
. The derivation parameters for this mechanism are: derivation functionCKD_SHA256_KDF
, shared data and public data (public data are taken from the public EC master key). - Wrap the private key, using the secret AES key and a mechanism such as
CKM_AES_GCM
,CKM_AES_KEY_WRAP_PAD
orCKM_AES_CBC_PAD
. - The HSM returns a byte array.
Could someone tell me if I'm doing right and what I should use as shared and public data when the HSM generates the secret key?
Then, how could I recover this private key, with the help of the private part of the EC master key pair, in order to be sure that the process works well?