Skip to content

Commit 2731a94

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

File tree

4 files changed

+45
-53
lines changed

4 files changed

+45
-53
lines changed

fs/f2fs/crypto.c

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@
2323
* The usage of AES-XTS should conform to recommendations in NIST
2424
* Special Publication 800-38E and IEEE P1619/D16.
2525
*/
26-
#include <crypto/hash.h>
27-
#include <crypto/sha.h>
26+
#include <crypto/skcipher.h>
2827
#include <keys/user-type.h>
2928
#include <keys/encrypted-type.h>
30-
#include <linux/crypto.h>
3129
#include <linux/ecryptfs.h>
3230
#include <linux/gfp.h>
3331
#include <linux/kernel.h>
@@ -328,21 +326,21 @@ static int f2fs_page_crypto(struct f2fs_crypto_ctx *ctx,
328326
struct page *dest_page)
329327
{
330328
u8 xts_tweak[F2FS_XTS_TWEAK_SIZE];
331-
struct ablkcipher_request *req = NULL;
329+
struct skcipher_request *req = NULL;
332330
DECLARE_F2FS_COMPLETION_RESULT(ecr);
333331
struct scatterlist dst, src;
334332
struct f2fs_crypt_info *ci = F2FS_I(inode)->i_crypt_info;
335-
struct crypto_ablkcipher *tfm = ci->ci_ctfm;
333+
struct crypto_skcipher *tfm = ci->ci_ctfm;
336334
int res = 0;
337335

338-
req = ablkcipher_request_alloc(tfm, GFP_NOFS);
336+
req = skcipher_request_alloc(tfm, GFP_NOFS);
339337
if (!req) {
340338
printk_ratelimited(KERN_ERR
341339
"%s: crypto_request_alloc() failed\n",
342340
__func__);
343341
return -ENOMEM;
344342
}
345-
ablkcipher_request_set_callback(
343+
skcipher_request_set_callback(
346344
req, CRYPTO_TFM_REQ_MAY_BACKLOG | CRYPTO_TFM_REQ_MAY_SLEEP,
347345
f2fs_crypt_complete, &ecr);
348346

@@ -355,21 +353,21 @@ static int f2fs_page_crypto(struct f2fs_crypto_ctx *ctx,
355353
sg_set_page(&dst, dest_page, PAGE_CACHE_SIZE, 0);
356354
sg_init_table(&src, 1);
357355
sg_set_page(&src, src_page, PAGE_CACHE_SIZE, 0);
358-
ablkcipher_request_set_crypt(req, &src, &dst, PAGE_CACHE_SIZE,
359-
xts_tweak);
356+
skcipher_request_set_crypt(req, &src, &dst, PAGE_CACHE_SIZE,
357+
xts_tweak);
360358
if (rw == F2FS_DECRYPT)
361-
res = crypto_ablkcipher_decrypt(req);
359+
res = crypto_skcipher_decrypt(req);
362360
else
363-
res = crypto_ablkcipher_encrypt(req);
361+
res = crypto_skcipher_encrypt(req);
364362
if (res == -EINPROGRESS || res == -EBUSY) {
365363
BUG_ON(req->base.data != &ecr);
366364
wait_for_completion(&ecr.completion);
367365
res = ecr.res;
368366
}
369-
ablkcipher_request_free(req);
367+
skcipher_request_free(req);
370368
if (res) {
371369
printk_ratelimited(KERN_ERR
372-
"%s: crypto_ablkcipher_encrypt() returned %d\n",
370+
"%s: crypto_skcipher_encrypt() returned %d\n",
373371
__func__, res);
374372
return res;
375373
}

fs/f2fs/crypto_fname.c

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@
1515
*
1616
* This has not yet undergone a rigorous security audit.
1717
*/
18-
#include <crypto/hash.h>
19-
#include <crypto/sha.h>
18+
#include <crypto/skcipher.h>
2019
#include <keys/encrypted-type.h>
2120
#include <keys/user-type.h>
22-
#include <linux/crypto.h>
2321
#include <linux/gfp.h>
2422
#include <linux/kernel.h>
2523
#include <linux/key.h>
@@ -70,10 +68,10 @@ static int f2fs_fname_encrypt(struct inode *inode,
7068
const struct qstr *iname, struct f2fs_str *oname)
7169
{
7270
u32 ciphertext_len;
73-
struct ablkcipher_request *req = NULL;
71+
struct skcipher_request *req = NULL;
7472
DECLARE_F2FS_COMPLETION_RESULT(ecr);
7573
struct f2fs_crypt_info *ci = F2FS_I(inode)->i_crypt_info;
76-
struct crypto_ablkcipher *tfm = ci->ci_ctfm;
74+
struct crypto_skcipher *tfm = ci->ci_ctfm;
7775
int res = 0;
7876
char iv[F2FS_CRYPTO_BLOCK_SIZE];
7977
struct scatterlist src_sg, dst_sg;
@@ -99,14 +97,14 @@ static int f2fs_fname_encrypt(struct inode *inode,
9997
}
10098

10199
/* Allocate request */
102-
req = ablkcipher_request_alloc(tfm, GFP_NOFS);
100+
req = skcipher_request_alloc(tfm, GFP_NOFS);
103101
if (!req) {
104102
printk_ratelimited(KERN_ERR
105103
"%s: crypto_request_alloc() failed\n", __func__);
106104
kfree(alloc_buf);
107105
return -ENOMEM;
108106
}
109-
ablkcipher_request_set_callback(req,
107+
skcipher_request_set_callback(req,
110108
CRYPTO_TFM_REQ_MAY_BACKLOG | CRYPTO_TFM_REQ_MAY_SLEEP,
111109
f2fs_dir_crypt_complete, &ecr);
112110

@@ -121,15 +119,15 @@ static int f2fs_fname_encrypt(struct inode *inode,
121119
/* Create encryption request */
122120
sg_init_one(&src_sg, workbuf, ciphertext_len);
123121
sg_init_one(&dst_sg, oname->name, ciphertext_len);
124-
ablkcipher_request_set_crypt(req, &src_sg, &dst_sg, ciphertext_len, iv);
125-
res = crypto_ablkcipher_encrypt(req);
122+
skcipher_request_set_crypt(req, &src_sg, &dst_sg, ciphertext_len, iv);
123+
res = crypto_skcipher_encrypt(req);
126124
if (res == -EINPROGRESS || res == -EBUSY) {
127125
BUG_ON(req->base.data != &ecr);
128126
wait_for_completion(&ecr.completion);
129127
res = ecr.res;
130128
}
131129
kfree(alloc_buf);
132-
ablkcipher_request_free(req);
130+
skcipher_request_free(req);
133131
if (res < 0) {
134132
printk_ratelimited(KERN_ERR
135133
"%s: Error (error code %d)\n", __func__, res);
@@ -148,11 +146,11 @@ static int f2fs_fname_encrypt(struct inode *inode,
148146
static int f2fs_fname_decrypt(struct inode *inode,
149147
const struct f2fs_str *iname, struct f2fs_str *oname)
150148
{
151-
struct ablkcipher_request *req = NULL;
149+
struct skcipher_request *req = NULL;
152150
DECLARE_F2FS_COMPLETION_RESULT(ecr);
153151
struct scatterlist src_sg, dst_sg;
154152
struct f2fs_crypt_info *ci = F2FS_I(inode)->i_crypt_info;
155-
struct crypto_ablkcipher *tfm = ci->ci_ctfm;
153+
struct crypto_skcipher *tfm = ci->ci_ctfm;
156154
int res = 0;
157155
char iv[F2FS_CRYPTO_BLOCK_SIZE];
158156
unsigned lim = max_name_len(inode);
@@ -161,13 +159,13 @@ static int f2fs_fname_decrypt(struct inode *inode,
161159
return -EIO;
162160

163161
/* Allocate request */
164-
req = ablkcipher_request_alloc(tfm, GFP_NOFS);
162+
req = skcipher_request_alloc(tfm, GFP_NOFS);
165163
if (!req) {
166164
printk_ratelimited(KERN_ERR
167165
"%s: crypto_request_alloc() failed\n", __func__);
168166
return -ENOMEM;
169167
}
170-
ablkcipher_request_set_callback(req,
168+
skcipher_request_set_callback(req,
171169
CRYPTO_TFM_REQ_MAY_BACKLOG | CRYPTO_TFM_REQ_MAY_SLEEP,
172170
f2fs_dir_crypt_complete, &ecr);
173171

@@ -177,14 +175,14 @@ static int f2fs_fname_decrypt(struct inode *inode,
177175
/* Create decryption request */
178176
sg_init_one(&src_sg, iname->name, iname->len);
179177
sg_init_one(&dst_sg, oname->name, oname->len);
180-
ablkcipher_request_set_crypt(req, &src_sg, &dst_sg, iname->len, iv);
181-
res = crypto_ablkcipher_decrypt(req);
178+
skcipher_request_set_crypt(req, &src_sg, &dst_sg, iname->len, iv);
179+
res = crypto_skcipher_decrypt(req);
182180
if (res == -EINPROGRESS || res == -EBUSY) {
183181
BUG_ON(req->base.data != &ecr);
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(KERN_ERR
190188
"%s: Error in f2fs_fname_decrypt (error code %d)\n",

fs/f2fs/crypto_key.c

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include <linux/random.h>
1515
#include <linux/scatterlist.h>
1616
#include <uapi/linux/keyctl.h>
17-
#include <crypto/hash.h>
17+
#include <crypto/skcipher.h>
1818
#include <linux/f2fs_fs.h>
1919

2020
#include "f2fs.h"
@@ -44,46 +44,43 @@ static int f2fs_derive_key_aes(char deriving_key[F2FS_AES_128_ECB_KEY_SIZE],
4444
char derived_key[F2FS_AES_256_XTS_KEY_SIZE])
4545
{
4646
int res = 0;
47-
struct ablkcipher_request *req = NULL;
47+
struct skcipher_request *req = NULL;
4848
DECLARE_F2FS_COMPLETION_RESULT(ecr);
4949
struct scatterlist src_sg, dst_sg;
50-
struct crypto_ablkcipher *tfm = crypto_alloc_ablkcipher("ecb(aes)", 0,
51-
0);
50+
struct crypto_skcipher *tfm = crypto_alloc_skcipher("ecb(aes)", 0, 0);
5251

5352
if (IS_ERR(tfm)) {
5453
res = PTR_ERR(tfm);
5554
tfm = NULL;
5655
goto out;
5756
}
58-
crypto_ablkcipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
59-
req = ablkcipher_request_alloc(tfm, GFP_NOFS);
57+
crypto_skcipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
58+
req = skcipher_request_alloc(tfm, GFP_NOFS);
6059
if (!req) {
6160
res = -ENOMEM;
6261
goto out;
6362
}
64-
ablkcipher_request_set_callback(req,
63+
skcipher_request_set_callback(req,
6564
CRYPTO_TFM_REQ_MAY_BACKLOG | CRYPTO_TFM_REQ_MAY_SLEEP,
6665
derive_crypt_complete, &ecr);
67-
res = crypto_ablkcipher_setkey(tfm, deriving_key,
66+
res = crypto_skcipher_setkey(tfm, deriving_key,
6867
F2FS_AES_128_ECB_KEY_SIZE);
6968
if (res < 0)
7069
goto out;
7170

7271
sg_init_one(&src_sg, source_key, F2FS_AES_256_XTS_KEY_SIZE);
7372
sg_init_one(&dst_sg, derived_key, F2FS_AES_256_XTS_KEY_SIZE);
74-
ablkcipher_request_set_crypt(req, &src_sg, &dst_sg,
73+
skcipher_request_set_crypt(req, &src_sg, &dst_sg,
7574
F2FS_AES_256_XTS_KEY_SIZE, NULL);
76-
res = crypto_ablkcipher_encrypt(req);
75+
res = crypto_skcipher_encrypt(req);
7776
if (res == -EINPROGRESS || res == -EBUSY) {
7877
BUG_ON(req->base.data != &ecr);
7978
wait_for_completion(&ecr.completion);
8079
res = ecr.res;
8180
}
8281
out:
83-
if (req)
84-
ablkcipher_request_free(req);
85-
if (tfm)
86-
crypto_free_ablkcipher(tfm);
82+
skcipher_request_free(req);
83+
crypto_free_skcipher(tfm);
8784
return res;
8885
}
8986

@@ -93,7 +90,7 @@ static void f2fs_free_crypt_info(struct f2fs_crypt_info *ci)
9390
return;
9491

9592
key_put(ci->ci_keyring_key);
96-
crypto_free_ablkcipher(ci->ci_ctfm);
93+
crypto_free_skcipher(ci->ci_ctfm);
9794
kmem_cache_free(f2fs_crypt_info_cachep, ci);
9895
}
9996

@@ -123,7 +120,7 @@ int _f2fs_get_encryption_info(struct inode *inode)
123120
struct f2fs_encryption_key *master_key;
124121
struct f2fs_encryption_context ctx;
125122
const struct user_key_payload *ukp;
126-
struct crypto_ablkcipher *ctfm;
123+
struct crypto_skcipher *ctfm;
127124
const char *cipher_str;
128125
char raw_key[F2FS_MAX_KEY_SIZE];
129126
char mode;
@@ -213,7 +210,7 @@ int _f2fs_get_encryption_info(struct inode *inode)
213210
if (res)
214211
goto out;
215212

216-
ctfm = crypto_alloc_ablkcipher(cipher_str, 0, 0);
213+
ctfm = crypto_alloc_skcipher(cipher_str, 0, 0);
217214
if (!ctfm || IS_ERR(ctfm)) {
218215
res = ctfm ? PTR_ERR(ctfm) : -ENOMEM;
219216
printk(KERN_DEBUG
@@ -222,11 +219,10 @@ int _f2fs_get_encryption_info(struct inode *inode)
222219
goto out;
223220
}
224221
crypt_info->ci_ctfm = ctfm;
225-
crypto_ablkcipher_clear_flags(ctfm, ~0);
226-
crypto_tfm_set_flags(crypto_ablkcipher_tfm(ctfm),
227-
CRYPTO_TFM_REQ_WEAK_KEY);
228-
res = crypto_ablkcipher_setkey(ctfm, raw_key,
229-
f2fs_encryption_key_size(mode));
222+
crypto_skcipher_clear_flags(ctfm, ~0);
223+
crypto_skcipher_set_flags(ctfm, CRYPTO_TFM_REQ_WEAK_KEY);
224+
res = crypto_skcipher_setkey(ctfm, raw_key,
225+
f2fs_encryption_key_size(mode));
230226
if (res)
231227
goto out;
232228

fs/f2fs/f2fs_crypto.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ struct f2fs_crypt_info {
7878
char ci_data_mode;
7979
char ci_filename_mode;
8080
char ci_flags;
81-
struct crypto_ablkcipher *ci_ctfm;
81+
struct crypto_skcipher *ci_ctfm;
8282
struct key *ci_keyring_key;
8383
char ci_master_key[F2FS_KEY_DESCRIPTOR_SIZE];
8484
};

0 commit comments

Comments
 (0)