Skip to content

Commit 71c0286

Browse files
Ronnie Sahlbergsmfrench
authored andcommitted
cifs: fork arc4 and create a separate module for it for cifs and other users
We can not drop ARC4 and basically destroy CIFS connectivity for almost all CIFS users so create a new forked ARC4 module that CIFS and other subsystems that have a hard dependency on ARC4 can use. Signed-off-by: Ronnie Sahlberg <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 76a3c92 commit 71c0286

File tree

7 files changed

+128
-5
lines changed

7 files changed

+128
-5
lines changed

fs/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,14 @@ config NFS_V4_2_SSC_HELPER
358358

359359
source "net/sunrpc/Kconfig"
360360
source "fs/ceph/Kconfig"
361+
361362
source "fs/cifs/Kconfig"
363+
364+
config CIFS_COMMON
365+
tristate
366+
default y if CIFS=y
367+
default m if CIFS=m
368+
362369
source "fs/coda/Kconfig"
363370
source "fs/afs/Kconfig"
364371
source "fs/9p/Kconfig"

fs/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ obj-$(CONFIG_LOCKD) += lockd/
9696
obj-$(CONFIG_NLS) += nls/
9797
obj-$(CONFIG_UNICODE) += unicode/
9898
obj-$(CONFIG_SYSV_FS) += sysv/
99+
obj-$(CONFIG_CIFS_COMMON) += cifs_common/
99100
obj-$(CONFIG_CIFS) += cifs/
100101
obj-$(CONFIG_HPFS_FS) += hpfs/
101102
obj-$(CONFIG_NTFS_FS) += ntfs/

fs/cifs/Kconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ config CIFS
1010
select CRYPTO_SHA512
1111
select CRYPTO_CMAC
1212
select CRYPTO_HMAC
13-
select CRYPTO_LIB_ARC4
1413
select CRYPTO_AEAD2
1514
select CRYPTO_CCM
1615
select CRYPTO_GCM

fs/cifs/cifsencrypt.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include <linux/random.h>
2323
#include <linux/highmem.h>
2424
#include <linux/fips.h>
25-
#include <crypto/arc4.h>
25+
#include "../cifs_common/arc4.h"
2626
#include <crypto/aead.h>
2727

2828
int __cifs_calc_signature(struct smb_rqst *rqst,
@@ -699,9 +699,9 @@ calc_seckey(struct cifs_ses *ses)
699699
return -ENOMEM;
700700
}
701701

702-
arc4_setkey(ctx_arc4, ses->auth_key.response, CIFS_SESS_KEY_SIZE);
703-
arc4_crypt(ctx_arc4, ses->ntlmssp->ciphertext, sec_key,
704-
CIFS_CPHTXT_SIZE);
702+
cifs_arc4_setkey(ctx_arc4, ses->auth_key.response, CIFS_SESS_KEY_SIZE);
703+
cifs_arc4_crypt(ctx_arc4, ses->ntlmssp->ciphertext, sec_key,
704+
CIFS_CPHTXT_SIZE);
705705

706706
/* make secondary_key/nonce as session key */
707707
memcpy(ses->auth_key.response, sec_key, CIFS_SESS_KEY_SIZE);

fs/cifs_common/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# SPDX-License-Identifier: GPL-2.0-only
2+
#
3+
# Makefile for Linux filesystem routines that are shared by client and server.
4+
#
5+
6+
obj-$(CONFIG_CIFS_COMMON) += cifs_arc4.o

fs/cifs_common/arc4.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* SPDX-License-Identifier: GPL-2.0+ */
2+
/*
3+
* Common values for ARC4 Cipher Algorithm
4+
*/
5+
6+
#ifndef _CRYPTO_ARC4_H
7+
#define _CRYPTO_ARC4_H
8+
9+
#include <linux/types.h>
10+
11+
#define ARC4_MIN_KEY_SIZE 1
12+
#define ARC4_MAX_KEY_SIZE 256
13+
#define ARC4_BLOCK_SIZE 1
14+
15+
struct arc4_ctx {
16+
u32 S[256];
17+
u32 x, y;
18+
};
19+
20+
int cifs_arc4_setkey(struct arc4_ctx *ctx, const u8 *in_key, unsigned int key_len);
21+
void cifs_arc4_crypt(struct arc4_ctx *ctx, u8 *out, const u8 *in, unsigned int len);
22+
23+
#endif /* _CRYPTO_ARC4_H */

fs/cifs_common/cifs_arc4.c

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
/*
3+
* Cryptographic API
4+
*
5+
* ARC4 Cipher Algorithm
6+
*
7+
* Jon Oberheide <[email protected]>
8+
*/
9+
10+
#include <linux/module.h>
11+
#include "arc4.h"
12+
13+
MODULE_LICENSE("GPL");
14+
15+
int cifs_arc4_setkey(struct arc4_ctx *ctx, const u8 *in_key, unsigned int key_len)
16+
{
17+
int i, j = 0, k = 0;
18+
19+
ctx->x = 1;
20+
ctx->y = 0;
21+
22+
for (i = 0; i < 256; i++)
23+
ctx->S[i] = i;
24+
25+
for (i = 0; i < 256; i++) {
26+
u32 a = ctx->S[i];
27+
28+
j = (j + in_key[k] + a) & 0xff;
29+
ctx->S[i] = ctx->S[j];
30+
ctx->S[j] = a;
31+
if (++k >= key_len)
32+
k = 0;
33+
}
34+
35+
return 0;
36+
}
37+
EXPORT_SYMBOL_GPL(cifs_arc4_setkey);
38+
39+
void cifs_arc4_crypt(struct arc4_ctx *ctx, u8 *out, const u8 *in, unsigned int len)
40+
{
41+
u32 *const S = ctx->S;
42+
u32 x, y, a, b;
43+
u32 ty, ta, tb;
44+
45+
if (len == 0)
46+
return;
47+
48+
x = ctx->x;
49+
y = ctx->y;
50+
51+
a = S[x];
52+
y = (y + a) & 0xff;
53+
b = S[y];
54+
55+
do {
56+
S[y] = a;
57+
a = (a + b) & 0xff;
58+
S[x] = b;
59+
x = (x + 1) & 0xff;
60+
ta = S[x];
61+
ty = (y + ta) & 0xff;
62+
tb = S[ty];
63+
*out++ = *in++ ^ S[a];
64+
if (--len == 0)
65+
break;
66+
y = ty;
67+
a = ta;
68+
b = tb;
69+
} while (true);
70+
71+
ctx->x = x;
72+
ctx->y = y;
73+
}
74+
EXPORT_SYMBOL_GPL(cifs_arc4_crypt);
75+
76+
static int __init
77+
init_cifs_common(void)
78+
{
79+
return 0;
80+
}
81+
static void __init
82+
exit_cifs_common(void)
83+
{
84+
}
85+
86+
module_init(init_cifs_common)
87+
module_exit(exit_cifs_common)

0 commit comments

Comments
 (0)