Lines Matching refs:crypto

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