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

block: cryptoloop - Use new skcipher interface

This patch replaces uses of blkcipher with the new skcipher
interface.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

+25 -23
+25 -23
drivers/block/cryptoloop.c
··· 21 21 22 22 #include <linux/module.h> 23 23 24 + #include <crypto/skcipher.h> 24 25 #include <linux/init.h> 25 26 #include <linux/string.h> 26 - #include <linux/crypto.h> 27 27 #include <linux/blkdev.h> 28 28 #include <linux/scatterlist.h> 29 29 #include <asm/uaccess.h> ··· 46 46 char *cipher; 47 47 char *mode; 48 48 char *cmsp = cms; /* c-m string pointer */ 49 - struct crypto_blkcipher *tfm; 49 + struct crypto_skcipher *tfm; 50 50 51 51 /* encryption breaks for non sector aligned offsets */ 52 52 ··· 82 82 *cmsp++ = ')'; 83 83 *cmsp = 0; 84 84 85 - tfm = crypto_alloc_blkcipher(cms, 0, CRYPTO_ALG_ASYNC); 85 + tfm = crypto_alloc_skcipher(cms, 0, CRYPTO_ALG_ASYNC); 86 86 if (IS_ERR(tfm)) 87 87 return PTR_ERR(tfm); 88 88 89 - err = crypto_blkcipher_setkey(tfm, info->lo_encrypt_key, 90 - info->lo_encrypt_key_size); 89 + err = crypto_skcipher_setkey(tfm, info->lo_encrypt_key, 90 + info->lo_encrypt_key_size); 91 91 92 92 if (err != 0) 93 93 goto out_free_tfm; ··· 96 96 return 0; 97 97 98 98 out_free_tfm: 99 - crypto_free_blkcipher(tfm); 99 + crypto_free_skcipher(tfm); 100 100 101 101 out: 102 102 return err; 103 103 } 104 104 105 105 106 - typedef int (*encdec_cbc_t)(struct blkcipher_desc *desc, 107 - struct scatterlist *sg_out, 108 - struct scatterlist *sg_in, 109 - unsigned int nsg); 106 + typedef int (*encdec_cbc_t)(struct skcipher_request *req); 110 107 111 108 static int 112 109 cryptoloop_transfer(struct loop_device *lo, int cmd, ··· 111 114 struct page *loop_page, unsigned loop_off, 112 115 int size, sector_t IV) 113 116 { 114 - struct crypto_blkcipher *tfm = lo->key_data; 115 - struct blkcipher_desc desc = { 116 - .tfm = tfm, 117 - .flags = CRYPTO_TFM_REQ_MAY_SLEEP, 118 - }; 117 + struct crypto_skcipher *tfm = lo->key_data; 118 + SKCIPHER_REQUEST_ON_STACK(req, tfm); 119 119 struct scatterlist sg_out; 120 120 struct scatterlist sg_in; 121 121 ··· 120 126 struct page *in_page, *out_page; 121 127 unsigned in_offs, out_offs; 122 128 int err; 129 + 130 + skcipher_request_set_tfm(req, tfm); 131 + skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_SLEEP, 132 + NULL, NULL); 123 133 124 134 sg_init_table(&sg_out, 1); 125 135 sg_init_table(&sg_in, 1); ··· 133 135 in_offs = raw_off; 134 136 out_page = loop_page; 135 137 out_offs = loop_off; 136 - encdecfunc = crypto_blkcipher_crt(tfm)->decrypt; 138 + encdecfunc = crypto_skcipher_decrypt; 137 139 } else { 138 140 in_page = loop_page; 139 141 in_offs = loop_off; 140 142 out_page = raw_page; 141 143 out_offs = raw_off; 142 - encdecfunc = crypto_blkcipher_crt(tfm)->encrypt; 144 + encdecfunc = crypto_skcipher_encrypt; 143 145 } 144 146 145 147 while (size > 0) { ··· 150 152 sg_set_page(&sg_in, in_page, sz, in_offs); 151 153 sg_set_page(&sg_out, out_page, sz, out_offs); 152 154 153 - desc.info = iv; 154 - err = encdecfunc(&desc, &sg_out, &sg_in, sz); 155 + skcipher_request_set_crypt(req, &sg_in, &sg_out, sz, iv); 156 + err = encdecfunc(req); 155 157 if (err) 156 - return err; 158 + goto out; 157 159 158 160 IV++; 159 161 size -= sz; ··· 161 163 out_offs += sz; 162 164 } 163 165 164 - return 0; 166 + err = 0; 167 + 168 + out: 169 + skcipher_request_zero(req); 170 + return err; 165 171 } 166 172 167 173 static int ··· 177 175 static int 178 176 cryptoloop_release(struct loop_device *lo) 179 177 { 180 - struct crypto_blkcipher *tfm = lo->key_data; 178 + struct crypto_skcipher *tfm = lo->key_data; 181 179 if (tfm != NULL) { 182 - crypto_free_blkcipher(tfm); 180 + crypto_free_skcipher(tfm); 183 181 lo->key_data = NULL; 184 182 return 0; 185 183 }