Lines Matching defs:crypto

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