Lines Matching +full:aes +full:- +full:gcm
1 // SPDX-License-Identifier: GPL-2.0-only
3 * AMD Cryptographic Coprocessor (CCP) AES GCM crypto API support
17 #include <crypto/aes.h>
19 #include <crypto/gcm.h>
22 #include "ccp-crypto.h"
36 ctx->u.aes.type = CCP_AES_TYPE_128; in ccp_aes_gcm_setkey()
39 ctx->u.aes.type = CCP_AES_TYPE_192; in ccp_aes_gcm_setkey()
42 ctx->u.aes.type = CCP_AES_TYPE_256; in ccp_aes_gcm_setkey()
45 return -EINVAL; in ccp_aes_gcm_setkey()
48 ctx->u.aes.mode = CCP_AES_MODE_GCM; in ccp_aes_gcm_setkey()
49 ctx->u.aes.key_len = key_len; in ccp_aes_gcm_setkey()
51 memcpy(ctx->u.aes.key, key, key_len); in ccp_aes_gcm_setkey()
52 sg_init_one(&ctx->u.aes.key_sg, ctx->u.aes.key, key_len); in ccp_aes_gcm_setkey()
70 return -EINVAL; in ccp_aes_gcm_setauthsize()
86 if (!ctx->u.aes.key_len) in ccp_aes_gcm_crypt()
87 return -EINVAL; in ccp_aes_gcm_crypt()
89 if (ctx->u.aes.mode != CCP_AES_MODE_GCM) in ccp_aes_gcm_crypt()
90 return -EINVAL; in ccp_aes_gcm_crypt()
92 if (!req->iv) in ccp_aes_gcm_crypt()
93 return -EINVAL; in ccp_aes_gcm_crypt()
105 memcpy(rctx->iv, req->iv, GCM_AES_IV_SIZE); in ccp_aes_gcm_crypt()
107 rctx->iv[i + GCM_AES_IV_SIZE] = 0; in ccp_aes_gcm_crypt()
108 rctx->iv[AES_BLOCK_SIZE - 1] = 1; in ccp_aes_gcm_crypt()
111 iv_sg = &rctx->iv_sg; in ccp_aes_gcm_crypt()
113 sg_init_one(iv_sg, rctx->iv, iv_len); in ccp_aes_gcm_crypt()
116 memset(&rctx->cmd, 0, sizeof(rctx->cmd)); in ccp_aes_gcm_crypt()
117 INIT_LIST_HEAD(&rctx->cmd.entry); in ccp_aes_gcm_crypt()
118 rctx->cmd.engine = CCP_ENGINE_AES; in ccp_aes_gcm_crypt()
119 rctx->cmd.u.aes.authsize = crypto_aead_authsize(tfm); in ccp_aes_gcm_crypt()
120 rctx->cmd.u.aes.type = ctx->u.aes.type; in ccp_aes_gcm_crypt()
121 rctx->cmd.u.aes.mode = ctx->u.aes.mode; in ccp_aes_gcm_crypt()
122 rctx->cmd.u.aes.action = encrypt; in ccp_aes_gcm_crypt()
123 rctx->cmd.u.aes.key = &ctx->u.aes.key_sg; in ccp_aes_gcm_crypt()
124 rctx->cmd.u.aes.key_len = ctx->u.aes.key_len; in ccp_aes_gcm_crypt()
125 rctx->cmd.u.aes.iv = iv_sg; in ccp_aes_gcm_crypt()
126 rctx->cmd.u.aes.iv_len = iv_len; in ccp_aes_gcm_crypt()
127 rctx->cmd.u.aes.src = req->src; in ccp_aes_gcm_crypt()
128 rctx->cmd.u.aes.src_len = req->cryptlen; in ccp_aes_gcm_crypt()
129 rctx->cmd.u.aes.aad_len = req->assoclen; in ccp_aes_gcm_crypt()
132 rctx->cmd.u.aes.dst = req->dst; in ccp_aes_gcm_crypt()
134 ret = ccp_crypto_enqueue_request(&req->base, &rctx->cmd); in ccp_aes_gcm_crypt()
153 ctx->complete = ccp_aes_gcm_complete; in ccp_aes_gcm_cra_init()
154 ctx->u.aes.key_len = 0; in ccp_aes_gcm_cra_init()
200 .name = "gcm(aes)",
201 .driver_name = "gcm-aes-ccp",
217 return -ENOMEM; in ccp_register_aes_aead()
219 INIT_LIST_HEAD(&ccp_aead->entry); in ccp_register_aes_aead()
221 ccp_aead->mode = def->mode; in ccp_register_aes_aead()
224 alg = &ccp_aead->alg; in ccp_register_aes_aead()
225 *alg = *def->alg_defaults; in ccp_register_aes_aead()
226 snprintf(alg->base.cra_name, CRYPTO_MAX_ALG_NAME, "%s", def->name); in ccp_register_aes_aead()
227 snprintf(alg->base.cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s", in ccp_register_aes_aead()
228 def->driver_name); in ccp_register_aes_aead()
229 alg->base.cra_blocksize = def->blocksize; in ccp_register_aes_aead()
234 alg->base.cra_name, ret); in ccp_register_aes_aead()
239 list_add(&ccp_aead->entry, head); in ccp_register_aes_aead()