Consumer application: - Adding a flag 'is_hbk', in its "struct crypto_config". - After fetching the keys, it is setting the above mentioned flag, based on the key fetched. -- Note: Supported for trusted keys only. - After allocating the tfm, and before calling crypto_xxx_setkey(), setting the: -- tfm flag 'is_hbk': cc->cipher_tfm.tfms[i]->base.is_hbk = cc->is_hbk; -- tfm hbk_info, if cc->is_hbk, is non-zero. Note: HBK Supported for symmetric-key ciphers only. Signed-off-by: Pankaj Gupta <pankaj.gupta@xxxxxxx> --- drivers/md/dm-crypt.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c index 159c6806c19b..d28c4af2904e 100644 --- a/drivers/md/dm-crypt.c +++ b/drivers/md/dm-crypt.c @@ -221,6 +221,8 @@ struct crypt_config { struct mutex bio_alloc_lock; u8 *authenc_key; /* space for keys in authenc() format (if used) */ + unsigned int is_hbk; + struct hw_bound_key_info hbk_info; u8 key[]; }; @@ -2397,10 +2399,16 @@ static int crypt_setkey(struct crypt_config *cc) r = crypto_aead_setkey(cc->cipher_tfm.tfms_aead[i], cc->key + (i * subkey_size), subkey_size); - else + else { + cc->cipher_tfm.tfms[i]->base.is_hbk = cc->is_hbk; + if (cc->is_hbk) + memcpy(&(cc->cipher_tfm.tfms[i]->base.hbk_info), + &(cc->hbk_info), + sizeof(struct hw_bound_key_info)); r = crypto_skcipher_setkey(cc->cipher_tfm.tfms[i], cc->key + (i * subkey_size), subkey_size); + } if (r) err = r; } @@ -2461,9 +2469,11 @@ static int set_key_trusted(struct crypt_config *cc, struct key *key) if (!tkp) return -EKEYREVOKED; + cc->is_hbk = tkp->is_hw_bound; if (cc->key_size != tkp->key_len) return -EINVAL; + memcpy(&(cc->hbk_info), &(tkp->hbk_info), sizeof(struct hw_bound_key_info)); memcpy(cc->key, tkp->key, cc->key_size); return 0; -- 2.17.1