diff options
Diffstat (limited to 'fs/cifs/smbencrypt.c')
-rw-r--r-- | fs/cifs/smbencrypt.c | 92 |
1 files changed, 65 insertions, 27 deletions
diff --git a/fs/cifs/smbencrypt.c b/fs/cifs/smbencrypt.c index 192ea51af20f..b5041c849981 100644 --- a/fs/cifs/smbencrypt.c +++ b/fs/cifs/smbencrypt.c | |||
@@ -32,9 +32,8 @@ | |||
32 | #include "cifs_unicode.h" | 32 | #include "cifs_unicode.h" |
33 | #include "cifspdu.h" | 33 | #include "cifspdu.h" |
34 | #include "cifsglob.h" | 34 | #include "cifsglob.h" |
35 | #include "md5.h" | ||
36 | #include "cifs_debug.h" | 35 | #include "cifs_debug.h" |
37 | #include "cifsencrypt.h" | 36 | #include "cifsproto.h" |
38 | 37 | ||
39 | #ifndef false | 38 | #ifndef false |
40 | #define false 0 | 39 | #define false 0 |
@@ -48,14 +47,58 @@ | |||
48 | #define SSVALX(buf,pos,val) (CVAL(buf,pos)=(val)&0xFF,CVAL(buf,pos+1)=(val)>>8) | 47 | #define SSVALX(buf,pos,val) (CVAL(buf,pos)=(val)&0xFF,CVAL(buf,pos+1)=(val)>>8) |
49 | #define SSVAL(buf,pos,val) SSVALX((buf),(pos),((__u16)(val))) | 48 | #define SSVAL(buf,pos,val) SSVALX((buf),(pos),((__u16)(val))) |
50 | 49 | ||
51 | /*The following definitions come from libsmb/smbencrypt.c */ | 50 | /* produce a md4 message digest from data of length n bytes */ |
51 | int | ||
52 | mdfour(unsigned char *md4_hash, unsigned char *link_str, int link_len) | ||
53 | { | ||
54 | int rc; | ||
55 | unsigned int size; | ||
56 | struct crypto_shash *md4; | ||
57 | struct sdesc *sdescmd4; | ||
58 | |||
59 | md4 = crypto_alloc_shash("md4", 0, 0); | ||
60 | if (IS_ERR(md4)) { | ||
61 | rc = PTR_ERR(md4); | ||
62 | cERROR(1, "%s: Crypto md4 allocation error %d\n", __func__, rc); | ||
63 | return rc; | ||
64 | } | ||
65 | size = sizeof(struct shash_desc) + crypto_shash_descsize(md4); | ||
66 | sdescmd4 = kmalloc(size, GFP_KERNEL); | ||
67 | if (!sdescmd4) { | ||
68 | rc = -ENOMEM; | ||
69 | cERROR(1, "%s: Memory allocation failure\n", __func__); | ||
70 | goto mdfour_err; | ||
71 | } | ||
72 | sdescmd4->shash.tfm = md4; | ||
73 | sdescmd4->shash.flags = 0x0; | ||
74 | |||
75 | rc = crypto_shash_init(&sdescmd4->shash); | ||
76 | if (rc) { | ||
77 | cERROR(1, "%s: Could not init md4 shash\n", __func__); | ||
78 | goto mdfour_err; | ||
79 | } | ||
80 | crypto_shash_update(&sdescmd4->shash, link_str, link_len); | ||
81 | rc = crypto_shash_final(&sdescmd4->shash, md4_hash); | ||
52 | 82 | ||
53 | void SMBencrypt(unsigned char *passwd, const unsigned char *c8, | 83 | mdfour_err: |
54 | unsigned char *p24); | 84 | crypto_free_shash(md4); |
55 | void E_md4hash(const unsigned char *passwd, unsigned char *p16); | 85 | kfree(sdescmd4); |
56 | static void SMBOWFencrypt(unsigned char passwd[16], const unsigned char *c8, | 86 | |
57 | unsigned char p24[24]); | 87 | return rc; |
58 | void SMBNTencrypt(unsigned char *passwd, unsigned char *c8, unsigned char *p24); | 88 | } |
89 | |||
90 | /* Does the des encryption from the NT or LM MD4 hash. */ | ||
91 | static void | ||
92 | SMBOWFencrypt(unsigned char passwd[16], const unsigned char *c8, | ||
93 | unsigned char p24[24]) | ||
94 | { | ||
95 | unsigned char p21[21]; | ||
96 | |||
97 | memset(p21, '\0', 21); | ||
98 | |||
99 | memcpy(p21, passwd, 16); | ||
100 | E_P24(p21, c8, p24); | ||
101 | } | ||
59 | 102 | ||
60 | /* | 103 | /* |
61 | This implements the X/Open SMB password encryption | 104 | This implements the X/Open SMB password encryption |
@@ -118,9 +161,10 @@ _my_mbstowcs(__u16 *dst, const unsigned char *src, int len) | |||
118 | * Creates the MD4 Hash of the users password in NT UNICODE. | 161 | * Creates the MD4 Hash of the users password in NT UNICODE. |
119 | */ | 162 | */ |
120 | 163 | ||
121 | void | 164 | int |
122 | E_md4hash(const unsigned char *passwd, unsigned char *p16) | 165 | E_md4hash(const unsigned char *passwd, unsigned char *p16) |
123 | { | 166 | { |
167 | int rc; | ||
124 | int len; | 168 | int len; |
125 | __u16 wpwd[129]; | 169 | __u16 wpwd[129]; |
126 | 170 | ||
@@ -139,8 +183,10 @@ E_md4hash(const unsigned char *passwd, unsigned char *p16) | |||
139 | /* Calculate length in bytes */ | 183 | /* Calculate length in bytes */ |
140 | len = _my_wcslen(wpwd) * sizeof(__u16); | 184 | len = _my_wcslen(wpwd) * sizeof(__u16); |
141 | 185 | ||
142 | mdfour(p16, (unsigned char *) wpwd, len); | 186 | rc = mdfour(p16, (unsigned char *) wpwd, len); |
143 | memset(wpwd, 0, 129 * 2); | 187 | memset(wpwd, 0, 129 * 2); |
188 | |||
189 | return rc; | ||
144 | } | 190 | } |
145 | 191 | ||
146 | #if 0 /* currently unused */ | 192 | #if 0 /* currently unused */ |
@@ -212,19 +258,6 @@ ntv2_owf_gen(const unsigned char owf[16], const char *user_n, | |||
212 | } | 258 | } |
213 | #endif | 259 | #endif |
214 | 260 | ||
215 | /* Does the des encryption from the NT or LM MD4 hash. */ | ||
216 | static void | ||
217 | SMBOWFencrypt(unsigned char passwd[16], const unsigned char *c8, | ||
218 | unsigned char p24[24]) | ||
219 | { | ||
220 | unsigned char p21[21]; | ||
221 | |||
222 | memset(p21, '\0', 21); | ||
223 | |||
224 | memcpy(p21, passwd, 16); | ||
225 | E_P24(p21, c8, p24); | ||
226 | } | ||
227 | |||
228 | /* Does the des encryption from the FIRST 8 BYTES of the NT or LM MD4 hash. */ | 261 | /* Does the des encryption from the FIRST 8 BYTES of the NT or LM MD4 hash. */ |
229 | #if 0 /* currently unused */ | 262 | #if 0 /* currently unused */ |
230 | static void | 263 | static void |
@@ -242,16 +275,21 @@ NTLMSSPOWFencrypt(unsigned char passwd[8], | |||
242 | #endif | 275 | #endif |
243 | 276 | ||
244 | /* Does the NT MD4 hash then des encryption. */ | 277 | /* Does the NT MD4 hash then des encryption. */ |
245 | 278 | int | |
246 | void | ||
247 | SMBNTencrypt(unsigned char *passwd, unsigned char *c8, unsigned char *p24) | 279 | SMBNTencrypt(unsigned char *passwd, unsigned char *c8, unsigned char *p24) |
248 | { | 280 | { |
281 | int rc; | ||
249 | unsigned char p21[21]; | 282 | unsigned char p21[21]; |
250 | 283 | ||
251 | memset(p21, '\0', 21); | 284 | memset(p21, '\0', 21); |
252 | 285 | ||
253 | E_md4hash(passwd, p21); | 286 | rc = E_md4hash(passwd, p21); |
287 | if (rc) { | ||
288 | cFYI(1, "%s Can't generate NT hash, error: %d", __func__, rc); | ||
289 | return rc; | ||
290 | } | ||
254 | SMBOWFencrypt(p21, c8, p24); | 291 | SMBOWFencrypt(p21, c8, p24); |
292 | return rc; | ||
255 | } | 293 | } |
256 | 294 | ||
257 | 295 | ||