Skip to content

Commit bfd9efd

Browse files
ebiggersherbertx
authored andcommitted
crypto: nx - convert AES-ECB to skcipher API
Convert the PowerPC Nest (NX) implementation of AES-ECB from the deprecated "blkcipher" API to the "skcipher" API. This is needed in order for the blkcipher API to be removed. Signed-off-by: Eric Biggers <ebiggers@google.com> Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 7740bd5 commit bfd9efd

3 files changed

Lines changed: 58 additions & 51 deletions

File tree

drivers/crypto/nx/nx-aes-ecb.c

Lines changed: 32 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
#include "nx.h"
1919

2020

21-
static int ecb_aes_nx_set_key(struct crypto_tfm *tfm,
22-
const u8 *in_key,
23-
unsigned int key_len)
21+
static int ecb_aes_nx_set_key(struct crypto_skcipher *tfm,
22+
const u8 *in_key,
23+
unsigned int key_len)
2424
{
25-
struct nx_crypto_ctx *nx_ctx = crypto_tfm_ctx(tfm);
25+
struct nx_crypto_ctx *nx_ctx = crypto_skcipher_ctx(tfm);
2626
struct nx_csbcpb *csbcpb = (struct nx_csbcpb *)nx_ctx->csbcpb;
2727

2828
nx_ctx_init(nx_ctx, HCOP_FC_AES);
@@ -50,13 +50,11 @@ static int ecb_aes_nx_set_key(struct crypto_tfm *tfm,
5050
return 0;
5151
}
5252

53-
static int ecb_aes_nx_crypt(struct blkcipher_desc *desc,
54-
struct scatterlist *dst,
55-
struct scatterlist *src,
56-
unsigned int nbytes,
57-
int enc)
53+
static int ecb_aes_nx_crypt(struct skcipher_request *req,
54+
int enc)
5855
{
59-
struct nx_crypto_ctx *nx_ctx = crypto_blkcipher_ctx(desc->tfm);
56+
struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
57+
struct nx_crypto_ctx *nx_ctx = crypto_skcipher_ctx(tfm);
6058
struct nx_csbcpb *csbcpb = nx_ctx->csbcpb;
6159
unsigned long irq_flags;
6260
unsigned int processed = 0, to_process;
@@ -70,10 +68,10 @@ static int ecb_aes_nx_crypt(struct blkcipher_desc *desc,
7068
NX_CPB_FDM(csbcpb) &= ~NX_FDM_ENDE_ENCRYPT;
7169

7270
do {
73-
to_process = nbytes - processed;
71+
to_process = req->cryptlen - processed;
7472

75-
rc = nx_build_sg_lists(nx_ctx, NULL, dst, src, &to_process,
76-
processed, NULL);
73+
rc = nx_build_sg_lists(nx_ctx, NULL, req->dst, req->src,
74+
&to_process, processed, NULL);
7775
if (rc)
7876
goto out;
7977

@@ -83,7 +81,7 @@ static int ecb_aes_nx_crypt(struct blkcipher_desc *desc,
8381
}
8482

8583
rc = nx_hcall_sync(nx_ctx, &nx_ctx->op,
86-
desc->flags & CRYPTO_TFM_REQ_MAY_SLEEP);
84+
req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP);
8785
if (rc)
8886
goto out;
8987

@@ -92,46 +90,36 @@ static int ecb_aes_nx_crypt(struct blkcipher_desc *desc,
9290
&(nx_ctx->stats->aes_bytes));
9391

9492
processed += to_process;
95-
} while (processed < nbytes);
93+
} while (processed < req->cryptlen);
9694

9795
out:
9896
spin_unlock_irqrestore(&nx_ctx->lock, irq_flags);
9997
return rc;
10098
}
10199

102-
static int ecb_aes_nx_encrypt(struct blkcipher_desc *desc,
103-
struct scatterlist *dst,
104-
struct scatterlist *src,
105-
unsigned int nbytes)
100+
static int ecb_aes_nx_encrypt(struct skcipher_request *req)
106101
{
107-
return ecb_aes_nx_crypt(desc, dst, src, nbytes, 1);
102+
return ecb_aes_nx_crypt(req, 1);
108103
}
109104

