Lines Matching full:crypto
19 #include <crypto/aead.h>
45 struct snp_guest_crypto *crypto; member
146 struct snp_guest_crypto *crypto; in init_crypto() local
148 crypto = kzalloc(sizeof(*crypto), GFP_KERNEL_ACCOUNT); in init_crypto()
149 if (!crypto) in init_crypto()
152 crypto->tfm = crypto_alloc_aead("gcm(aes)", 0, 0); in init_crypto()
153 if (IS_ERR(crypto->tfm)) in init_crypto()
156 if (crypto_aead_setkey(crypto->tfm, key, keylen)) in init_crypto()
159 crypto->iv_len = crypto_aead_ivsize(crypto->tfm); in init_crypto()
160 crypto->iv = kmalloc(crypto->iv_len, GFP_KERNEL_ACCOUNT); in init_crypto()
161 if (!crypto->iv) in init_crypto()
164 if (crypto_aead_authsize(crypto->tfm) > MAX_AUTHTAG_LEN) { in init_crypto()
165 if (crypto_aead_setauthsize(crypto->tfm, MAX_AUTHTAG_LEN)) { in init_crypto()
171 crypto->a_len = crypto_aead_authsize(crypto->tfm); in init_crypto()
172 crypto->authtag = kmalloc(crypto->a_len, GFP_KERNEL_ACCOUNT); in init_crypto()
173 if (!crypto->authtag) in init_crypto()
176 return crypto; in init_crypto()
179 kfree(crypto->authtag); in init_crypto()
181 kfree(crypto->iv); in init_crypto()
183 crypto_free_aead(crypto->tfm); in init_crypto()
185 kfree(crypto); in init_crypto()
190 static void deinit_crypto(struct snp_guest_crypto *crypto) in deinit_crypto() argument
192 crypto_free_aead(crypto->tfm); in deinit_crypto()
193 kfree(crypto->iv); in deinit_crypto()
194 kfree(crypto->authtag); in deinit_crypto()
195 kfree(crypto); in deinit_crypto()
198 static int enc_dec_message(struct snp_guest_crypto *crypto, struct snp_guest_msg *msg, in enc_dec_message() argument
207 req = aead_request_alloc(crypto->tfm, GFP_KERNEL); in enc_dec_message()
222 sg_set_buf(&src[2], hdr->authtag, crypto->a_len); in enc_dec_message()
227 sg_set_buf(&dst[2], hdr->authtag, crypto->a_len); in enc_dec_message()
230 aead_request_set_tfm(req, crypto->tfm); in enc_dec_message()
233 aead_request_set_crypt(req, src, dst, len, crypto->iv); in enc_dec_message()
243 struct snp_guest_crypto *crypto = snp_dev->crypto; in __enc_payload() local
246 memset(crypto->iv, 0, crypto->iv_len); in __enc_payload()
247 memcpy(crypto->iv, &hdr->msg_seqno, sizeof(hdr->msg_seqno)); in __enc_payload()
249 return enc_dec_message(crypto, msg, plaintext, msg->payload, len, true); in __enc_payload()
255 struct snp_guest_crypto *crypto = snp_dev->crypto; in dec_payload() local
259 memset(crypto->iv, 0, crypto->iv_len); in dec_payload()
260 memcpy(crypto->iv, &hdr->msg_seqno, sizeof(hdr->msg_seqno)); in dec_payload()
262 return enc_dec_message(crypto, msg, msg->payload, plaintext, len, false); in dec_payload()
267 struct snp_guest_crypto *crypto = snp_dev->crypto; in verify_and_dec_payload() local
289 if (unlikely((resp_hdr->msg_sz + crypto->a_len) > sz)) in verify_and_dec_payload()
293 return dec_payload(snp_dev, resp, payload, resp_hdr->msg_sz + crypto->a_len); in verify_and_dec_payload()
412 struct snp_guest_crypto *crypto = snp_dev->crypto; in get_report() local
430 resp_len = sizeof(resp->data) + crypto->a_len; in get_report()
451 struct snp_guest_crypto *crypto = snp_dev->crypto; in get_derived_key() local
468 resp_len = sizeof(resp.data) + crypto->a_len; in get_derived_key()
493 struct snp_guest_crypto *crypto = snp_dev->crypto; in get_ext_report() local
531 resp_len = sizeof(resp->data) + crypto->a_len; in get_ext_report()
740 snp_dev->crypto = init_crypto(snp_dev, snp_dev->vmpck, VMPCK_KEY_LEN); in sev_guest_probe()
741 if (!snp_dev->crypto) in sev_guest_probe()
779 deinit_crypto(snp_dev->crypto); in sev_guest_remove()