xref: /linux/drivers/crypto/ccp/ccp-crypto-aes.c (revision 06d07429858317ded2db7986113a9e0129cd599b)
1d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
22b789435STom Lendacky /*
32b789435STom Lendacky  * AMD Cryptographic Coprocessor (CCP) AES crypto API support
42b789435STom Lendacky  *
5c3b359d6SHook, Gary  * Copyright (C) 2013-2019 Advanced Micro Devices, Inc.
62b789435STom Lendacky  *
72b789435STom Lendacky  * Author: Tom Lendacky <thomas.lendacky@amd.com>
82b789435STom Lendacky  */
92b789435STom Lendacky 
102b789435STom Lendacky #include <linux/module.h>
112b789435STom Lendacky #include <linux/sched.h>
122b789435STom Lendacky #include <linux/delay.h>
132b789435STom Lendacky #include <linux/scatterlist.h>
142b789435STom Lendacky #include <linux/crypto.h>
152b789435STom Lendacky #include <crypto/algapi.h>
162b789435STom Lendacky #include <crypto/aes.h>
172b789435STom Lendacky #include <crypto/ctr.h>
182b789435STom Lendacky #include <crypto/scatterwalk.h>
192b789435STom Lendacky 
202b789435STom Lendacky #include "ccp-crypto.h"
212b789435STom Lendacky 
ccp_aes_complete(struct crypto_async_request * async_req,int ret)222b789435STom Lendacky static int ccp_aes_complete(struct crypto_async_request *async_req, int ret)
232b789435STom Lendacky {
24be9fe620SArd Biesheuvel 	struct skcipher_request *req = skcipher_request_cast(async_req);
25*99c6b20eSHerbert Xu 	struct ccp_ctx *ctx = crypto_skcipher_ctx_dma(
26*99c6b20eSHerbert Xu 		crypto_skcipher_reqtfm(req));
27*99c6b20eSHerbert Xu 	struct ccp_aes_req_ctx *rctx = skcipher_request_ctx_dma(req);
282b789435STom Lendacky 
292b789435STom Lendacky 	if (ret)
302b789435STom Lendacky 		return ret;
312b789435STom Lendacky 
322b789435STom Lendacky 	if (ctx->u.aes.mode != CCP_AES_MODE_ECB)
33be9fe620SArd Biesheuvel 		memcpy(req->iv, rctx->iv, AES_BLOCK_SIZE);
342b789435STom Lendacky 
352b789435STom Lendacky 	return 0;
362b789435STom Lendacky }
372b789435STom Lendacky 
ccp_aes_setkey(struct crypto_skcipher * tfm,const u8 * key,unsigned int key_len)38be9fe620SArd Biesheuvel static int ccp_aes_setkey(struct crypto_skcipher *tfm, const u8 *key,
392b789435STom Lendacky 			  unsigned int key_len)
402b789435STom Lendacky {
41be9fe620SArd Biesheuvel 	struct ccp_crypto_skcipher_alg *alg = ccp_crypto_skcipher_alg(tfm);
42*99c6b20eSHerbert Xu 	struct ccp_ctx *ctx = crypto_skcipher_ctx_dma(tfm);
432b789435STom Lendacky 
442b789435STom Lendacky 	switch (key_len) {
452b789435STom Lendacky 	case AES_KEYSIZE_128:
462b789435STom Lendacky 		ctx->u.aes.type = CCP_AES_TYPE_128;
472b789435STom Lendacky 		break;
482b789435STom Lendacky 	case AES_KEYSIZE_192:
492b789435STom Lendacky 		ctx->u.aes.type = CCP_AES_TYPE_192;
502b789435STom Lendacky 		break;
512b789435STom Lendacky 	case AES_KEYSIZE_256:
522b789435STom Lendacky 		ctx->u.aes.type = CCP_AES_TYPE_256;
532b789435STom Lendacky 		break;
542b789435STom Lendacky 	default:
552b789435STom Lendacky 		return -EINVAL;
562b789435STom Lendacky 	}
572b789435STom Lendacky 	ctx->u.aes.mode = alg->mode;
582b789435STom Lendacky 	ctx->u.aes.key_len = key_len;
592b789435STom Lendacky 
602b789435STom Lendacky 	memcpy(ctx->u.aes.key, key, key_len);
612b789435STom Lendacky 	sg_init_one(&ctx->u.aes.key_sg, ctx->u.aes.key, key_len);
622b789435STom Lendacky 
632b789435STom Lendacky 	return 0;
642b789435STom Lendacky }
652b789435STom Lendacky 
ccp_aes_crypt(struct skcipher_request * req,bool encrypt)66be9fe620SArd Biesheuvel static int ccp_aes_crypt(struct skcipher_request *req, bool encrypt)
672b789435STom Lendacky {
68be9fe620SArd Biesheuvel 	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
69*99c6b20eSHerbert Xu 	struct ccp_ctx *ctx = crypto_skcipher_ctx_dma(tfm);
70*99c6b20eSHerbert Xu 	struct ccp_aes_req_ctx *rctx = skcipher_request_ctx_dma(req);
712b789435STom Lendacky 	struct scatterlist *iv_sg = NULL;
722b789435STom Lendacky 	unsigned int iv_len = 0;
732b789435STom Lendacky 
74369f3dabSTom Lendacky 	if (!ctx->u.aes.key_len)
752b789435STom Lendacky 		return -EINVAL;
762b789435STom Lendacky 
772b789435STom Lendacky 	if (((ctx->u.aes.mode == CCP_AES_MODE_ECB) ||
78c3b359d6SHook, Gary 	     (ctx->u.aes.mode == CCP_AES_MODE_CBC)) &&
79be9fe620SArd Biesheuvel 	    (req->cryptlen & (AES_BLOCK_SIZE - 1)))
802b789435STom Lendacky 		return -EINVAL;
812b789435STom Lendacky 
822b789435STom Lendacky 	if (ctx->u.aes.mode != CCP_AES_MODE_ECB) {
83be9fe620SArd Biesheuvel 		if (!req->iv)
842b789435STom Lendacky 			return -EINVAL;
852b789435STom Lendacky 
86be9fe620SArd Biesheuvel 		memcpy(rctx->iv, req->iv, AES_BLOCK_SIZE);
872b789435STom Lendacky 		iv_sg = &rctx->iv_sg;
882b789435STom Lendacky 		iv_len = AES_BLOCK_SIZE;
892b789435STom Lendacky 		sg_init_one(iv_sg, rctx->iv, iv_len);
902b789435STom Lendacky 	}
912b789435STom Lendacky 
922b789435STom Lendacky 	memset(&rctx->cmd, 0, sizeof(rctx->cmd));
932b789435STom Lendacky 	INIT_LIST_HEAD(&rctx->cmd.entry);
942b789435STom Lendacky 	rctx->cmd.engine = CCP_ENGINE_AES;
952b789435STom Lendacky 	rctx->cmd.u.aes.type = ctx->u.aes.type;
962b789435STom Lendacky 	rctx->cmd.u.aes.mode = ctx->u.aes.mode;
972b789435STom Lendacky 	rctx->cmd.u.aes.action =
982b789435STom Lendacky 		(encrypt) ? CCP_AES_ACTION_ENCRYPT : CCP_AES_ACTION_DECRYPT;
992b789435STom Lendacky 	rctx->cmd.u.aes.key = &ctx->u.aes.key_sg;
1002b789435STom Lendacky 	rctx->cmd.u.aes.key_len = ctx->u.aes.key_len;
1012b789435STom Lendacky 	rctx->cmd.u.aes.iv = iv_sg;
1022b789435STom Lendacky 	rctx->cmd.u.aes.iv_len = iv_len;
1032b789435STom Lendacky 	rctx->cmd.u.aes.src = req->src;
104be9fe620SArd Biesheuvel 	rctx->cmd.u.aes.src_len = req->cryptlen;
1052b789435STom Lendacky 	rctx->cmd.u.aes.dst = req->dst;
1062b789435STom Lendacky 
107735efea6SMinghao Chi 	return ccp_crypto_enqueue_request(&req->base, &rctx->cmd);
1082b789435STom Lendacky }
1092b789435STom Lendacky 
ccp_aes_encrypt(struct skcipher_request * req)110be9fe620SArd Biesheuvel static int ccp_aes_encrypt(struct skcipher_request *req)
1112b789435STom Lendacky {
1122b789435STom Lendacky 	return ccp_aes_crypt(req, true);
1132b789435STom Lendacky }
1142b789435STom Lendacky 
ccp_aes_decrypt(struct skcipher_request * req)115be9fe620SArd Biesheuvel static int ccp_aes_decrypt(struct skcipher_request *req)
1162b789435STom Lendacky {
1172b789435STom Lendacky 	return ccp_aes_crypt(req, false);
1182b789435STom Lendacky }
1192b789435STom Lendacky 
ccp_aes_init_tfm(struct crypto_skcipher * tfm)120be9fe620SArd Biesheuvel static int ccp_aes_init_tfm(struct crypto_skcipher *tfm)
1212b789435STom Lendacky {
122*99c6b20eSHerbert Xu 	struct ccp_ctx *ctx = crypto_skcipher_ctx_dma(tfm);
1232b789435STom Lendacky 
1242b789435STom Lendacky 	ctx->complete = ccp_aes_complete;
1252b789435STom Lendacky 	ctx->u.aes.key_len = 0;
1262b789435STom Lendacky 
127be9fe620SArd Biesheuvel 	crypto_skcipher_set_reqsize(tfm, sizeof(struct ccp_aes_req_ctx));
1282b789435STom Lendacky 
1292b789435STom Lendacky 	return 0;
1302b789435STom Lendacky }
1312b789435STom Lendacky 
ccp_aes_rfc3686_complete(struct crypto_async_request * async_req,int ret)1322b789435STom Lendacky static int ccp_aes_rfc3686_complete(struct crypto_async_request *async_req,
1332b789435STom Lendacky 				    int ret)
1342b789435STom Lendacky {
135be9fe620SArd Biesheuvel 	struct skcipher_request *req = skcipher_request_cast(async_req);
136*99c6b20eSHerbert Xu 	struct ccp_aes_req_ctx *rctx = skcipher_request_ctx_dma(req);
1372b789435STom Lendacky 
1382b789435STom Lendacky 	/* Restore the original pointer */
139be9fe620SArd Biesheuvel 	req->iv = rctx->rfc3686_info;
1402b789435STom Lendacky 
1412b789435STom Lendacky 	return ccp_aes_complete(async_req, ret);
1422b789435STom Lendacky }
1432b789435STom Lendacky 
ccp_aes_rfc3686_setkey(struct crypto_skcipher * tfm,const u8 * key,unsigned int key_len)144be9fe620SArd Biesheuvel static int ccp_aes_rfc3686_setkey(struct crypto_skcipher *tfm, const u8 *key,
1452b789435STom Lendacky 				  unsigned int key_len)
1462b789435STom Lendacky {
147*99c6b20eSHerbert Xu 	struct ccp_ctx *ctx = crypto_skcipher_ctx_dma(tfm);
1482b789435STom Lendacky 
1492b789435STom Lendacky 	if (key_len < CTR_RFC3686_NONCE_SIZE)
1502b789435STom Lendacky 		return -EINVAL;
1512b789435STom Lendacky 
1522b789435STom Lendacky 	key_len -= CTR_RFC3686_NONCE_SIZE;
1532b789435STom Lendacky 	memcpy(ctx->u.aes.nonce, key + key_len, CTR_RFC3686_NONCE_SIZE);
1542b789435STom Lendacky 
1552b789435STom Lendacky 	return ccp_aes_setkey(tfm, key, key_len);
1562b789435STom Lendacky }
1572b789435STom Lendacky 
ccp_aes_rfc3686_crypt(struct skcipher_request * req,bool encrypt)158be9fe620SArd Biesheuvel static int ccp_aes_rfc3686_crypt(struct skcipher_request *req, bool encrypt)
1592b789435STom Lendacky {
160be9fe620SArd Biesheuvel 	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
161*99c6b20eSHerbert Xu 	struct ccp_ctx *ctx = crypto_skcipher_ctx_dma(tfm);
162*99c6b20eSHerbert Xu 	struct ccp_aes_req_ctx *rctx = skcipher_request_ctx_dma(req);
1632b789435STom Lendacky 	u8 *iv;
1642b789435STom Lendacky 
1652b789435STom Lendacky 	/* Initialize the CTR block */
1662b789435STom Lendacky 	iv = rctx->rfc3686_iv;
1672b789435STom Lendacky 	memcpy(iv, ctx->u.aes.nonce, CTR_RFC3686_NONCE_SIZE);
1682b789435STom Lendacky 
1692b789435STom Lendacky 	iv += CTR_RFC3686_NONCE_SIZE;
170be9fe620SArd Biesheuvel 	memcpy(iv, req->iv, CTR_RFC3686_IV_SIZE);
1712b789435STom Lendacky 
1722b789435STom Lendacky 	iv += CTR_RFC3686_IV_SIZE;
1732b789435STom Lendacky 	*(__be32 *)iv = cpu_to_be32(1);
1742b789435STom Lendacky 
1752b789435STom Lendacky 	/* Point to the new IV */
176be9fe620SArd Biesheuvel 	rctx->rfc3686_info = req->iv;
177be9fe620SArd Biesheuvel 	req->iv = rctx->rfc3686_iv;
1782b789435STom Lendacky 
1792b789435STom Lendacky 	return ccp_aes_crypt(req, encrypt);
1802b789435STom Lendacky }
1812b789435STom Lendacky 
ccp_aes_rfc3686_encrypt(struct skcipher_request * req)182be9fe620SArd Biesheuvel static int ccp_aes_rfc3686_encrypt(struct skcipher_request *req)
1832b789435STom Lendacky {
1842b789435STom Lendacky 	return ccp_aes_rfc3686_crypt(req, true);
1852b789435STom Lendacky }
1862b789435STom Lendacky 
ccp_aes_rfc3686_decrypt(struct skcipher_request * req)187be9fe620SArd Biesheuvel static int ccp_aes_rfc3686_decrypt(struct skcipher_request *req)
1882b789435STom Lendacky {
1892b789435STom Lendacky 	return ccp_aes_rfc3686_crypt(req, false);
1902b789435STom Lendacky }
1912b789435STom Lendacky 
ccp_aes_rfc3686_init_tfm(struct crypto_skcipher * tfm)192be9fe620SArd Biesheuvel static int ccp_aes_rfc3686_init_tfm(struct crypto_skcipher *tfm)
1932b789435STom Lendacky {
194*99c6b20eSHerbert Xu 	struct ccp_ctx *ctx = crypto_skcipher_ctx_dma(tfm);
1952b789435STom Lendacky 
1962b789435STom Lendacky 	ctx->complete = ccp_aes_rfc3686_complete;
1972b789435STom Lendacky 	ctx->u.aes.key_len = 0;
1982b789435STom Lendacky 
199*99c6b20eSHerbert Xu 	crypto_skcipher_set_reqsize_dma(tfm, sizeof(struct ccp_aes_req_ctx));
2002b789435STom Lendacky 
2012b789435STom Lendacky 	return 0;
2022b789435STom Lendacky }
2032b789435STom Lendacky 
204be9fe620SArd Biesheuvel static const struct skcipher_alg ccp_aes_defaults = {
2052b789435STom Lendacky 	.setkey			= ccp_aes_setkey,
2062b789435STom Lendacky 	.encrypt		= ccp_aes_encrypt,
2072b789435STom Lendacky 	.decrypt		= ccp_aes_decrypt,
2082b789435STom Lendacky 	.min_keysize		= AES_MIN_KEY_SIZE,
2092b789435STom Lendacky 	.max_keysize		= AES_MAX_KEY_SIZE,
210be9fe620SArd Biesheuvel 	.init			= ccp_aes_init_tfm,
2112b789435STom Lendacky 
212be9fe620SArd Biesheuvel 	.base.cra_flags		= CRYPTO_ALG_ASYNC |
213b8aa7dc5SMikulas Patocka 				  CRYPTO_ALG_ALLOCATES_MEMORY |
2142b789435STom Lendacky 				  CRYPTO_ALG_KERN_DRIVER_ONLY |
2152b789435STom Lendacky 				  CRYPTO_ALG_NEED_FALLBACK,
216be9fe620SArd Biesheuvel 	.base.cra_blocksize	= AES_BLOCK_SIZE,
217*99c6b20eSHerbert Xu 	.base.cra_ctxsize	= sizeof(struct ccp_ctx) + CRYPTO_DMA_PADDING,
218be9fe620SArd Biesheuvel 	.base.cra_priority	= CCP_CRA_PRIORITY,
219be9fe620SArd Biesheuvel 	.base.cra_module	= THIS_MODULE,
220be9fe620SArd Biesheuvel };
221be9fe620SArd Biesheuvel 
222be9fe620SArd Biesheuvel static const struct skcipher_alg ccp_aes_rfc3686_defaults = {
2232b789435STom Lendacky 	.setkey			= ccp_aes_rfc3686_setkey,
2242b789435STom Lendacky 	.encrypt		= ccp_aes_rfc3686_encrypt,
2252b789435STom Lendacky 	.decrypt		= ccp_aes_rfc3686_decrypt,
2262b789435STom Lendacky 	.min_keysize		= AES_MIN_KEY_SIZE + CTR_RFC3686_NONCE_SIZE,
2272b789435STom Lendacky 	.max_keysize		= AES_MAX_KEY_SIZE + CTR_RFC3686_NONCE_SIZE,
228be9fe620SArd Biesheuvel 	.init			= ccp_aes_rfc3686_init_tfm,
229be9fe620SArd Biesheuvel 
230be9fe620SArd Biesheuvel 	.base.cra_flags		= CRYPTO_ALG_ASYNC |
231b8aa7dc5SMikulas Patocka 				  CRYPTO_ALG_ALLOCATES_MEMORY |
232be9fe620SArd Biesheuvel 				  CRYPTO_ALG_KERN_DRIVER_ONLY |
233be9fe620SArd Biesheuvel 				  CRYPTO_ALG_NEED_FALLBACK,
234be9fe620SArd Biesheuvel 	.base.cra_blocksize	= CTR_RFC3686_BLOCK_SIZE,
235*99c6b20eSHerbert Xu 	.base.cra_ctxsize	= sizeof(struct ccp_ctx) + CRYPTO_DMA_PADDING,
236be9fe620SArd Biesheuvel 	.base.cra_priority	= CCP_CRA_PRIORITY,
237be9fe620SArd Biesheuvel 	.base.cra_module	= THIS_MODULE,
2382b789435STom Lendacky };
2392b789435STom Lendacky 
2402b789435STom Lendacky struct ccp_aes_def {
2412b789435STom Lendacky 	enum ccp_aes_mode mode;
242c7019c4dSGary R Hook 	unsigned int version;
2432b789435STom Lendacky 	const char *name;
2442b789435STom Lendacky 	const char *driver_name;
2452b789435STom Lendacky 	unsigned int blocksize;
2462b789435STom Lendacky 	unsigned int ivsize;
247be9fe620SArd Biesheuvel 	const struct skcipher_alg *alg_defaults;
2482b789435STom Lendacky };
2492b789435STom Lendacky 
2502b789435STom Lendacky static struct ccp_aes_def aes_algs[] = {
2512b789435STom Lendacky 	{
2522b789435STom Lendacky 		.mode		= CCP_AES_MODE_ECB,
253c7019c4dSGary R Hook 		.version	= CCP_VERSION(3, 0),
2542b789435STom Lendacky 		.name		= "ecb(aes)",
2552b789435STom Lendacky 		.driver_name	= "ecb-aes-ccp",
2562b789435STom Lendacky 		.blocksize	= AES_BLOCK_SIZE,
2572b789435STom Lendacky 		.ivsize		= 0,
2582b789435STom Lendacky 		.alg_defaults	= &ccp_aes_defaults,
2592b789435STom Lendacky 	},
2602b789435STom Lendacky 	{
2612b789435STom Lendacky 		.mode		= CCP_AES_MODE_CBC,
262c7019c4dSGary R Hook 		.version	= CCP_VERSION(3, 0),
2632b789435STom Lendacky 		.name		= "cbc(aes)",
2642b789435STom Lendacky 		.driver_name	= "cbc-aes-ccp",
2652b789435STom Lendacky 		.blocksize	= AES_BLOCK_SIZE,
2662b789435STom Lendacky 		.ivsize		= AES_BLOCK_SIZE,
2672b789435STom Lendacky 		.alg_defaults	= &ccp_aes_defaults,
2682b789435STom Lendacky 	},
2692b789435STom Lendacky 	{
2702b789435STom Lendacky 		.mode		= CCP_AES_MODE_CTR,
271c7019c4dSGary R Hook 		.version	= CCP_VERSION(3, 0),
2722b789435STom Lendacky 		.name		= "ctr(aes)",
2732b789435STom Lendacky 		.driver_name	= "ctr-aes-ccp",
2742b789435STom Lendacky 		.blocksize	= 1,
2752b789435STom Lendacky 		.ivsize		= AES_BLOCK_SIZE,
2762b789435STom Lendacky 		.alg_defaults	= &ccp_aes_defaults,
2772b789435STom Lendacky 	},
2782b789435STom Lendacky 	{
2792b789435STom Lendacky 		.mode		= CCP_AES_MODE_CTR,
280c7019c4dSGary R Hook 		.version	= CCP_VERSION(3, 0),
2812b789435STom Lendacky 		.name		= "rfc3686(ctr(aes))",
2822b789435STom Lendacky 		.driver_name	= "rfc3686-ctr-aes-ccp",
2832b789435STom Lendacky 		.blocksize	= 1,
2842b789435STom Lendacky 		.ivsize		= CTR_RFC3686_IV_SIZE,
2852b789435STom Lendacky 		.alg_defaults	= &ccp_aes_rfc3686_defaults,
2862b789435STom Lendacky 	},
2872b789435STom Lendacky };
2882b789435STom Lendacky 
ccp_register_aes_alg(struct list_head * head,const struct ccp_aes_def * def)2892b789435STom Lendacky static int ccp_register_aes_alg(struct list_head *head,
2902b789435STom Lendacky 				const struct ccp_aes_def *def)
2912b789435STom Lendacky {
292be9fe620SArd Biesheuvel 	struct ccp_crypto_skcipher_alg *ccp_alg;
293be9fe620SArd Biesheuvel 	struct skcipher_alg *alg;
2942b789435STom Lendacky 	int ret;
2952b789435STom Lendacky 
2962b789435STom Lendacky 	ccp_alg = kzalloc(sizeof(*ccp_alg), GFP_KERNEL);
2972b789435STom Lendacky 	if (!ccp_alg)
2982b789435STom Lendacky 		return -ENOMEM;
2992b789435STom Lendacky 
3002b789435STom Lendacky 	INIT_LIST_HEAD(&ccp_alg->entry);
3012b789435STom Lendacky 
3022b789435STom Lendacky 	ccp_alg->mode = def->mode;
3032b789435STom Lendacky 
3042b789435STom Lendacky 	/* Copy the defaults and override as necessary */
3052b789435STom Lendacky 	alg = &ccp_alg->alg;
306d1dd206cSFengguang Wu 	*alg = *def->alg_defaults;
307be9fe620SArd Biesheuvel 	snprintf(alg->base.cra_name, CRYPTO_MAX_ALG_NAME, "%s", def->name);
308be9fe620SArd Biesheuvel 	snprintf(alg->base.cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s",
3092b789435STom Lendacky 		 def->driver_name);
310be9fe620SArd Biesheuvel 	alg->base.cra_blocksize = def->blocksize;
311be9fe620SArd Biesheuvel 	alg->ivsize = def->ivsize;
3122b789435STom Lendacky 
313be9fe620SArd Biesheuvel 	ret = crypto_register_skcipher(alg);
3142b789435STom Lendacky 	if (ret) {
315be9fe620SArd Biesheuvel 		pr_err("%s skcipher algorithm registration error (%d)\n",
316be9fe620SArd Biesheuvel 		       alg->base.cra_name, ret);
3172b789435STom Lendacky 		kfree(ccp_alg);
3182b789435STom Lendacky 		return ret;
3192b789435STom Lendacky 	}
3202b789435STom Lendacky 
3212b789435STom Lendacky 	list_add(&ccp_alg->entry, head);
3222b789435STom Lendacky 
3232b789435STom Lendacky 	return 0;
3242b789435STom Lendacky }
3252b789435STom Lendacky 
ccp_register_aes_algs(struct list_head * head)3262b789435STom Lendacky int ccp_register_aes_algs(struct list_head *head)
3272b789435STom Lendacky {
3282b789435STom Lendacky 	int i, ret;
329c7019c4dSGary R Hook 	unsigned int ccpversion = ccp_version();
3302b789435STom Lendacky 
3312b789435STom Lendacky 	for (i = 0; i < ARRAY_SIZE(aes_algs); i++) {
332c7019c4dSGary R Hook 		if (aes_algs[i].version > ccpversion)
333c7019c4dSGary R Hook 			continue;
3342b789435STom Lendacky 		ret = ccp_register_aes_alg(head, &aes_algs[i]);
3352b789435STom Lendacky 		if (ret)
3362b789435STom Lendacky 			return ret;
3372b789435STom Lendacky 	}
3382b789435STom Lendacky 
3392b789435STom Lendacky 	return 0;
3402b789435STom Lendacky }
341