110-
static int ecb_aes_nx_decrypt(struct blkcipher_desc *desc,
111-
struct scatterlist *dst,
112-
struct scatterlist *src,
113-
unsigned int nbytes)
105+
static int ecb_aes_nx_decrypt(struct skcipher_request *req)
114106
{
115-
return ecb_aes_nx_crypt(desc, dst, src, nbytes, 0);
107+
return ecb_aes_nx_crypt(req, 0);
116108
}
117109

118-
struct crypto_alg nx_ecb_aes_alg = {
119-
.cra_name = "ecb(aes)",
120-
.cra_driver_name = "ecb-aes-nx",
121-
.cra_priority = 300,
122-
.cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER,
123-
.cra_blocksize = AES_BLOCK_SIZE,
124-
.cra_alignmask = 0xf,
125-
.cra_ctxsize = sizeof(struct nx_crypto_ctx),
126-
.cra_type = &crypto_blkcipher_type,
127-
.cra_module = THIS_MODULE,
128-
.cra_init = nx_crypto_ctx_aes_ecb_init,
129-
.cra_exit = nx_crypto_ctx_exit,
130-
.cra_blkcipher = {
131-
.min_keysize = AES_MIN_KEY_SIZE,
132-
.max_keysize = AES_MAX_KEY_SIZE,
133-
.setkey = ecb_aes_nx_set_key,
134-
.encrypt = ecb_aes_nx_encrypt,
135-
.decrypt = ecb_aes_nx_decrypt,
136-
}
110+
struct skcipher_alg nx_ecb_aes_alg = {
111+
.base.cra_name = "ecb(aes)",
112+
.base.cra_driver_name = "ecb-aes-nx",
113+
.base.cra_priority = 300,
114+
.base.cra_blocksize = AES_BLOCK_SIZE,
115+
.base.cra_alignmask = 0xf,
116+
.base.cra_ctxsize = sizeof(struct nx_crypto_ctx),
117+
.base.cra_module = THIS_MODULE,
118+
.init = nx_crypto_ctx_aes_ecb_init,
119+
.exit = nx_crypto_ctx_skcipher_exit,
120+
.min_keysize = AES_MIN_KEY_SIZE,
121+
.max_keysize = AES_MAX_KEY_SIZE,
122+
.setkey = ecb_aes_nx_set_key,
123+
.encrypt = ecb_aes_nx_encrypt,
124+
.decrypt = ecb_aes_nx_decrypt,
137125
};

drivers/crypto/nx/nx.c

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,12 @@ static int nx_register_alg(struct crypto_alg *alg, u32 fc, u32 mode)
517517
crypto_register_alg(alg) : 0;
518518
}
519519

520+
static int nx_register_skcipher(struct skcipher_alg *alg, u32 fc, u32 mode)
521+
{
522+
return nx_check_props(&nx_driver.viodev->dev, fc, mode) ?
523+
crypto_register_skcipher(alg) : 0;
524+
}
525+
520526
static int nx_register_aead(struct aead_alg *alg, u32 fc, u32 mode)
521527
{
522528
return nx_check_props(&nx_driver.viodev->dev, fc, mode) ?
@@ -537,6 +543,12 @@ static void nx_unregister_alg(struct crypto_alg *alg, u32 fc, u32 mode)
537543
crypto_unregister_alg(alg);
538544
}
539545

546+
static void nx_unregister_skcipher(struct skcipher_alg *alg, u32 fc, u32 mode)
547+
{
548+
if (nx_check_props(NULL, fc, mode))
549+
crypto_unregister_skcipher(alg);
550+
}
551+
540552
static void nx_unregister_aead(struct aead_alg *alg, u32 fc, u32 mode)
541553
{
542554
if (nx_check_props(NULL, fc, mode))
@@ -573,7 +585,7 @@ static int nx_register_algs(void)
573585

574586
nx_driver.of.status = NX_OKAY;
575587

576-
rc = nx_register_alg(&nx_ecb_aes_alg, NX_FC_AES, NX_MODE_AES_ECB);
588+
rc = nx_register_skcipher(&nx_ecb_aes_alg, NX_FC_AES, NX_MODE_AES_ECB);
577589
if (rc)
578590
goto out;
579591

@@ -637,7 +649,7 @@ static int nx_register_algs(void)
637649
out_unreg_cbc:
638650
nx_unregister_alg(&nx_cbc_aes_alg, NX_FC_AES, NX_MODE_AES_CBC);
639651
out_unreg_ecb:
640-
nx_unregister_alg(&nx_ecb_aes_alg, NX_FC_AES, NX_MODE_AES_ECB);
652+
nx_unregister_skcipher(&nx_ecb_aes_alg, NX_FC_AES, NX_MODE_AES_ECB);
641653
out:
642654
return rc;
643655
}
@@ -716,9 +728,9 @@ int nx_crypto_ctx_aes_cbc_init(struct crypto_tfm *tfm)
716728
NX_MODE_AES_CBC);
717729
}
718730

