Skip to content

Commit 84a2c93

Browse files
committed
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>
1 parent a2d382a commit 84a2c93

File tree

1 file changed

+25
-23
lines changed

1 file changed

+25
-23
lines changed

drivers/block/cryptoloop.c

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121

2222
#include <linux/module.h>
2323

24+
#include <crypto/skcipher.h>
2425
#include <linux/init.h>
2526
#include <linux/string.h>
26-
#include <linux/crypto.h>
2727
#include <linux/blkdev.h>
2828
#include <linux/scatterlist.h>
2929
#include <asm/uaccess.h>
@@ -46,7 +46,7 @@ cryptoloop_init(struct loop_device *lo, const struct loop_info64 *info)
4646
char *cipher;
4747
char *mode;
4848
char *cmsp = cms; /* c-m string pointer */
49-
struct crypto_blkcipher *tfm;
49+
struct crypto_skcipher *tfm;
5050

5151
/* encryption breaks for non sector aligned offsets */
5252

@@ -82,12 +82,12 @@ cryptoloop_init(struct loop_device *lo, const struct loop_info64 *info)
8282
*cmsp++ = ')';
8383
*cmsp = 0;
8484

85-
tfm = crypto_alloc_blkcipher(cms, 0, CRYPTO_ALG_ASYNC);
85+
tfm = crypto_alloc_skcipher(cms, 0, CRYPTO_ALG_ASYNC);
8686
if (IS_ERR(tfm))
8787
return PTR_ERR(tfm);
8888

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);
9191

9292
if (err != 0)
9393
goto out_free_tfm;
@@ -96,29 +96,23 @@ cryptoloop_init(struct loop_device *lo, const struct loop_info64 *info)
9696
return 0;
9797

9898
out_free_tfm:
99-
crypto_free_blkcipher(tfm);
99+
crypto_free_skcipher(tfm);
100100

101101
out:
102102
return err;
103103
}
104104

105105

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);
110107

111108
static int
112109
cryptoloop_transfer(struct loop_device *lo, int cmd,
113110
struct page *raw_page, unsigned raw_off,
114111
struct page *loop_page, unsigned loop_off,
115112
int size, sector_t IV)
116113
{
117-
struct crypto_blkcipher *tfm = lo->key_data;
118-
struct blkcipher_desc desc = {
119-
.tfm = tfm,
120-
.flags = CRYPTO_TFM_REQ_MAY_SLEEP,
121-
};
114+
struct crypto_skcipher *tfm = lo->key_data;
115+
SKCIPHER_REQUEST_ON_STACK(req, tfm);
122116
struct scatterlist sg_out;
123117
struct scatterlist sg_in;
124118

@@ -127,6 +121,10 @@ cryptoloop_transfer(struct loop_device *lo, int cmd,
127121
unsigned in_offs, out_offs;
128122
int err;
129123

124+
skcipher_request_set_tfm(req, tfm);
125+
skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_SLEEP,
126+
NULL, NULL);
127+
130128
sg_init_table(&sg_out, 1);
131129
sg_init_table(&sg_in, 1);
132130

@@ -135,13 +133,13 @@ cryptoloop_transfer(struct loop_device *lo, int cmd,
135133
in_offs = raw_off;
136134
out_page = loop_page;
137135
out_offs = loop_off;
138-
encdecfunc = crypto_blkcipher_crt(tfm)->decrypt;
136+
encdecfunc = crypto_skcipher_decrypt;
139137
} else {
140138
in_page = loop_page;
141139
in_offs = loop_off;
142140
out_page = raw_page;
143141
out_offs = raw_off;
144-
encdecfunc = crypto_blkcipher_crt(tfm)->encrypt;
142+
encdecfunc = crypto_skcipher_encrypt;
145143
}
146144

147145
while (size > 0) {
@@ -152,18 +150,22 @@ cryptoloop_transfer(struct loop_device *lo, int cmd,
152150
sg_set_page(&sg_in, in_page, sz, in_offs);
153151
sg_set_page(&sg_out, out_page, sz, out_offs);
154152

155-
desc.info = iv;
156-
err = encdecfunc(&desc, &sg_out, &sg_in, sz);
153+
skcipher_request_set_crypt(req, &sg_in, &sg_out, sz, iv);
154+
err = encdecfunc(req);
157155
if (err)
158-
return err;
156+
goto out;
159157

160158
IV++;
161159
size -= sz;
162160
in_offs += sz;
163161
out_offs += sz;
164162
}
165163

166-
return 0;
164+
err = 0;
165+
166+
out:
167+
skcipher_request_zero(req);
168+
return err;
167169
}
168170

169171
static int
@@ -175,9 +177,9 @@ cryptoloop_ioctl(struct loop_device *lo, int cmd, unsigned long arg)
175177
static int
176178
cryptoloop_release(struct loop_device *lo)
177179
{
178-
struct crypto_blkcipher *tfm = lo->key_data;
180+
struct crypto_skcipher *tfm = lo->key_data;
179181
if (tfm != NULL) {
180-
crypto_free_blkcipher(tfm);
182+
crypto_free_skcipher(tfm);
181183
lo->key_data = NULL;
182184
return 0;
183185
}

0 commit comments

Comments
 (0)