23 #include <crypto/aes.h>
26 #include <linux/module.h>
27 #include <linux/types.h>
35 static int gcm_aes_nx_set_key(
struct crypto_aead *tfm,
66 memcpy(csbcpb->
cpb.aes_gcm.key, in_key, key_len);
69 memcpy(csbcpb_aead->
cpb.aes_gca.key, in_key, key_len);
74 static int gcm4106_aes_nx_set_key(
struct crypto_aead *tfm,
87 rc = gcm_aes_nx_set_key(tfm, in_key, key_len);
91 memcpy(nonce, in_key + key_len, 4);
96 static int gcm_aes_nx_setauthsize(
struct crypto_aead *tfm,
97 unsigned int authsize)
99 if (authsize > crypto_aead_alg(tfm)->maxauthsize)
102 crypto_aead_crt(tfm)->authsize = authsize;
107 static int gcm4106_aes_nx_setauthsize(
struct crypto_aead *tfm,
108 unsigned int authsize)
119 crypto_aead_crt(tfm)->authsize = authsize;
148 nx_ctx->
op_aead.inlen = (nx_ctx->
in_sg - nx_sg) *
sizeof(
struct nx_sg);
163 static int gcm_aes_nx_crypt(
struct aead_request *req,
int enc)
171 if (nbytes > nx_ctx->
ap->databytelen)
186 desc.tfm = crypto_alloc_blkcipher(
"ctr(aes)", 0, 0);
187 if (IS_ERR(
desc.tfm)) {
192 crypto_blkcipher_setkey(
desc.tfm, csbcpb->
cpb.aes_gcm.key,
198 crypto_blkcipher_encrypt_iv(&
desc, req->
dst, &
sg,
201 crypto_blkcipher_decrypt_iv(&
desc, req->
dst, &
sg,
203 crypto_free_blkcipher(
desc.tfm);
211 csbcpb->
cpb.aes_gcm.bit_length_aad = req->
assoclen * 8;
214 rc = nx_gca(nx_ctx, req, csbcpb->
cpb.aes_gcm.in_pat_or_aad);
224 csbcpb->
cpb.aes_gcm.bit_length_data = nbytes * 8;
227 csbcpb->
cpb.aes_gcm.iv_or_cnt);
238 &(nx_ctx->
stats->aes_bytes));
244 crypto_aead_authsize(crypto_aead_reqtfm(req)),
248 u8 *otag = csbcpb->
cpb.aes_gcm.out_pat_or_mac;
251 crypto_aead_authsize(crypto_aead_reqtfm(req)),
254 crypto_aead_authsize(crypto_aead_reqtfm(req))) ?
268 return gcm_aes_nx_crypt(req, 1);
278 return gcm_aes_nx_crypt(req, 0);
281 static int gcm4106_aes_nx_encrypt(
struct aead_request *req)
285 char *nonce = nx_ctx->
priv.
gcm.nonce;
290 return gcm_aes_nx_crypt(req, 1);
293 static int gcm4106_aes_nx_decrypt(
struct aead_request *req)
297 char *nonce = nx_ctx->
priv.
gcm.nonce;
302 return gcm_aes_nx_crypt(req, 0);
311 .cra_name =
"gcm(aes)",
312 .cra_driver_name =
"gcm-aes-nx",
324 .setkey = gcm_aes_nx_set_key,
325 .setauthsize = gcm_aes_nx_setauthsize,
326 .encrypt = gcm_aes_nx_encrypt,
327 .decrypt = gcm_aes_nx_decrypt,
332 .cra_name =
"rfc4106(gcm(aes))",
333 .cra_driver_name =
"rfc4106-gcm-aes-nx",
346 .setkey = gcm4106_aes_nx_set_key,
347 .setauthsize = gcm4106_aes_nx_setauthsize,
348 .encrypt = gcm4106_aes_nx_encrypt,
349 .decrypt = gcm4106_aes_nx_decrypt,