]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
smb: Use arc4 library instead of duplicate arc4 code
authorEric Biggers <ebiggers@kernel.org>
Sun, 7 Sep 2025 03:20:03 +0000 (20:20 -0700)
committerSteve French <stfrench@microsoft.com>
Tue, 30 Sep 2025 02:21:23 +0000 (21:21 -0500)
fs/smb/common/cifs_arc4.c has an implementation of ARC4, but a copy of
this same code is also present in lib/crypto/arc4.c to serve the other
users of this legacy algorithm in the kernel.  Remove the duplicate
implementation in fs/smb/, which seems to have been added because of a
misunderstanding, and just use the lib/crypto/ one.

Signed-off-by: Eric Biggers <ebiggers@kernel.org>
Reviewed-by: Paulo Alcantara (Red Hat) <pc@manguebit.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
fs/smb/client/Kconfig
fs/smb/client/cifsencrypt.c
fs/smb/common/Makefile
fs/smb/common/arc4.h [deleted file]
fs/smb/common/cifs_arc4.c [deleted file]
fs/smb/server/Kconfig
fs/smb/server/auth.c

index 9f05f94e265a6d85a1af0a80a05f106b321021f4..a4c02199fef486d136480a95b2ff6e15ed8551d1 100644 (file)
@@ -15,6 +15,7 @@ config CIFS
        select CRYPTO_GCM
        select CRYPTO_ECB
        select CRYPTO_AES
+       select CRYPTO_LIB_ARC4
        select KEYS
        select DNS_RESOLVER
        select ASN1
index 3cc68624690876f7f74d2bce2f876e92c86246fd..7b7c8c38fdd08d725e5f69f5c1da0b114b363c30 100644 (file)
@@ -22,8 +22,8 @@
 #include <linux/highmem.h>
 #include <linux/fips.h>
 #include <linux/iov_iter.h>
-#include "../common/arc4.h"
 #include <crypto/aead.h>
+#include <crypto/arc4.h>
 
 static size_t cifs_shash_step(void *iter_base, size_t progress, size_t len,
                              void *priv, void *priv2)
@@ -725,9 +725,9 @@ calc_seckey(struct cifs_ses *ses)
                return -ENOMEM;
        }
 
-       cifs_arc4_setkey(ctx_arc4, ses->auth_key.response, CIFS_SESS_KEY_SIZE);
-       cifs_arc4_crypt(ctx_arc4, ses->ntlmssp->ciphertext, sec_key,
-                       CIFS_CPHTXT_SIZE);
+       arc4_setkey(ctx_arc4, ses->auth_key.response, CIFS_SESS_KEY_SIZE);
+       arc4_crypt(ctx_arc4, ses->ntlmssp->ciphertext, sec_key,
+                  CIFS_CPHTXT_SIZE);
 
        /* make secondary_key/nonce as session key */
        memcpy(ses->auth_key.response, sec_key, CIFS_SESS_KEY_SIZE);
index c66dbbc1469c3f68e29660885f12305c3aa8dfe4..9e0730a385fb118fc3c44d139dba24e9fae19c45 100644 (file)
@@ -3,5 +3,4 @@
 # Makefile for Linux filesystem routines that are shared by client and server.
 #
 
-obj-$(CONFIG_SMBFS) += cifs_arc4.o
 obj-$(CONFIG_SMBFS) += cifs_md4.o
