hc
2024-05-10 9999e48639b3cecb08ffb37358bcba3b48161b29
kernel/fs/cifs/smbencrypt.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 Unix SMB/Netbios implementation.
34 Version 1.9.
....@@ -8,28 +9,16 @@
89 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2002-2003
910 Modified by Steve French (sfrench@us.ibm.com) 2002-2003
1011
11
- This program is free software; you can redistribute it and/or modify
12
- it under the terms of the GNU General Public License as published by
13
- the Free Software Foundation; either version 2 of the License, or
14
- (at your option) any later version.
15
-
16
- This program is distributed in the hope that it will be useful,
17
- but WITHOUT ANY WARRANTY; without even the implied warranty of
18
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
- GNU General Public License for more details.
20
-
21
- You should have received a copy of the GNU General Public License
22
- along with this program; if not, write to the Free Software
23
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
2412 */
2513
26
-#include <linux/crypto.h>
2714 #include <linux/module.h>
2815 #include <linux/slab.h>
16
+#include <linux/fips.h>
2917 #include <linux/fs.h>
3018 #include <linux/string.h>
3119 #include <linux/kernel.h>
3220 #include <linux/random.h>
21
+#include <crypto/des.h>
3322 #include "cifs_fs_sb.h"
3423 #include "cifs_unicode.h"
3524 #include "cifspdu.h"
....@@ -70,19 +59,18 @@
7059 smbhash(unsigned char *out, const unsigned char *in, unsigned char *key)
7160 {
7261 unsigned char key2[8];
73
- struct crypto_cipher *tfm_des;
62
+ struct des_ctx ctx;
7463
7564 str_to_key(key, key2);
7665
77
- tfm_des = crypto_alloc_cipher("des", 0, 0);
78
- if (IS_ERR(tfm_des)) {
79
- cifs_dbg(VFS, "could not allocate des crypto API\n");
80
- return PTR_ERR(tfm_des);
66
+ if (fips_enabled) {
67
+ cifs_dbg(VFS, "FIPS compliance enabled: DES not permitted\n");
68
+ return -ENOENT;
8169 }
8270
83
- crypto_cipher_setkey(tfm_des, key2, 8);
84
- crypto_cipher_encrypt_one(tfm_des, out, in);
85
- crypto_free_cipher(tfm_des);
71
+ des_expand_key(&ctx, key2, DES_KEY_SIZE);
72
+ des_encrypt(&ctx, out, in);
73
+ memzero_explicit(&ctx, sizeof(ctx));
8674
8775 return 0;
8876 }