719-
int nx_crypto_ctx_aes_ecb_init(struct crypto_tfm *tfm)
731+
int nx_crypto_ctx_aes_ecb_init(struct crypto_skcipher *tfm)
720732
{
721-
return nx_crypto_ctx_init(crypto_tfm_ctx(tfm), NX_FC_AES,
733+
return nx_crypto_ctx_init(crypto_skcipher_ctx(tfm), NX_FC_AES,
722734
NX_MODE_AES_ECB);
723735
}
724736

@@ -752,6 +764,11 @@ void nx_crypto_ctx_exit(struct crypto_tfm *tfm)
752764
nx_ctx->out_sg = NULL;
753765
}
754766

767+
void nx_crypto_ctx_skcipher_exit(struct crypto_skcipher *tfm)
768+
{
769+
nx_crypto_ctx_exit(crypto_skcipher_ctx(tfm));
770+
}
771+
755772
void nx_crypto_ctx_aead_exit(struct crypto_aead *tfm)
756773
{
757774
struct nx_crypto_ctx *nx_ctx = crypto_aead_ctx(tfm);
@@ -801,7 +818,8 @@ static int nx_remove(struct vio_dev *viodev)
801818
nx_unregister_alg(&nx_ctr3686_aes_alg,
802819
NX_FC_AES, NX_MODE_AES_CTR);
803820
nx_unregister_alg(&nx_cbc_aes_alg, NX_FC_AES, NX_MODE_AES_CBC);
804-
nx_unregister_alg(&nx_ecb_aes_alg, NX_FC_AES, NX_MODE_AES_ECB);
821+
nx_unregister_skcipher(&nx_ecb_aes_alg, NX_FC_AES,
822+
NX_MODE_AES_ECB);
805823
}
806824

807825
return 0;

drivers/crypto/nx/nx.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,10 @@ int nx_crypto_ctx_aes_gcm_init(struct crypto_aead *tfm);
147147
int nx_crypto_ctx_aes_xcbc_init(struct crypto_tfm *tfm);
148148
int nx_crypto_ctx_aes_ctr_init(struct crypto_tfm *tfm);
149149
int nx_crypto_ctx_aes_cbc_init(struct crypto_tfm *tfm);
150-
int nx_crypto_ctx_aes_ecb_init(struct crypto_tfm *tfm);
150+
int nx_crypto_ctx_aes_ecb_init(struct crypto_skcipher *tfm);
151151
int nx_crypto_ctx_sha_init(struct crypto_tfm *tfm);
152152
void nx_crypto_ctx_exit(struct crypto_tfm *tfm);
153+
void nx_crypto_ctx_skcipher_exit(struct crypto_skcipher *tfm);
153154
void nx_crypto_ctx_aead_exit(struct crypto_aead *tfm);
154155
void nx_ctx_init(struct nx_crypto_ctx *nx_ctx, unsigned int function);
155156
int nx_hcall_sync(struct nx_crypto_ctx *ctx, struct vio_pfo_op *op,
@@ -176,7 +177,7 @@ void nx_debugfs_fini(struct nx_crypto_driver *);
176177
#define NX_PAGE_NUM(x) ((u64)(x) & 0xfffffffffffff000ULL)
177178

178179
extern struct crypto_alg nx_cbc_aes_alg;
179-
extern struct crypto_alg nx_ecb_aes_alg;
180+
extern struct skcipher_alg nx_ecb_aes_alg;
180181
extern struct aead_alg nx_gcm_aes_alg;
181182
extern struct aead_alg nx_gcm4106_aes_alg;
182183
extern struct crypto_alg nx_ctr3686_aes_alg;

0 commit comments

Comments
 (0)