^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * AMD Cryptographic Coprocessor (CCP) AES GCM crypto API support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2016,2017 Advanced Micro Devices, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Author: Gary R Hook <gary.hook@amd.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/scatterlist.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/crypto.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <crypto/internal/aead.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <crypto/algapi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <crypto/aes.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <crypto/ctr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <crypto/gcm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <crypto/scatterwalk.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include "ccp-crypto.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) static int ccp_aes_gcm_complete(struct crypto_async_request *async_req, int ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) static int ccp_aes_gcm_setkey(struct crypto_aead *tfm, const u8 *key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) unsigned int key_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) struct ccp_ctx *ctx = crypto_aead_ctx(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) switch (key_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) case AES_KEYSIZE_128:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) ctx->u.aes.type = CCP_AES_TYPE_128;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) case AES_KEYSIZE_192:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) ctx->u.aes.type = CCP_AES_TYPE_192;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) case AES_KEYSIZE_256:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) ctx->u.aes.type = CCP_AES_TYPE_256;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) ctx->u.aes.mode = CCP_AES_MODE_GCM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) ctx->u.aes.key_len = key_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) memcpy(ctx->u.aes.key, key, key_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) sg_init_one(&ctx->u.aes.key_sg, ctx->u.aes.key, key_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) static int ccp_aes_gcm_setauthsize(struct crypto_aead *tfm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) unsigned int authsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) switch (authsize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) case 16:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) case 15:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) case 14:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) case 13:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) case 12:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) case 8:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) case 4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) static int ccp_aes_gcm_crypt(struct aead_request *req, bool encrypt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) struct crypto_aead *tfm = crypto_aead_reqtfm(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) struct ccp_ctx *ctx = crypto_aead_ctx(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) struct ccp_aes_req_ctx *rctx = aead_request_ctx(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) struct scatterlist *iv_sg = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) unsigned int iv_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) if (!ctx->u.aes.key_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) if (ctx->u.aes.mode != CCP_AES_MODE_GCM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) if (!req->iv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) * 5 parts:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) * plaintext/ciphertext input
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) * AAD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) * key
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) * IV
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) * Destination+tag buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) /* Prepare the IV: 12 bytes + an integer (counter) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) memcpy(rctx->iv, req->iv, GCM_AES_IV_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) for (i = 0; i < 3; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) rctx->iv[i + GCM_AES_IV_SIZE] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) rctx->iv[AES_BLOCK_SIZE - 1] = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) /* Set up a scatterlist for the IV */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) iv_sg = &rctx->iv_sg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) iv_len = AES_BLOCK_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) sg_init_one(iv_sg, rctx->iv, iv_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) /* The AAD + plaintext are concatenated in the src buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) memset(&rctx->cmd, 0, sizeof(rctx->cmd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) INIT_LIST_HEAD(&rctx->cmd.entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) rctx->cmd.engine = CCP_ENGINE_AES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) rctx->cmd.u.aes.authsize = crypto_aead_authsize(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) rctx->cmd.u.aes.type = ctx->u.aes.type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) rctx->cmd.u.aes.mode = ctx->u.aes.mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) rctx->cmd.u.aes.action = encrypt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) rctx->cmd.u.aes.key = &ctx->u.aes.key_sg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) rctx->cmd.u.aes.key_len = ctx->u.aes.key_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) rctx->cmd.u.aes.iv = iv_sg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) rctx->cmd.u.aes.iv_len = iv_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) rctx->cmd.u.aes.src = req->src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) rctx->cmd.u.aes.src_len = req->cryptlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) rctx->cmd.u.aes.aad_len = req->assoclen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) /* The cipher text + the tag are in the dst buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) rctx->cmd.u.aes.dst = req->dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) ret = ccp_crypto_enqueue_request(&req->base, &rctx->cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) static int ccp_aes_gcm_encrypt(struct aead_request *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) return ccp_aes_gcm_crypt(req, CCP_AES_ACTION_ENCRYPT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) static int ccp_aes_gcm_decrypt(struct aead_request *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) return ccp_aes_gcm_crypt(req, CCP_AES_ACTION_DECRYPT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) static int ccp_aes_gcm_cra_init(struct crypto_aead *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) struct ccp_ctx *ctx = crypto_aead_ctx(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) ctx->complete = ccp_aes_gcm_complete;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) ctx->u.aes.key_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) crypto_aead_set_reqsize(tfm, sizeof(struct ccp_aes_req_ctx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) static void ccp_aes_gcm_cra_exit(struct crypto_tfm *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) static struct aead_alg ccp_aes_gcm_defaults = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) .setkey = ccp_aes_gcm_setkey,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) .setauthsize = ccp_aes_gcm_setauthsize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) .encrypt = ccp_aes_gcm_encrypt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) .decrypt = ccp_aes_gcm_decrypt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) .init = ccp_aes_gcm_cra_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) .ivsize = GCM_AES_IV_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) .maxauthsize = AES_BLOCK_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) .base = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) .cra_flags = CRYPTO_ALG_ASYNC |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) CRYPTO_ALG_ALLOCATES_MEMORY |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) CRYPTO_ALG_KERN_DRIVER_ONLY |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) CRYPTO_ALG_NEED_FALLBACK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) .cra_blocksize = AES_BLOCK_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) .cra_ctxsize = sizeof(struct ccp_ctx),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) .cra_priority = CCP_CRA_PRIORITY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) .cra_exit = ccp_aes_gcm_cra_exit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) .cra_module = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) struct ccp_aes_aead_def {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) enum ccp_aes_mode mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) unsigned int version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) const char *driver_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) unsigned int blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) unsigned int ivsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) struct aead_alg *alg_defaults;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) static struct ccp_aes_aead_def aes_aead_algs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) .mode = CCP_AES_MODE_GHASH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) .version = CCP_VERSION(5, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) .name = "gcm(aes)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) .driver_name = "gcm-aes-ccp",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) .blocksize = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) .ivsize = AES_BLOCK_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) .alg_defaults = &ccp_aes_gcm_defaults,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) static int ccp_register_aes_aead(struct list_head *head,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) const struct ccp_aes_aead_def *def)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) struct ccp_crypto_aead *ccp_aead;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) struct aead_alg *alg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) ccp_aead = kzalloc(sizeof(*ccp_aead), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) if (!ccp_aead)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) INIT_LIST_HEAD(&ccp_aead->entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) ccp_aead->mode = def->mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) /* Copy the defaults and override as necessary */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) alg = &ccp_aead->alg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) *alg = *def->alg_defaults;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) snprintf(alg->base.cra_name, CRYPTO_MAX_ALG_NAME, "%s", def->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) snprintf(alg->base.cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) def->driver_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) alg->base.cra_blocksize = def->blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) ret = crypto_register_aead(alg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) pr_err("%s aead algorithm registration error (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) alg->base.cra_name, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) kfree(ccp_aead);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) list_add(&ccp_aead->entry, head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) int ccp_register_aes_aeads(struct list_head *head)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) int i, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) unsigned int ccpversion = ccp_version();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) for (i = 0; i < ARRAY_SIZE(aes_aead_algs); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) if (aes_aead_algs[i].version > ccpversion)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) ret = ccp_register_aes_aead(head, &aes_aead_algs[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) }