Lines Matching full:crypto
19 #include <crypto/aead.h>
48 struct snp_guest_crypto *crypto; member
162 struct snp_guest_crypto *crypto; in init_crypto() local
164 crypto = kzalloc(sizeof(*crypto), GFP_KERNEL_ACCOUNT); in init_crypto()
165 if (!crypto) in init_crypto()
168 crypto->tfm = crypto_alloc_aead("gcm(aes)", 0, 0); in init_crypto()
169 if (IS_ERR(crypto->tfm)) in init_crypto()
172 if (crypto_aead_setkey(crypto->tfm, key, keylen)) in init_crypto()
175 crypto->iv_len = crypto_aead_ivsize(crypto->tfm); in init_crypto()
176 crypto->iv = kmalloc(crypto->iv_len, GFP_KERNEL_ACCOUNT); in init_crypto()
177 if (!crypto->iv) in init_crypto()
180 if (crypto_aead_authsize(crypto->tfm) > MAX_AUTHTAG_LEN) { in init_crypto()
181 if (crypto_aead_setauthsize(crypto->tfm, MAX_AUTHTAG_LEN)) { in init_crypto()
187 crypto->a_len = crypto_aead_authsize(crypto->tfm); in init_crypto()
188 crypto->authtag = kmalloc(crypto->a_len, GFP_KERNEL_ACCOUNT); in init_crypto()
189 if (!crypto->authtag) in init_crypto()
192 return crypto; in init_crypto()
195 kfree(crypto->iv); in init_crypto()
197 crypto_free_aead(crypto->tfm); in init_crypto()
199 kfree(crypto); in init_crypto()
204 static void deinit_crypto(struct snp_guest_crypto *crypto) in deinit_crypto() argument
206 crypto_free_aead(crypto->tfm); in deinit_crypto()
207 kfree(crypto->iv); in deinit_crypto()
208 kfree(crypto->authtag); in deinit_crypto()
209 kfree(crypto); in deinit_crypto()
212 static int enc_dec_message(struct snp_guest_crypto *crypto, struct snp_guest_msg *msg, in enc_dec_message() argument
221 req = aead_request_alloc(crypto->tfm, GFP_KERNEL); in enc_dec_message()
236 sg_set_buf(&src[2], hdr->authtag, crypto->a_len); in enc_dec_message()
241 sg_set_buf(&dst[2], hdr->authtag, crypto->a_len); in enc_dec_message()
244 aead_request_set_tfm(req, crypto->tfm); in enc_dec_message()
247 aead_request_set_crypt(req, src, dst, len, crypto->iv); in enc_dec_message()
257 struct snp_guest_crypto *crypto = snp_dev->crypto; in __enc_payload() local
260 memset(crypto->iv, 0, crypto->iv_len); in __enc_payload()
261 memcpy(crypto->iv, &hdr->msg_seqno, sizeof(hdr->msg_seqno)); in __enc_payload()
263 return enc_dec_message(crypto, msg, plaintext, msg->payload, len, true); in __enc_payload()
269 struct snp_guest_crypto *crypto = snp_dev->crypto; in dec_payload() local
273 memset(crypto->iv, 0, crypto->iv_len); in dec_payload()
274 memcpy(crypto->iv, &hdr->msg_seqno, sizeof(hdr->msg_seqno)); in dec_payload()
276 return enc_dec_message(crypto, msg, msg->payload, plaintext, len, false); in dec_payload()
281 struct snp_guest_crypto *crypto = snp_dev->crypto; in verify_and_dec_payload() local
306 if (unlikely((resp_hdr->msg_sz + crypto->a_len) > sz)) in verify_and_dec_payload()
310 return dec_payload(snp_dev, resp, payload, resp_hdr->msg_sz + crypto->a_len); in verify_and_dec_payload()
480 struct snp_guest_crypto *crypto = snp_dev->crypto; in get_report() local
498 resp_len = sizeof(resp->data) + crypto->a_len; in get_report()
520 struct snp_guest_crypto *crypto = snp_dev->crypto; in get_derived_key() local
536 resp_len = sizeof(resp.data) + crypto->a_len; in get_derived_key()
561 struct snp_guest_crypto *crypto = snp_dev->crypto; in get_ext_report() local
598 resp_len = sizeof(resp->data) + crypto->a_len; in get_ext_report()
810 snp_dev->crypto = init_crypto(snp_dev, snp_dev->vmpck, VMPCK_KEY_LEN); in sev_guest_probe()
811 if (!snp_dev->crypto) in sev_guest_probe()
849 deinit_crypto(snp_dev->crypto); in sev_guest_remove()