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,7 +46,7 @@ cryptoloop_init(struct loop_device *lo, const struct loop_info64 *info)
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,12 +82,12 @@ cryptoloop_init(struct loop_device *lo, const struct loop_info64 *info)
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,29 +96,23 @@ cryptoloop_init(struct loop_device *lo, const struct loop_info64 *info)
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 ,
113
110
struct page * raw_page , unsigned raw_off ,
114
111
struct page * loop_page , unsigned loop_off ,
115
112
int size , sector_t IV )
116
113
{
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 );
122
116
struct scatterlist sg_out ;
123
117
struct scatterlist sg_in ;
124
118
@@ -127,6 +121,10 @@ cryptoloop_transfer(struct loop_device *lo, int cmd,
127
121
unsigned in_offs , out_offs ;
128
122
int err ;
129
123
124
+ skcipher_request_set_tfm (req , tfm );
125
+ skcipher_request_set_callback (req , CRYPTO_TFM_REQ_MAY_SLEEP ,
126
+ NULL , NULL );
127
+
130
128
sg_init_table (& sg_out , 1 );
131
129
sg_init_table (& sg_in , 1 );
132
130
@@ -135,13 +133,13 @@ cryptoloop_transfer(struct loop_device *lo, int cmd,
135
133
in_offs = raw_off ;
136
134
out_page = loop_page ;
137
135
out_offs = loop_off ;
138
- encdecfunc = crypto_blkcipher_crt ( tfm ) -> decrypt ;
136
+ encdecfunc = crypto_skcipher_decrypt ;
139
137
} else {
140
138
in_page = loop_page ;
141
139
in_offs = loop_off ;
142
140
out_page = raw_page ;
143
141
out_offs = raw_off ;
144
- encdecfunc = crypto_blkcipher_crt ( tfm ) -> encrypt ;
142
+ encdecfunc = crypto_skcipher_encrypt ;
145
143
}
146
144
147
145
while (size > 0 ) {
@@ -152,18 +150,22 @@ cryptoloop_transfer(struct loop_device *lo, int cmd,
152
150
sg_set_page (& sg_in , in_page , sz , in_offs );
153
151
sg_set_page (& sg_out , out_page , sz , out_offs );
154
152
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 );
157
155
if (err )
158
- return err ;
156
+ goto out ;
159
157
160
158
IV ++ ;
161
159
size -= sz ;
162
160
in_offs += sz ;
163
161
out_offs += sz ;
164
162
}
165
163
166
- return 0 ;
164
+ err = 0 ;
165
+
166
+ out :
167
+ skcipher_request_zero (req );
168
+ return err ;
167
169
}
168
170
169
171
static int
@@ -175,9 +177,9 @@ cryptoloop_ioctl(struct loop_device *lo, int cmd, unsigned long arg)
175
177
static int
176
178
cryptoloop_release (struct loop_device * lo )
177
179
{
178
- struct crypto_blkcipher * tfm = lo -> key_data ;
180
+ struct crypto_skcipher * tfm = lo -> key_data ;
179
181
if (tfm != NULL ) {
180
- crypto_free_blkcipher (tfm );
182
+ crypto_free_skcipher (tfm );
181
183
lo -> key_data = NULL ;
182
184
return 0 ;
183
185
}
0 commit comments