Skip to content

Commit 3f32a5b

Browse files
committed
ext4: Use skcipher
This patch replaces uses of ablkcipher with skcipher. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 9651ddb commit 3f32a5b

File tree

4 files changed

+47
-53
lines changed

4 files changed

+47
-53
lines changed

fs/ext4/crypto.c

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,9 @@
1818
* Special Publication 800-38E and IEEE P1619/D16.
1919
*/
2020

21-
#include <crypto/hash.h>
22-
#include <crypto/sha.h>
21+
#include <crypto/skcipher.h>
2322
#include <keys/user-type.h>
2423
#include <keys/encrypted-type.h>
25-
#include <linux/crypto.h>
2624
#include <linux/ecryptfs.h>
2725
#include <linux/gfp.h>
2826
#include <linux/kernel.h>
@@ -261,21 +259,21 @@ static int ext4_page_crypto(struct inode *inode,
261259

262260
{
263261
u8 xts_tweak[EXT4_XTS_TWEAK_SIZE];
264-
struct ablkcipher_request *req = NULL;
262+
struct skcipher_request *req = NULL;
265263
DECLARE_EXT4_COMPLETION_RESULT(ecr);
266264
struct scatterlist dst, src;
267265
struct ext4_crypt_info *ci = EXT4_I(inode)->i_crypt_info;
268-
struct crypto_ablkcipher *tfm = ci->ci_ctfm;
266+
struct crypto_skcipher *tfm = ci->ci_ctfm;
269267
int res = 0;
270268

271-
req = ablkcipher_request_alloc(tfm, GFP_NOFS);
269+
req = skcipher_request_alloc(tfm, GFP_NOFS);
272270
if (!req) {
273271
printk_ratelimited(KERN_ERR
274272
"%s: crypto_request_alloc() failed\n",
275273
__func__);
276274
return -ENOMEM;
277275
}
278-
ablkcipher_request_set_callback(
276+
skcipher_request_set_callback(
279277
req, CRYPTO_TFM_REQ_MAY_BACKLOG | CRYPTO_TFM_REQ_MAY_SLEEP,
280278
ext4_crypt_complete, &ecr);
281279

@@ -288,21 +286,21 @@ static int ext4_page_crypto(struct inode *inode,
288286
sg_set_page(&dst, dest_page, PAGE_CACHE_SIZE, 0);
289287
sg_init_table(&src, 1);
290288
sg_set_page(&src, src_page, PAGE_CACHE_SIZE, 0);
291-
ablkcipher_request_set_crypt(req, &src, &dst, PAGE_CACHE_SIZE,
292-
xts_tweak);
289+
skcipher_request_set_crypt(req, &src, &dst, PAGE_CACHE_SIZE,
290+
xts_tweak);
293291
if (rw == EXT4_DECRYPT)
294-
res = crypto_ablkcipher_decrypt(req);
292+
res = crypto_skcipher_decrypt(req);
295293
else
296-
res = crypto_ablkcipher_encrypt(req);
294+
res = crypto_skcipher_encrypt(req);
297295
if (res == -EINPROGRESS || res == -EBUSY) {
298296
wait_for_completion(&ecr.completion);
299297
res = ecr.res;
300298
}
301-
ablkcipher_request_free(req);
299+
skcipher_request_free(req);
302300
if (res) {
303301
printk_ratelimited(
304302
KERN_ERR
305-
"%s: crypto_ablkcipher_encrypt() returned %d\n",
303+
"%s: crypto_skcipher_encrypt() returned %d\n",
306304
__func__, res);
307305
return res;
308306
}

fs/ext4/crypto_fname.c

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@
1111
*
1212
*/
1313

14-
#include <crypto/hash.h>
15-
#include <crypto/sha.h>
14+
#include <crypto/skcipher.h>
1615
#include <keys/encrypted-type.h>
1716
#include <keys/user-type.h>
18-
#include <linux/crypto.h>
1917
#include <linux/gfp.h>
2018
#include <linux/kernel.h>
2119
#include <linux/key.h>
@@ -65,10 +63,10 @@ static int ext4_fname_encrypt(struct inode *inode,
6563
struct ext4_str *oname)
6664
{
6765
u32 ciphertext_len;
68-
struct ablkcipher_request *req = NULL;
66+
struct skcipher_request *req = NULL;
6967
DECLARE_EXT4_COMPLETION_RESULT(ecr);
7068
struct ext4_crypt_info *ci = EXT4_I(inode)->i_crypt_info;
71-
struct crypto_ablkcipher *tfm = ci->ci_ctfm;
69+
struct crypto_skcipher *tfm = ci->ci_ctfm;
7270
int res = 0;
7371
char iv[EXT4_CRYPTO_BLOCK_SIZE];
7472
struct scatterlist src_sg, dst_sg;
@@ -95,14 +93,14 @@ static int ext4_fname_encrypt(struct inode *inode,
9593
}
9694

9795
/* Allocate request */
98-
req = ablkcipher_request_alloc(tfm, GFP_NOFS);
96+
req = skcipher_request_alloc(tfm, GFP_NOFS);
9997
if (!req) {
10098
printk_ratelimited(
10199
KERN_ERR "%s: crypto_request_alloc() failed\n", __func__);
102100
kfree(alloc_buf);
103101
return -ENOMEM;
104102
}
105-
ablkcipher_request_set_callback(req,
103+
skcipher_request_set_callback(req,
106104
CRYPTO_TFM_REQ_MAY_BACKLOG | CRYPTO_TFM_REQ_MAY_SLEEP,
107105
ext4_dir_crypt_complete, &ecr);
108106

@@ -117,14 +115,14 @@ static int ext4_fname_encrypt(struct inode *inode,
117115
/* Create encryption request */
118116
sg_init_one(&src_sg, workbuf, ciphertext_len);
119117
sg_init_one(&dst_sg, oname->name, ciphertext_len);
120-
ablkcipher_request_set_crypt(req, &src_sg, &dst_sg, ciphertext_len, iv);
121-
res = crypto_ablkcipher_encrypt(req);
118+
skcipher_request_set_crypt(req, &src_sg, &dst_sg, ciphertext_len, iv);
119+
res = crypto_skcipher_encrypt(req);
122120
if (res == -EINPROGRESS || res == -EBUSY) {
123121
wait_for_completion(&ecr.completion);
124122
res = ecr.res;
125123
}
126124
kfree(alloc_buf);
127-
ablkcipher_request_free(req);
125+
skcipher_request_free(req);
128126
if (res < 0) {
129127
printk_ratelimited(
130128
KERN_ERR "%s: Error (error code %d)\n", __func__, res);
@@ -145,11 +143,11 @@ static int ext4_fname_decrypt(struct inode *inode,
145143
struct ext4_str *oname)
146144
{
147145
struct ext4_str tmp_in[2], tmp_out[1];
148-
struct ablkcipher_request *req = NULL;
146+
struct skcipher_request *req = NULL;
149147
DECLARE_EXT4_COMPLETION_RESULT(ecr);
150148
struct scatterlist src_sg, dst_sg;
151149
struct ext4_crypt_info *ci = EXT4_I(inode)->i_crypt_info;
152-
struct crypto_ablkcipher *tfm = ci->ci_ctfm;
150+
struct crypto_skcipher *tfm = ci->ci_ctfm;
153151
int res = 0;
154152
char iv[EXT4_CRYPTO_BLOCK_SIZE];
155153
unsigned lim = max_name_len(inode);
@@ -162,13 +160,13 @@ static int ext4_fname_decrypt(struct inode *inode,
162160
tmp_out[0].name = oname->name;
163161

164162
/* Allocate request */
165-
req = ablkcipher_request_alloc(tfm, GFP_NOFS);
163+
req = skcipher_request_alloc(tfm, GFP_NOFS);
166164
if (!req) {
167165
printk_ratelimited(
168166
KERN_ERR "%s: crypto_request_alloc() failed\n", __func__);
169167
return -ENOMEM;
170168
}
171-
ablkcipher_request_set_callback(req,
169+
skcipher_request_set_callback(req,
172170
CRYPTO_TFM_REQ_MAY_BACKLOG | CRYPTO_TFM_REQ_MAY_SLEEP,
173171
ext4_dir_crypt_complete, &ecr);
174172

@@ -178,13 +176,13 @@ static int ext4_fname_decrypt(struct inode *inode,
178176
/* Create encryption request */
179177
sg_init_one(&src_sg, iname->name, iname->len);
180178
sg_init_one(&dst_sg, oname->name, oname->len);
181-
ablkcipher_request_set_crypt(req, &src_sg, &dst_sg, iname->len, iv);
182-
res = crypto_ablkcipher_decrypt(req);
179+
skcipher_request_set_crypt(req, &src_sg, &dst_sg, iname->len, iv);
180+
res = crypto_skcipher_decrypt(req);
183181
if (res == -EINPROGRESS || res == -EBUSY) {
184182
wait_for_completion(&ecr.completion);
185183
res = ecr.res;
186184
}
187-
ablkcipher_request_free(req);
185+
skcipher_request_free(req);
188186
if (res < 0) {
189187
printk_ratelimited(
190188
KERN_ERR "%s: Error in ext4_fname_encrypt (error code %d)\n",

fs/ext4/crypto_key.c

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* Written by Michael Halcrow, Ildar Muslukhov, and Uday Savagaonkar, 2015.
99
*/
1010

11+
#include <crypto/skcipher.h>
1112
#include <keys/encrypted-type.h>
1213
#include <keys/user-type.h>
1314
#include <linux/random.h>
@@ -41,45 +42,42 @@ static int ext4_derive_key_aes(char deriving_key[EXT4_AES_128_ECB_KEY_SIZE],
4142
char derived_key[EXT4_AES_256_XTS_KEY_SIZE])
4243
{
4344
int res = 0;
44-
struct ablkcipher_request *req = NULL;
45+
struct skcipher_request *req = NULL;
4546
DECLARE_EXT4_COMPLETION_RESULT(ecr);
4647
struct scatterlist src_sg, dst_sg;
47-
struct crypto_ablkcipher *tfm = crypto_alloc_ablkcipher("ecb(aes)", 0,
48-
0);
48+
struct crypto_skcipher *tfm = crypto_alloc_skcipher("ecb(aes)", 0, 0);
4949

5050
if (IS_ERR(tfm)) {
5151
res = PTR_ERR(tfm);
5252
tfm = NULL;
5353
goto out;
5454
}
55-
crypto_ablkcipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
56-
req = ablkcipher_request_alloc(tfm, GFP_NOFS);
55+
crypto_skcipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
56+
req = skcipher_request_alloc(tfm, GFP_NOFS);
5757
if (!req) {
5858
res = -ENOMEM;
5959
goto out;
6060
}
61-
ablkcipher_request_set_callback(req,
61+
skcipher_request_set_callback(req,
6262
CRYPTO_TFM_REQ_MAY_BACKLOG | CRYPTO_TFM_REQ_MAY_SLEEP,
6363
derive_crypt_complete, &ecr);
64-
res = crypto_ablkcipher_setkey(tfm, deriving_key,
65-
EXT4_AES_128_ECB_KEY_SIZE);
64+
res = crypto_skcipher_setkey(tfm, deriving_key,
65+
EXT4_AES_128_ECB_KEY_SIZE);
6666
if (res < 0)
6767
goto out;
6868
sg_init_one(&src_sg, source_key, EXT4_AES_256_XTS_KEY_SIZE);
6969
sg_init_one(&dst_sg, derived_key, EXT4_AES_256_XTS_KEY_SIZE);
70-
ablkcipher_request_set_crypt(req, &src_sg, &dst_sg,
71-
EXT4_AES_256_XTS_KEY_SIZE, NULL);
72-
res = crypto_ablkcipher_encrypt(req);
70+
skcipher_request_set_crypt(req, &src_sg, &dst_sg,
71+
EXT4_AES_256_XTS_KEY_SIZE, NULL);
72+
res = crypto_skcipher_encrypt(req);
7373
if (res == -EINPROGRESS || res == -EBUSY) {
7474
wait_for_completion(&ecr.completion);
7575
res = ecr.res;
7676
}
7777

7878
out:
79-
if (req)
80-
ablkcipher_request_free(req);
81-
if (tfm)
82-
crypto_free_ablkcipher(tfm);
79+
skcipher_request_free(req);
80+
crypto_free_skcipher(tfm);
8381
return res;
8482
}
8583

@@ -90,7 +88,7 @@ void ext4_free_crypt_info(struct ext4_crypt_info *ci)
9088

9189
if (ci->ci_keyring_key)
9290
key_put(ci->ci_keyring_key);
93-
crypto_free_ablkcipher(ci->ci_ctfm);
91+
crypto_free_skcipher(ci->ci_ctfm);
9492
kmem_cache_free(ext4_crypt_info_cachep, ci);
9593
}
9694

@@ -122,7 +120,7 @@ int _ext4_get_encryption_info(struct inode *inode)
122120
struct ext4_encryption_context ctx;
123121
const struct user_key_payload *ukp;
124122
struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
125-
struct crypto_ablkcipher *ctfm;
123+
struct crypto_skcipher *ctfm;
126124
const char *cipher_str;
127125
char raw_key[EXT4_MAX_KEY_SIZE];
128126
char mode;
@@ -237,7 +235,7 @@ int _ext4_get_encryption_info(struct inode *inode)
237235
if (res)
238236
goto out;
239237
got_key:
240-
ctfm = crypto_alloc_ablkcipher(cipher_str, 0, 0);
238+
ctfm = crypto_alloc_skcipher(cipher_str, 0, 0);
241239
if (!ctfm || IS_ERR(ctfm)) {
242240
res = ctfm ? PTR_ERR(ctfm) : -ENOMEM;
243241
printk(KERN_DEBUG
@@ -246,11 +244,11 @@ int _ext4_get_encryption_info(struct inode *inode)
246244
goto out;
247245
}
248246
crypt_info->ci_ctfm = ctfm;
249-
crypto_ablkcipher_clear_flags(ctfm, ~0);
250-
crypto_tfm_set_flags(crypto_ablkcipher_tfm(ctfm),
247+
crypto_skcipher_clear_flags(ctfm, ~0);
248+
crypto_tfm_set_flags(crypto_skcipher_tfm(ctfm),
251249
CRYPTO_TFM_REQ_WEAK_KEY);
252-
res = crypto_ablkcipher_setkey(ctfm, raw_key,
253-
ext4_encryption_key_size(mode));
250+
res = crypto_skcipher_setkey(ctfm, raw_key,
251+
ext4_encryption_key_size(mode));
254252
if (res)
255253
goto out;
256254
memzero_explicit(raw_key, sizeof(raw_key));

fs/ext4/ext4_crypto.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ struct ext4_crypt_info {
7777
char ci_data_mode;
7878
char ci_filename_mode;
7979
char ci_flags;
80-
struct crypto_ablkcipher *ci_ctfm;
80+
struct crypto_skcipher *ci_ctfm;
8181
struct key *ci_keyring_key;
8282
char ci_master_key[EXT4_KEY_DESCRIPTOR_SIZE];
8383
};

0 commit comments

Comments
 (0)