Skip to content

Commit 9651ddb

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

File tree

2 files changed

+40
-18
lines changed

2 files changed

+40
-18
lines changed

fs/cifs/cifsencrypt.c

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <linux/ctype.h>
3434
#include <linux/random.h>
3535
#include <linux/highmem.h>
36+
#include <crypto/skcipher.h>
3637

3738
static int
3839
cifs_crypto_shash_md5_allocate(struct TCP_Server_Info *server)
@@ -789,46 +790,55 @@ int
789790
calc_seckey(struct cifs_ses *ses)
790791
{
791792
int rc;
792-
struct crypto_blkcipher *tfm_arc4;
793+
struct crypto_skcipher *tfm_arc4;
793794
struct scatterlist sgin, sgout;
794-
struct blkcipher_desc desc;
795+
struct skcipher_request *req;
795796
unsigned char sec_key[CIFS_SESS_KEY_SIZE]; /* a nonce */
796797

797798
get_random_bytes(sec_key, CIFS_SESS_KEY_SIZE);
798799

799-
tfm_arc4 = crypto_alloc_blkcipher("ecb(arc4)", 0, CRYPTO_ALG_ASYNC);
800+
tfm_arc4 = crypto_alloc_skcipher("ecb(arc4)", 0, CRYPTO_ALG_ASYNC);
800801
if (IS_ERR(tfm_arc4)) {
801802
rc = PTR_ERR(tfm_arc4);
802803
cifs_dbg(VFS, "could not allocate crypto API arc4\n");
803804
return rc;
804805
}
805806

806-
desc.tfm = tfm_arc4;
807-
808-
rc = crypto_blkcipher_setkey(tfm_arc4, ses->auth_key.response,
807+
rc = crypto_skcipher_setkey(tfm_arc4, ses->auth_key.response,
809808
CIFS_SESS_KEY_SIZE);
810809
if (rc) {
811810
cifs_dbg(VFS, "%s: Could not set response as a key\n",
812811
__func__);
813-
return rc;
812+
goto out_free_cipher;
813+
}
814+
815+
req = skcipher_request_alloc(tfm_arc4, GFP_KERNEL);
816+
if (!req) {
817+
rc = -ENOMEM;
818+
cifs_dbg(VFS, "could not allocate crypto API arc4 request\n");
819+
goto out_free_cipher;
814820
}
815821

816822
sg_init_one(&sgin, sec_key, CIFS_SESS_KEY_SIZE);
817823
sg_init_one(&sgout, ses->ntlmssp->ciphertext, CIFS_CPHTXT_SIZE);
818824

819-
rc = crypto_blkcipher_encrypt(&desc, &sgout, &sgin, CIFS_CPHTXT_SIZE);
825+
skcipher_request_set_callback(req, 0, NULL, NULL);
826+
skcipher_request_set_crypt(req, &sgin, &sgout, CIFS_CPHTXT_SIZE, NULL);
827+
828+
rc = crypto_skcipher_encrypt(req);
829+
skcipher_request_free(req);
820830
if (rc) {
821831
cifs_dbg(VFS, "could not encrypt session key rc: %d\n", rc);
822-
crypto_free_blkcipher(tfm_arc4);
823-
return rc;
832+
goto out_free_cipher;
824833
}
825834

826835
/* make secondary_key/nonce as session key */
827836
memcpy(ses->auth_key.response, sec_key, CIFS_SESS_KEY_SIZE);
828837
/* and make len as that of session key only */
829838
ses->auth_key.len = CIFS_SESS_KEY_SIZE;
830839

831-
crypto_free_blkcipher(tfm_arc4);
840+
out_free_cipher:
841+
crypto_free_skcipher(tfm_arc4);
832842

833843
return rc;
834844
}

fs/cifs/smbencrypt.c

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
2424
*/
2525

26+
#include <crypto/skcipher.h>
2627
#include <linux/module.h>
2728
#include <linux/slab.h>
2829
#include <linux/fs.h>
@@ -70,31 +71,42 @@ smbhash(unsigned char *out, const unsigned char *in, unsigned char *key)
7071
{
7172
int rc;
7273
unsigned char key2[8];
73-
struct crypto_blkcipher *tfm_des;
74+
struct crypto_skcipher *tfm_des;
7475
struct scatterlist sgin, sgout;
75-
struct blkcipher_desc desc;
76+
struct skcipher_request *req;
7677

7778
str_to_key(key, key2);
7879

79-
tfm_des = crypto_alloc_blkcipher("ecb(des)", 0, CRYPTO_ALG_ASYNC);
80+
tfm_des = crypto_alloc_skcipher("ecb(des)", 0, CRYPTO_ALG_ASYNC);
8081
if (IS_ERR(tfm_des)) {
8182
rc = PTR_ERR(tfm_des);
8283
cifs_dbg(VFS, "could not allocate des crypto API\n");
8384
goto smbhash_err;
8485
}
8586

86-
desc.tfm = tfm_des;
87+
req = skcipher_request_alloc(tfm_des, GFP_KERNEL);
88+
if (!req) {
89+
rc = -ENOMEM;
90+
cifs_dbg(VFS, "could not allocate des crypto API\n");
91+
goto smbhash_free_skcipher;
92+
}
8793

88-
crypto_blkcipher_setkey(tfm_des, key2, 8);
94+
crypto_skcipher_setkey(tfm_des, key2, 8);
8995

9096
sg_init_one(&sgin, in, 8);
9197
sg_init_one(&sgout, out, 8);
9298

93-
rc = crypto_blkcipher_encrypt(&desc, &sgout, &sgin, 8);
99+
skcipher_request_set_callback(req, 0, NULL, NULL);
100+
skcipher_request_set_crypt(req, &sgin, &sgout, 8, NULL);
101+
102+
rc = crypto_skcipher_encrypt(req);
94103
if (rc)
95104
cifs_dbg(VFS, "could not encrypt crypt key rc: %d\n", rc);
96105

97-
crypto_free_blkcipher(tfm_des);
106+
skcipher_request_free(req);
107+
108+
smbhash_free_skcipher:
109+
crypto_free_skcipher(tfm_des);
98110
smbhash_err:
99111
return rc;
100112
}

0 commit comments

Comments
 (0)