forked from torvalds/linux
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cifs: fork arc4 and add a private copy in fs/cifs
SMB supports two authentication modes, a modified krb5 mode which contains ActiveDirectory extensions and accound information for the tickets and NTLMSSP. For NTLMSSP in SMB1/2/3 authentication uses a combination of all three of md4/md5/arc4. Fork/copy the ARC4 implementation from the crypto library into fs/cifs so that we have a private version for NTLMSSP once ARC4 is removed from the kernel crypto libraries. Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
- Loading branch information
1 parent
1c2809b
commit 370a85a
Showing
5 changed files
with
94 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
/* | ||
* Cryptographic API | ||
* | ||
* ARC4 Cipher Algorithm | ||
* | ||
* Jon Oberheide <jon@oberheide.org> | ||
*/ | ||
|
||
#include "arc4.h" | ||
|
||
int 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; | ||
} | ||
|
||
void 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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* 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 arc4_setkey(struct arc4_ctx *ctx, const u8 *in_key, unsigned int key_len); | ||
void arc4_crypt(struct arc4_ctx *ctx, u8 *out, const u8 *in, unsigned int len); | ||
|
||
#endif /* _CRYPTO_ARC4_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters