• Home
  • Raw
  • Download

Lines Matching +full:aes +full:- +full:gcm

2  * AES GCM routines supporting the Power 7+ Nest Accelerators driver
23 #include <crypto/aes.h>
25 #include <crypto/gcm.h>
40 struct nx_csbcpb *csbcpb = nx_ctx->csbcpb; in gcm_aes_nx_set_key()
41 struct nx_csbcpb *csbcpb_aead = nx_ctx->csbcpb_aead; in gcm_aes_nx_set_key()
49 nx_ctx->ap = &nx_ctx->props[NX_PROPS_AES_128]; in gcm_aes_nx_set_key()
54 nx_ctx->ap = &nx_ctx->props[NX_PROPS_AES_192]; in gcm_aes_nx_set_key()
59 nx_ctx->ap = &nx_ctx->props[NX_PROPS_AES_256]; in gcm_aes_nx_set_key()
62 return -EINVAL; in gcm_aes_nx_set_key()
65 csbcpb->cpb.hdr.mode = NX_MODE_AES_GCM; in gcm_aes_nx_set_key()
66 memcpy(csbcpb->cpb.aes_gcm.key, in_key, key_len); in gcm_aes_nx_set_key()
68 csbcpb_aead->cpb.hdr.mode = NX_MODE_AES_GCA; in gcm_aes_nx_set_key()
69 memcpy(csbcpb_aead->cpb.aes_gca.key, in_key, key_len); in gcm_aes_nx_set_key()
79 char *nonce = nx_ctx->priv.gcm.nonce; in gcm4106_aes_nx_set_key()
83 return -EINVAL; in gcm4106_aes_nx_set_key()
85 key_len -= 4; in gcm4106_aes_nx_set_key()
105 return -EINVAL; in gcm4106_aes_nx_setauthsize()
117 struct nx_csbcpb *csbcpb_aead = nx_ctx->csbcpb_aead; in nx_gca()
119 struct nx_sg *nx_sg = nx_ctx->in_sg; in nx_gca()
125 scatterwalk_start(&walk, req->src); in nx_gca()
135 nx_ctx->ap->sglen); in nx_gca()
137 nx_ctx->ap->databytelen/NX_PAGE_SIZE); in nx_gca()
144 to_process = min_t(u64, nbytes - processed, in nx_gca()
145 nx_ctx->ap->databytelen); in nx_gca()
147 NX_PAGE_SIZE * (max_sg_len - 1)); in nx_gca()
149 nx_sg = nx_walk_and_build(nx_ctx->in_sg, max_sg_len, in nx_gca()
150 req->src, processed, &to_process); in nx_gca()
157 nx_ctx->op_aead.inlen = (nx_ctx->in_sg - nx_sg) in nx_gca()
160 rc = nx_hcall_sync(nx_ctx, &nx_ctx->op_aead, in nx_gca()
161 req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP); in nx_gca()
165 memcpy(csbcpb_aead->cpb.aes_gca.in_pat, in nx_gca()
166 csbcpb_aead->cpb.aes_gca.out_pat, in nx_gca()
170 atomic_inc(&(nx_ctx->stats->aes_ops)); in nx_gca()
171 atomic64_add(assoclen, &(nx_ctx->stats->aes_bytes)); in nx_gca()
176 memcpy(out, csbcpb_aead->cpb.aes_gca.out_pat, AES_BLOCK_SIZE); in nx_gca()
187 struct nx_csbcpb *csbcpb = nx_ctx->csbcpb; in gmac()
194 csbcpb->cpb.hdr.mode = NX_MODE_AES_GMAC; in gmac()
200 nx_ctx->ap->sglen); in gmac()
202 nx_ctx->ap->databytelen/NX_PAGE_SIZE); in gmac()
205 memcpy(csbcpb->cpb.aes_gcm.iv_or_cnt, desc->info, AES_BLOCK_SIZE); in gmac()
212 to_process = min_t(u64, nbytes - processed, in gmac()
213 nx_ctx->ap->databytelen); in gmac()
215 NX_PAGE_SIZE * (max_sg_len - 1)); in gmac()
217 nx_sg = nx_walk_and_build(nx_ctx->in_sg, max_sg_len, in gmac()
218 req->src, processed, &to_process); in gmac()
225 nx_ctx->op.inlen = (nx_ctx->in_sg - nx_sg) in gmac()
228 csbcpb->cpb.aes_gcm.bit_length_data = 0; in gmac()
229 csbcpb->cpb.aes_gcm.bit_length_aad = 8 * nbytes; in gmac()
231 rc = nx_hcall_sync(nx_ctx, &nx_ctx->op, in gmac()
232 req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP); in gmac()
236 memcpy(csbcpb->cpb.aes_gcm.in_pat_or_aad, in gmac()
237 csbcpb->cpb.aes_gcm.out_pat_or_mac, AES_BLOCK_SIZE); in gmac()
238 memcpy(csbcpb->cpb.aes_gcm.in_s0, in gmac()
239 csbcpb->cpb.aes_gcm.out_s0, AES_BLOCK_SIZE); in gmac()
243 atomic_inc(&(nx_ctx->stats->aes_ops)); in gmac()
244 atomic64_add(assoclen, &(nx_ctx->stats->aes_bytes)); in gmac()
250 /* Restore GCM mode */ in gmac()
251 csbcpb->cpb.hdr.mode = NX_MODE_AES_GCM; in gmac()
261 struct nx_csbcpb *csbcpb = nx_ctx->csbcpb; in gcm_empty()
266 /* For scenarios where the input message is zero length, AES CTR mode in gcm_empty()
269 * value. - nx_wb 4.8.1.3 */ in gcm_empty()
272 csbcpb->cpb.hdr.mode = NX_MODE_AES_ECB; in gcm_empty()
273 memcpy(csbcpb->cpb.aes_ecb.key, csbcpb->cpb.aes_gcm.key, in gcm_empty()
274 sizeof(csbcpb->cpb.aes_ecb.key)); in gcm_empty()
283 in_sg = nx_build_sg_list(nx_ctx->in_sg, (u8 *) desc->info, in gcm_empty()
284 &len, nx_ctx->ap->sglen); in gcm_empty()
287 return -EINVAL; in gcm_empty()
290 out_sg = nx_build_sg_list(nx_ctx->out_sg, (u8 *) out, &len, in gcm_empty()
291 nx_ctx->ap->sglen); in gcm_empty()
294 return -EINVAL; in gcm_empty()
296 nx_ctx->op.inlen = (nx_ctx->in_sg - in_sg) * sizeof(struct nx_sg); in gcm_empty()
297 nx_ctx->op.outlen = (nx_ctx->out_sg - out_sg) * sizeof(struct nx_sg); in gcm_empty()
299 rc = nx_hcall_sync(nx_ctx, &nx_ctx->op, in gcm_empty()
300 desc->flags & CRYPTO_TFM_REQ_MAY_SLEEP); in gcm_empty()
303 atomic_inc(&(nx_ctx->stats->aes_ops)); in gcm_empty()
306 memcpy(csbcpb->cpb.aes_gcm.out_pat_or_mac, out, in gcm_empty()
310 csbcpb->cpb.hdr.mode = NX_MODE_AES_GCM; in gcm_empty()
313 * ECB key uses the same region that GCM AAD and counter, so it's safe in gcm_empty()
316 memset(csbcpb->cpb.aes_ecb.key, 0, sizeof(csbcpb->cpb.aes_ecb.key)); in gcm_empty()
327 struct nx_csbcpb *csbcpb = nx_ctx->csbcpb; in gcm_aes_nx_crypt()
329 unsigned int nbytes = req->cryptlen; in gcm_aes_nx_crypt()
332 int rc = -EINVAL; in gcm_aes_nx_crypt()
334 spin_lock_irqsave(&nx_ctx->lock, irq_flags); in gcm_aes_nx_crypt()
336 desc.info = rctx->iv; in gcm_aes_nx_crypt()
352 csbcpb->cpb.aes_gcm.bit_length_aad = assoclen * 8; in gcm_aes_nx_crypt()
354 rc = nx_gca(nx_ctx, req, csbcpb->cpb.aes_gcm.in_pat_or_aad, in gcm_aes_nx_crypt()
366 nbytes -= crypto_aead_authsize(crypto_aead_reqtfm(req)); in gcm_aes_nx_crypt()
370 to_process = nbytes - processed; in gcm_aes_nx_crypt()
372 csbcpb->cpb.aes_gcm.bit_length_data = nbytes * 8; in gcm_aes_nx_crypt()
373 rc = nx_build_sg_lists(nx_ctx, &desc, req->dst, in gcm_aes_nx_crypt()
374 req->src, &to_process, in gcm_aes_nx_crypt()
375 processed + req->assoclen, in gcm_aes_nx_crypt()
376 csbcpb->cpb.aes_gcm.iv_or_cnt); in gcm_aes_nx_crypt()
387 rc = nx_hcall_sync(nx_ctx, &nx_ctx->op, in gcm_aes_nx_crypt()
388 req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP); in gcm_aes_nx_crypt()
392 memcpy(desc.info, csbcpb->cpb.aes_gcm.out_cnt, AES_BLOCK_SIZE); in gcm_aes_nx_crypt()
393 memcpy(csbcpb->cpb.aes_gcm.in_pat_or_aad, in gcm_aes_nx_crypt()
394 csbcpb->cpb.aes_gcm.out_pat_or_mac, AES_BLOCK_SIZE); in gcm_aes_nx_crypt()
395 memcpy(csbcpb->cpb.aes_gcm.in_s0, in gcm_aes_nx_crypt()
396 csbcpb->cpb.aes_gcm.out_s0, AES_BLOCK_SIZE); in gcm_aes_nx_crypt()
400 atomic_inc(&(nx_ctx->stats->aes_ops)); in gcm_aes_nx_crypt()
401 atomic64_add(csbcpb->csb.processed_byte_count, in gcm_aes_nx_crypt()
402 &(nx_ctx->stats->aes_bytes)); in gcm_aes_nx_crypt()
411 csbcpb->cpb.aes_gcm.out_pat_or_mac, in gcm_aes_nx_crypt()
412 req->dst, req->assoclen + nbytes, in gcm_aes_nx_crypt()
416 u8 *itag = nx_ctx->priv.gcm.iauth_tag; in gcm_aes_nx_crypt()
417 u8 *otag = csbcpb->cpb.aes_gcm.out_pat_or_mac; in gcm_aes_nx_crypt()
420 itag, req->src, req->assoclen + nbytes, in gcm_aes_nx_crypt()
425 -EBADMSG : 0; in gcm_aes_nx_crypt()
428 spin_unlock_irqrestore(&nx_ctx->lock, irq_flags); in gcm_aes_nx_crypt()
435 char *iv = rctx->iv; in gcm_aes_nx_encrypt()
437 memcpy(iv, req->iv, GCM_AES_IV_SIZE); in gcm_aes_nx_encrypt()
439 return gcm_aes_nx_crypt(req, 1, req->assoclen); in gcm_aes_nx_encrypt()
445 char *iv = rctx->iv; in gcm_aes_nx_decrypt()
447 memcpy(iv, req->iv, GCM_AES_IV_SIZE); in gcm_aes_nx_decrypt()
449 return gcm_aes_nx_crypt(req, 0, req->assoclen); in gcm_aes_nx_decrypt()
457 char *iv = rctx->iv; in gcm4106_aes_nx_encrypt()
458 char *nonce = nx_ctx->priv.gcm.nonce; in gcm4106_aes_nx_encrypt()
461 memcpy(iv + NX_GCM4106_NONCE_LEN, req->iv, 8); in gcm4106_aes_nx_encrypt()
463 if (req->assoclen < 8) in gcm4106_aes_nx_encrypt()
464 return -EINVAL; in gcm4106_aes_nx_encrypt()
466 return gcm_aes_nx_crypt(req, 1, req->assoclen - 8); in gcm4106_aes_nx_encrypt()
474 char *iv = rctx->iv; in gcm4106_aes_nx_decrypt()
475 char *nonce = nx_ctx->priv.gcm.nonce; in gcm4106_aes_nx_decrypt()
478 memcpy(iv + NX_GCM4106_NONCE_LEN, req->iv, 8); in gcm4106_aes_nx_decrypt()
480 if (req->assoclen < 8) in gcm4106_aes_nx_decrypt()
481 return -EINVAL; in gcm4106_aes_nx_decrypt()
483 return gcm_aes_nx_crypt(req, 0, req->assoclen - 8); in gcm4106_aes_nx_decrypt()
489 * blkcipher_walk_done under the covers, which doesn't use walk->blocksize,
490 * but instead uses this tfm->blocksize. */
493 .cra_name = "gcm(aes)",
494 .cra_driver_name = "gcm-aes-nx",
511 .cra_name = "rfc4106(gcm(aes))",
512 .cra_driver_name = "rfc4106-gcm-aes-nx",