0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include <linux/module.h>
0015 #include <linux/slab.h>
0016 #include <linux/fips.h>
0017 #include <linux/fs.h>
0018 #include <linux/string.h>
0019 #include <linux/kernel.h>
0020 #include <linux/random.h>
0021 #include "cifs_fs_sb.h"
0022 #include "cifs_unicode.h"
0023 #include "cifspdu.h"
0024 #include "cifsglob.h"
0025 #include "cifs_debug.h"
0026 #include "cifsproto.h"
0027 #include "../smbfs_common/md4.h"
0028
0029 #ifndef false
0030 #define false 0
0031 #endif
0032 #ifndef true
0033 #define true 1
0034 #endif
0035
0036
0037 #define CVAL(buf,pos) (((unsigned char *)(buf))[pos])
0038 #define SSVALX(buf,pos,val) (CVAL(buf,pos)=(val)&0xFF,CVAL(buf,pos+1)=(val)>>8)
0039 #define SSVAL(buf,pos,val) SSVALX((buf),(pos),((__u16)(val)))
0040
0041
0042 static int
0043 mdfour(unsigned char *md4_hash, unsigned char *link_str, int link_len)
0044 {
0045 int rc;
0046 struct md4_ctx mctx;
0047
0048 rc = cifs_md4_init(&mctx);
0049 if (rc) {
0050 cifs_dbg(VFS, "%s: Could not init MD4\n", __func__);
0051 goto mdfour_err;
0052 }
0053 rc = cifs_md4_update(&mctx, link_str, link_len);
0054 if (rc) {
0055 cifs_dbg(VFS, "%s: Could not update MD4\n", __func__);
0056 goto mdfour_err;
0057 }
0058 rc = cifs_md4_final(&mctx, md4_hash);
0059 if (rc)
0060 cifs_dbg(VFS, "%s: Could not finalize MD4\n", __func__);
0061
0062
0063 mdfour_err:
0064 return rc;
0065 }
0066
0067
0068
0069
0070
0071 int
0072 E_md4hash(const unsigned char *passwd, unsigned char *p16,
0073 const struct nls_table *codepage)
0074 {
0075 int rc;
0076 int len;
0077 __le16 wpwd[129];
0078
0079
0080 if (passwd)
0081 len = cifs_strtoUTF16(wpwd, passwd, 128, codepage);
0082 else {
0083 len = 0;
0084 *wpwd = 0;
0085 }
0086
0087 rc = mdfour(p16, (unsigned char *) wpwd, len * sizeof(__le16));
0088 memzero_explicit(wpwd, sizeof(wpwd));
0089
0090 return rc;
0091 }