Lines Matching full:crypto

20 #include <crypto/aead.h>
52 struct snp_guest_crypto *crypto; member
166 struct snp_guest_crypto *crypto; in init_crypto() local
168 crypto = kzalloc(sizeof(*crypto), GFP_KERNEL_ACCOUNT); in init_crypto()
169 if (!crypto) in init_crypto()
172 crypto->tfm = crypto_alloc_aead("gcm(aes)", 0, 0); in init_crypto()
173 if (IS_ERR(crypto->tfm)) in init_crypto()
176 if (crypto_aead_setkey(crypto->tfm, key, keylen)) in init_crypto()
179 crypto->iv_len = crypto_aead_ivsize(crypto->tfm); in init_crypto()
180 crypto->iv = kmalloc(crypto->iv_len, GFP_KERNEL_ACCOUNT); in init_crypto()
181 if (!crypto->iv) in init_crypto()
184 if (crypto_aead_authsize(crypto->tfm) > MAX_AUTHTAG_LEN) { in init_crypto()
185 if (crypto_aead_setauthsize(crypto->tfm, MAX_AUTHTAG_LEN)) { in init_crypto()
191 crypto->a_len = crypto_aead_authsize(crypto->tfm); in init_crypto()
192 crypto->authtag = kmalloc(crypto->a_len, GFP_KERNEL_ACCOUNT); in init_crypto()
193 if (!crypto->authtag) in init_crypto()
196 return crypto; in init_crypto()
199 kfree(crypto->iv); in init_crypto()
201 crypto_free_aead(crypto->tfm); in init_crypto()
203 kfree(crypto); in init_crypto()
208 static void deinit_crypto(struct snp_guest_crypto *crypto) in deinit_crypto() argument
210 crypto_free_aead(crypto->tfm); in deinit_crypto()
211 kfree(crypto->iv); in deinit_crypto()
212 kfree(crypto->authtag); in deinit_crypto()
213 kfree(crypto); in deinit_crypto()
216 static int enc_dec_message(struct snp_guest_crypto *crypto, struct snp_guest_msg *msg, in enc_dec_message() argument
225 req = aead_request_alloc(crypto->tfm, GFP_KERNEL); in enc_dec_message()
240 sg_set_buf(&src[2], hdr->authtag, crypto->a_len); in enc_dec_message()
245 sg_set_buf(&dst[2], hdr->authtag, crypto->a_len); in enc_dec_message()
248 aead_request_set_tfm(req, crypto->tfm); in enc_dec_message()
251 aead_request_set_crypt(req, src, dst, len, crypto->iv); in enc_dec_message()
261 struct snp_guest_crypto *crypto = snp_dev->crypto; in __enc_payload() local
264 memset(crypto->iv, 0, crypto->iv_len); in __enc_payload()
265 memcpy(crypto->iv, &hdr->msg_seqno, sizeof(hdr->msg_seqno)); in __enc_payload()
267 return enc_dec_message(crypto, msg, plaintext, msg->payload, len, true); in __enc_payload()
273 struct snp_guest_crypto *crypto = snp_dev->crypto; in dec_payload() local
277 memset(crypto->iv, 0, crypto->iv_len); in dec_payload()
278 memcpy(crypto->iv, &hdr->msg_seqno, sizeof(hdr->msg_seqno)); in dec_payload()
280 return enc_dec_message(crypto, msg, msg->payload, plaintext, len, false); in dec_payload()
285 struct snp_guest_crypto *crypto = snp_dev->crypto; in verify_and_dec_payload() local
310 if (unlikely((resp_hdr->msg_sz + crypto->a_len) > sz)) in verify_and_dec_payload()
314 return dec_payload(snp_dev, resp, payload, resp_hdr->msg_sz + crypto->a_len); in verify_and_dec_payload()
489 struct snp_guest_crypto *crypto = snp_dev->crypto; in get_report() local
507 resp_len = sizeof(resp->data) + crypto->a_len; in get_report()
529 struct snp_guest_crypto *crypto = snp_dev->crypto; in get_derived_key() local
545 resp_len = sizeof(resp.data) + crypto->a_len; in get_derived_key()
572 struct snp_guest_crypto *crypto = snp_dev->crypto; in get_ext_report() local
615 resp_len = sizeof(resp->data) + crypto->a_len; in get_ext_report()
957 snp_dev->crypto = init_crypto(snp_dev, snp_dev->vmpck, VMPCK_KEY_LEN); in sev_guest_probe()
958 if (!snp_dev->crypto) in sev_guest_probe()
1004 deinit_crypto(snp_dev->crypto); in sev_guest_remove()