diff --git a/fs/smb/common/arc4.h b/fs/smb/common/arc4.h
deleted file mode 100644 (file)
index 12e71ec..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0+ */
-/*
- * Common values for ARC4 Cipher Algorithm
- */
-
-#ifndef _CRYPTO_ARC4_H
-#define _CRYPTO_ARC4_H
-
-#include <linux/types.h>
-
-#define ARC4_MIN_KEY_SIZE      1
-#define ARC4_MAX_KEY_SIZE      256
-#define ARC4_BLOCK_SIZE                1
-
-struct arc4_ctx {
-       u32 S[256];
-       u32 x, y;
-};
-
-int cifs_arc4_setkey(struct arc4_ctx *ctx, const u8 *in_key, unsigned int key_len);
-void cifs_arc4_crypt(struct arc4_ctx *ctx, u8 *out, const u8 *in, unsigned int len);
-
-#endif /* _CRYPTO_ARC4_H */
diff --git a/fs/smb/common/cifs_arc4.c b/fs/smb/common/cifs_arc4.c
deleted file mode 100644 (file)
index df360ca..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-or-later
-/*
- * Cryptographic API
- *
- * ARC4 Cipher Algorithm
- *
- * Jon Oberheide <jon@oberheide.org>
- */
-
-#include <linux/module.h>
-#include "arc4.h"
-
-MODULE_DESCRIPTION("ARC4 Cipher Algorithm");
-MODULE_LICENSE("GPL");
-
-int cifs_arc4_setkey(struct arc4_ctx *ctx, const u8 *in_key, unsigned int key_len)
-{
-       int i, j = 0, k = 0;
-
-       ctx->x = 1;
-       ctx->y = 0;
-
-       for (i = 0; i < 256; i++)
-               ctx->S[i] = i;
-
-       for (i = 0; i < 256; i++) {
-               u32 a = ctx->S[i];
-
-               j = (j + in_key[k] + a) & 0xff;
-               ctx->S[i] = ctx->S[j];
-               ctx->S[j] = a;
-               if (++k >= key_len)
-                       k = 0;
-       }
-
-       return 0;
-}
-EXPORT_SYMBOL_GPL(cifs_arc4_setkey);
-
-void cifs_arc4_crypt(struct arc4_ctx *ctx, u8 *out, const u8 *in, unsigned int len)
-{
-       u32 *const S = ctx->S;
-       u32 x, y, a, b;
-       u32 ty, ta, tb;
-
-       if (len == 0)
-               return;
-
-       x = ctx->x;
-       y = ctx->y;
-
-       a = S[x];
-       y = (y + a) & 0xff;
-       b = S[y];
-
-       do {
-               S[y] = a;
-               a = (a + b) & 0xff;
-               S[x] = b;
-               x = (x + 1) & 0xff;
-               ta = S[x];
-               ty = (y + ta) & 0xff;
-               tb = S[ty];
-               *out++ = *in++ ^ S[a];
-               if (--len == 0)
-                       break;
-               y = ty;
-               a = ta;
-               b = tb;
-       } while (true);
-
-       ctx->x = x;
-       ctx->y = y;
-}
-EXPORT_SYMBOL_GPL(cifs_arc4_crypt);
index 4a23a5e7e8fecd51d807d995f10ece12beebcc5f..098cac98d31e6f829037adeecac468d26016de1f 100644 (file)
@@ -10,6 +10,7 @@ config SMB_SERVER
        select CRYPTO_MD5
        select CRYPTO_HMAC
        select CRYPTO_ECB
+       select CRYPTO_LIB_ARC4
        select CRYPTO_LIB_DES
        select CRYPTO_LIB_SHA256
        select CRYPTO_SHA256
index d99871c214518f4e4bd0fd48a6ec51054b8d3eb4..b4020bb55a26819f6ce12c2c27c384e8967a631c 100644 (file)
@@ -20,6 +20,7 @@
 #include "glob.h"
 
 #include <linux/fips.h>
+#include <crypto/arc4.h>
 #include <crypto/des.h>
 
 #include "server.h"
@@ -29,7 +30,6 @@
 #include "mgmt/user_config.h"
 #include "crypto_ctx.h"
 #include "transport_ipc.h"
-#include "../common/arc4.h"
 
 /*
  * Fixed format data defining GSS header and fixed string
@@ -365,10 +365,9 @@ int ksmbd_decode_ntlmssp_auth_blob(struct authenticate_message *authblob,
                if (!ctx_arc4)
                        return -ENOMEM;
 
-               cifs_arc4_setkey(ctx_arc4, sess->sess_key,
-                                SMB2_NTLMV2_SESSKEY_SIZE);
-               cifs_arc4_crypt(ctx_arc4, sess->sess_key,
-                               (char *)authblob + sess_key_off, sess_key_len);
+               arc4_setkey(ctx_arc4, sess->sess_key, SMB2_NTLMV2_SESSKEY_SIZE);
+               arc4_crypt(ctx_arc4, sess->sess_key,
+                          (char *)authblob + sess_key_off, sess_key_len);
                kfree_sensitive(ctx_arc4);
        }