Commit 241118de authored by Herbert Xu's avatar Herbert Xu

crypto: ccp - Use skcipher for fallback

This patch replaces use of the obsolete ablkcipher with skcipher.
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 02fa472a
...@@ -14,9 +14,8 @@ ...@@ -14,9 +14,8 @@
#include <linux/sched.h> #include <linux/sched.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/scatterlist.h> #include <linux/scatterlist.h>
#include <linux/crypto.h>
#include <crypto/algapi.h>
#include <crypto/aes.h> #include <crypto/aes.h>
#include <crypto/internal/skcipher.h>
#include <crypto/scatterwalk.h> #include <crypto/scatterwalk.h>
#include "ccp-crypto.h" #include "ccp-crypto.h"
...@@ -110,15 +109,12 @@ static int ccp_aes_xts_setkey(struct crypto_ablkcipher *tfm, const u8 *key, ...@@ -110,15 +109,12 @@ static int ccp_aes_xts_setkey(struct crypto_ablkcipher *tfm, const u8 *key,
ctx->u.aes.key_len = key_len / 2; ctx->u.aes.key_len = key_len / 2;
sg_init_one(&ctx->u.aes.key_sg, ctx->u.aes.key, key_len); sg_init_one(&ctx->u.aes.key_sg, ctx->u.aes.key, key_len);
return crypto_ablkcipher_setkey(ctx->u.aes.tfm_ablkcipher, key, return crypto_skcipher_setkey(ctx->u.aes.tfm_skcipher, key, key_len);
key_len);
} }
static int ccp_aes_xts_crypt(struct ablkcipher_request *req, static int ccp_aes_xts_crypt(struct ablkcipher_request *req,
unsigned int encrypt) unsigned int encrypt)
{ {
struct crypto_tfm *tfm =
crypto_ablkcipher_tfm(crypto_ablkcipher_reqtfm(req));
struct ccp_ctx *ctx = crypto_tfm_ctx(req->base.tfm); struct ccp_ctx *ctx = crypto_tfm_ctx(req->base.tfm);
struct ccp_aes_req_ctx *rctx = ablkcipher_request_ctx(req); struct ccp_aes_req_ctx *rctx = ablkcipher_request_ctx(req);
unsigned int unit; unsigned int unit;
...@@ -146,14 +142,19 @@ static int ccp_aes_xts_crypt(struct ablkcipher_request *req, ...@@ -146,14 +142,19 @@ static int ccp_aes_xts_crypt(struct ablkcipher_request *req,
if ((unit_size == CCP_XTS_AES_UNIT_SIZE__LAST) || if ((unit_size == CCP_XTS_AES_UNIT_SIZE__LAST) ||
(ctx->u.aes.key_len != AES_KEYSIZE_128)) { (ctx->u.aes.key_len != AES_KEYSIZE_128)) {
SKCIPHER_REQUEST_ON_STACK(subreq, ctx->u.aes.tfm_skcipher);
/* Use the fallback to process the request for any /* Use the fallback to process the request for any
* unsupported unit sizes or key sizes * unsupported unit sizes or key sizes
*/ */
ablkcipher_request_set_tfm(req, ctx->u.aes.tfm_ablkcipher); skcipher_request_set_tfm(subreq, ctx->u.aes.tfm_skcipher);
ret = (encrypt) ? crypto_ablkcipher_encrypt(req) : skcipher_request_set_callback(subreq, req->base.flags,
crypto_ablkcipher_decrypt(req); NULL, NULL);
ablkcipher_request_set_tfm(req, __crypto_ablkcipher_cast(tfm)); skcipher_request_set_crypt(subreq, req->src, req->dst,
req->nbytes, req->info);
ret = encrypt ? crypto_skcipher_encrypt(subreq) :
crypto_skcipher_decrypt(subreq);
skcipher_request_zero(subreq);
return ret; return ret;
} }
...@@ -192,23 +193,21 @@ static int ccp_aes_xts_decrypt(struct ablkcipher_request *req) ...@@ -192,23 +193,21 @@ static int ccp_aes_xts_decrypt(struct ablkcipher_request *req)
static int ccp_aes_xts_cra_init(struct crypto_tfm *tfm) static int ccp_aes_xts_cra_init(struct crypto_tfm *tfm)
{ {
struct ccp_ctx *ctx = crypto_tfm_ctx(tfm); struct ccp_ctx *ctx = crypto_tfm_ctx(tfm);
struct crypto_ablkcipher *fallback_tfm; struct crypto_skcipher *fallback_tfm;
ctx->complete = ccp_aes_xts_complete; ctx->complete = ccp_aes_xts_complete;
ctx->u.aes.key_len = 0; ctx->u.aes.key_len = 0;
fallback_tfm = crypto_alloc_ablkcipher(crypto_tfm_alg_name(tfm), 0, fallback_tfm = crypto_alloc_skcipher("xts(aes)", 0,
CRYPTO_ALG_ASYNC | CRYPTO_ALG_ASYNC |
CRYPTO_ALG_NEED_FALLBACK); CRYPTO_ALG_NEED_FALLBACK);
if (IS_ERR(fallback_tfm)) { if (IS_ERR(fallback_tfm)) {
pr_warn("could not load fallback driver %s\n", pr_warn("could not load fallback driver xts(aes)\n");
crypto_tfm_alg_name(tfm));
return PTR_ERR(fallback_tfm); return PTR_ERR(fallback_tfm);
} }
ctx->u.aes.tfm_ablkcipher = fallback_tfm; ctx->u.aes.tfm_skcipher = fallback_tfm;
tfm->crt_ablkcipher.reqsize = sizeof(struct ccp_aes_req_ctx) + tfm->crt_ablkcipher.reqsize = sizeof(struct ccp_aes_req_ctx);
fallback_tfm->base.crt_ablkcipher.reqsize;
return 0; return 0;
} }
...@@ -217,9 +216,7 @@ static void ccp_aes_xts_cra_exit(struct crypto_tfm *tfm) ...@@ -217,9 +216,7 @@ static void ccp_aes_xts_cra_exit(struct crypto_tfm *tfm)
{ {
struct ccp_ctx *ctx = crypto_tfm_ctx(tfm); struct ccp_ctx *ctx = crypto_tfm_ctx(tfm);
if (ctx->u.aes.tfm_ablkcipher) crypto_free_skcipher(ctx->u.aes.tfm_skcipher);
crypto_free_ablkcipher(ctx->u.aes.tfm_ablkcipher);
ctx->u.aes.tfm_ablkcipher = NULL;
} }
static int ccp_register_aes_xts_alg(struct list_head *head, static int ccp_register_aes_xts_alg(struct list_head *head,
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
#include <linux/wait.h> #include <linux/wait.h>
#include <linux/pci.h> #include <linux/pci.h>
#include <linux/ccp.h> #include <linux/ccp.h>
#include <linux/crypto.h>
#include <crypto/algapi.h> #include <crypto/algapi.h>
#include <crypto/aes.h> #include <crypto/aes.h>
#include <crypto/ctr.h> #include <crypto/ctr.h>
...@@ -69,7 +68,7 @@ static inline struct ccp_crypto_ahash_alg * ...@@ -69,7 +68,7 @@ static inline struct ccp_crypto_ahash_alg *
/***** AES related defines *****/ /***** AES related defines *****/
struct ccp_aes_ctx { struct ccp_aes_ctx {
/* Fallback cipher for XTS with unsupported unit sizes */ /* Fallback cipher for XTS with unsupported unit sizes */
struct crypto_ablkcipher *tfm_ablkcipher; struct crypto_skcipher *tfm_skcipher;
/* Cipher used to generate CMAC K1/K2 keys */ /* Cipher used to generate CMAC K1/K2 keys */
struct crypto_cipher *tfm_cipher; struct crypto_cipher *tfm_cipher;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment