Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

crypto: nx - convert AES-CBC to skcipher API

Convert the PowerPC Nest (NX) implementation of AES-CBC 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>

authored by

Eric Biggers and committed by
Herbert Xu
c1e9c386 bfd9efdd

+41 -52
+33 -45
drivers/crypto/nx/nx-aes-cbc.c
··· 18 18 #include "nx.h" 19 19 20 20 21 - static int cbc_aes_nx_set_key(struct crypto_tfm *tfm, 22 - const u8 *in_key, 23 - unsigned int key_len) 21 + static int cbc_aes_nx_set_key(struct crypto_skcipher *tfm, 22 + const u8 *in_key, 23 + unsigned int key_len) 24 24 { 25 - struct nx_crypto_ctx *nx_ctx = crypto_tfm_ctx(tfm); 25 + struct nx_crypto_ctx *nx_ctx = crypto_skcipher_ctx(tfm); 26 26 struct nx_csbcpb *csbcpb = nx_ctx->csbcpb; 27 27 28 28 nx_ctx_init(nx_ctx, HCOP_FC_AES); ··· 50 50 return 0; 51 51 } 52 52 53 - static int cbc_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 cbc_aes_nx_crypt(struct skcipher_request *req, 54 + int enc) 58 55 { 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); 60 58 struct nx_csbcpb *csbcpb = nx_ctx->csbcpb; 61 59 unsigned long irq_flags; 62 60 unsigned int processed = 0, to_process; ··· 68 70 NX_CPB_FDM(csbcpb) &= ~NX_FDM_ENDE_ENCRYPT; 69 71 70 72 do { 71 - to_process = nbytes - processed; 73 + to_process = req->cryptlen - processed; 72 74 73 - rc = nx_build_sg_lists(nx_ctx, desc->info, dst, src, 75 + rc = nx_build_sg_lists(nx_ctx, req->iv, req->dst, req->src, 74 76 &to_process, processed, 75 77 csbcpb->cpb.aes_cbc.iv); 76 78 if (rc) ··· 82 84 } 83 85 84 86 rc = nx_hcall_sync(nx_ctx, &nx_ctx->op, 85 - desc->flags & CRYPTO_TFM_REQ_MAY_SLEEP); 87 + req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP); 86 88 if (rc) 87 89 goto out; 88 90 89 - memcpy(desc->info, csbcpb->cpb.aes_cbc.cv, AES_BLOCK_SIZE); 91 + memcpy(req->iv, csbcpb->cpb.aes_cbc.cv, AES_BLOCK_SIZE); 90 92 atomic_inc(&(nx_ctx->stats->aes_ops)); 91 93 atomic64_add(csbcpb->csb.processed_byte_count, 92 94 &(nx_ctx->stats->aes_bytes)); 93 95 94 96 processed += to_process; 95 - } while (processed < nbytes); 97 + } while (processed < req->cryptlen); 96 98 out: 97 99 spin_unlock_irqrestore(&nx_ctx->lock, irq_flags); 98 100 return rc; 99 101 } 100 102 101 - static int cbc_aes_nx_encrypt(struct blkcipher_desc *desc, 102 - struct scatterlist *dst, 103 - struct scatterlist *src, 104 - unsigned int nbytes) 103 + static int cbc_aes_nx_encrypt(struct skcipher_request *req) 105 104 { 106 - return cbc_aes_nx_crypt(desc, dst, src, nbytes, 1); 105 + return cbc_aes_nx_crypt(req, 1); 107 106 } 108 107 109 - static int cbc_aes_nx_decrypt(struct blkcipher_desc *desc, 110 - struct scatterlist *dst, 111 - struct scatterlist *src, 112 - unsigned int nbytes) 108 + static int cbc_aes_nx_decrypt(struct skcipher_request *req) 113 109 { 114 - return cbc_aes_nx_crypt(desc, dst, src, nbytes, 0); 110 + return cbc_aes_nx_crypt(req, 0); 115 111 } 116 112 117 - struct crypto_alg nx_cbc_aes_alg = { 118 - .cra_name = "cbc(aes)", 119 - .cra_driver_name = "cbc-aes-nx", 120 - .cra_priority = 300, 121 - .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, 122 - .cra_blocksize = AES_BLOCK_SIZE, 123 - .cra_ctxsize = sizeof(struct nx_crypto_ctx), 124 - .cra_type = &crypto_blkcipher_type, 125 - .cra_alignmask = 0xf, 126 - .cra_module = THIS_MODULE, 127 - .cra_init = nx_crypto_ctx_aes_cbc_init, 128 - .cra_exit = nx_crypto_ctx_exit, 129 - .cra_blkcipher = { 130 - .min_keysize = AES_MIN_KEY_SIZE, 131 - .max_keysize = AES_MAX_KEY_SIZE, 132 - .ivsize = AES_BLOCK_SIZE, 133 - .setkey = cbc_aes_nx_set_key, 134 - .encrypt = cbc_aes_nx_encrypt, 135 - .decrypt = cbc_aes_nx_decrypt, 136 - } 113 + struct skcipher_alg nx_cbc_aes_alg = { 114 + .base.cra_name = "cbc(aes)", 115 + .base.cra_driver_name = "cbc-aes-nx", 116 + .base.cra_priority = 300, 117 + .base.cra_blocksize = AES_BLOCK_SIZE, 118 + .base.cra_ctxsize = sizeof(struct nx_crypto_ctx), 119 + .base.cra_alignmask = 0xf, 120 + .base.cra_module = THIS_MODULE, 121 + .init = nx_crypto_ctx_aes_cbc_init, 122 + .exit = nx_crypto_ctx_skcipher_exit, 123 + .min_keysize = AES_MIN_KEY_SIZE, 124 + .max_keysize = AES_MAX_KEY_SIZE, 125 + .ivsize = AES_BLOCK_SIZE, 126 + .setkey = cbc_aes_nx_set_key, 127 + .encrypt = cbc_aes_nx_encrypt, 128 + .decrypt = cbc_aes_nx_decrypt, 137 129 };
+6 -5
drivers/crypto/nx/nx.c
··· 589 589 if (rc) 590 590 goto out; 591 591 592 - rc = nx_register_alg(&nx_cbc_aes_alg, NX_FC_AES, NX_MODE_AES_CBC); 592 + rc = nx_register_skcipher(&nx_cbc_aes_alg, NX_FC_AES, NX_MODE_AES_CBC); 593 593 if (rc) 594 594 goto out_unreg_ecb; 595 595 ··· 647 647 out_unreg_ctr3686: 648 648 nx_unregister_alg(&nx_ctr3686_aes_alg, NX_FC_AES, NX_MODE_AES_CTR); 649 649 out_unreg_cbc: 650 - nx_unregister_alg(&nx_cbc_aes_alg, NX_FC_AES, NX_MODE_AES_CBC); 650 + nx_unregister_skcipher(&nx_cbc_aes_alg, NX_FC_AES, NX_MODE_AES_CBC); 651 651 out_unreg_ecb: 652 652 nx_unregister_skcipher(&nx_ecb_aes_alg, NX_FC_AES, NX_MODE_AES_ECB); 653 653 out: ··· 722 722 NX_MODE_AES_CTR); 723 723 } 724 724 725 - int nx_crypto_ctx_aes_cbc_init(struct crypto_tfm *tfm) 725 + int nx_crypto_ctx_aes_cbc_init(struct crypto_skcipher *tfm) 726 726 { 727 - return nx_crypto_ctx_init(crypto_tfm_ctx(tfm), NX_FC_AES, 727 + return nx_crypto_ctx_init(crypto_skcipher_ctx(tfm), NX_FC_AES, 728 728 NX_MODE_AES_CBC); 729 729 } 730 730 ··· 817 817 NX_FC_AES, NX_MODE_AES_GCM); 818 818 nx_unregister_alg(&nx_ctr3686_aes_alg, 819 819 NX_FC_AES, NX_MODE_AES_CTR); 820 - nx_unregister_alg(&nx_cbc_aes_alg, NX_FC_AES, NX_MODE_AES_CBC); 820 + nx_unregister_skcipher(&nx_cbc_aes_alg, NX_FC_AES, 821 + NX_MODE_AES_CBC); 821 822 nx_unregister_skcipher(&nx_ecb_aes_alg, NX_FC_AES, 822 823 NX_MODE_AES_ECB); 823 824 }
+2 -2
drivers/crypto/nx/nx.h
··· 146 146 int nx_crypto_ctx_aes_gcm_init(struct crypto_aead *tfm); 147 147 int nx_crypto_ctx_aes_xcbc_init(struct crypto_tfm *tfm); 148 148 int nx_crypto_ctx_aes_ctr_init(struct crypto_tfm *tfm); 149 - int nx_crypto_ctx_aes_cbc_init(struct crypto_tfm *tfm); 149 + int nx_crypto_ctx_aes_cbc_init(struct crypto_skcipher *tfm); 150 150 int nx_crypto_ctx_aes_ecb_init(struct crypto_skcipher *tfm); 151 151 int nx_crypto_ctx_sha_init(struct crypto_tfm *tfm); 152 152 void nx_crypto_ctx_exit(struct crypto_tfm *tfm); ··· 176 176 177 177 #define NX_PAGE_NUM(x) ((u64)(x) & 0xfffffffffffff000ULL) 178 178 179 - extern struct crypto_alg nx_cbc_aes_alg; 179 + extern struct skcipher_alg nx_cbc_aes_alg; 180 180 extern struct skcipher_alg nx_ecb_aes_alg; 181 181 extern struct aead_alg nx_gcm_aes_alg; 182 182 extern struct aead_alg nx_gcm4106_aes_alg;