diff options
Diffstat (limited to 'fs/cifs/smbencrypt.c')
-rw-r--r-- | fs/cifs/smbencrypt.c | 91 |
1 files changed, 64 insertions, 27 deletions
diff --git a/fs/cifs/smbencrypt.c b/fs/cifs/smbencrypt.c index 192ea51af20..b5450e9f40c 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,57 @@ | |||
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 | cERROR(1, "%s: Crypto md4 allocation error %d\n", __func__, rc); | ||
62 | return PTR_ERR(md4); | ||
63 | } | ||
64 | size = sizeof(struct shash_desc) + crypto_shash_descsize(md4); | ||
65 | sdescmd4 = kmalloc(size, GFP_KERNEL); | ||
66 | if (!sdescmd4) { | ||
67 | rc = -ENOMEM; | ||
68 | cERROR(1, "%s: Memory allocation failure\n", __func__); | ||
69 | goto mdfour_err; | ||
70 | } | ||
71 | sdescmd4->shash.tfm = md4; | ||
72 | sdescmd4->shash.flags = 0x0; | ||
73 | |||
74 | rc = crypto_shash_init(&sdescmd4->shash); | ||
75 | if (rc) { | ||
76 | cERROR(1, "%s: Could not init md4 shash\n", __func__); | ||
77 | goto mdfour_err; | ||
78 | } | ||
79 | crypto_shash_update(&sdescmd4->shash, link_str, link_len); | ||
80 | rc = crypto_shash_final(&sdescmd4->shash, md4_hash); | ||
52 | 81 | ||
53 | void SMBencrypt(unsigned char *passwd, const unsigned char *c8, | 82 | mdfour_err: |
54 | unsigned char *p24); | 83 | crypto_free_shash(md4); |
55 | void E_md4hash(const unsigned char *passwd, unsigned char *p16); | 84 | kfree(sdescmd4); |
56 | static void SMBOWFencrypt(unsigned char passwd[16], const unsigned char *c8, | 85 | |
57 | unsigned char p24[24]); | 86 | return rc; |
58 | void SMBNTencrypt(unsigned char *passwd, unsigned char *c8, unsigned char *p24); | 87 | } |
88 | |||
89 | /* Does the des encryption from the NT or LM MD4 hash. */ | ||
90 | static void | ||
91 | SMBOWFencrypt(unsigned char passwd[16], const unsigned char *c8, | ||
92 | unsigned char p24[24]) | ||
93 | { | ||
94 | unsigned char p21[21]; | ||
95 | |||
96 | memset(p21, '\0', 21); | ||
97 | |||
98 | memcpy(p21, passwd, 16); | ||
99 | E_P24(p21, c8, p24); | ||
100 | } | ||
59 | 101 | ||
60 | /* | 102 | /* |
61 | This implements the X/Open SMB password encryption | 103 | This implements the X/Open SMB password encryption |
@@ -118,9 +160,10 @@ _my_mbstowcs(__u16 *dst, const unsigned char *src, int len) | |||
118 | * Creates the MD4 Hash of the users password in NT UNICODE. | 160 | * Creates the MD4 Hash of the users password in NT UNICODE. |
119 | */ | 161 | */ |
120 | 162 | ||
121 | void | 163 | int |
122 | E_md4hash(const unsigned char *passwd, unsigned char *p16) | 164 | E_md4hash(const unsigned char *passwd, unsigned char *p16) |
123 | { | 165 | { |
166 | int rc; | ||
124 | int len; | 167 | int len; |
125 | __u16 wpwd[129]; | 168 | __u16 wpwd[129]; |
126 | 169 | ||
@@ -139,8 +182,10 @@ E_md4hash(const unsigned char *passwd, unsigned char *p16) | |||
139 | /* Calculate length in bytes */ | 182 | /* Calculate length in bytes */ |
140 | len = _my_wcslen(wpwd) * sizeof(__u16); | 183 | len = _my_wcslen(wpwd) * sizeof(__u16); |
141 | 184 | ||
142 | mdfour(p16, (unsigned char *) wpwd, len); | 185 | rc = mdfour(p16, (unsigned char *) wpwd, len); |
143 | memset(wpwd, 0, 129 * 2); | 186 | memset(wpwd, 0, 129 * 2); |
187 | |||
188 | return rc; | ||
144 | } | 189 | } |
145 | 190 | ||
146 | #if 0 /* currently unused */ | 191 | #if 0 /* currently unused */ |
@@ -212,19 +257,6 @@ ntv2_owf_gen(const unsigned char owf[16], const char *user_n, | |||
212 | } | 257 | } |
213 | #endif | 258 | #endif |
214 | 259 | ||
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. */ | 260 | /* Does the des encryption from the FIRST 8 BYTES of the NT or LM MD4 hash. */ |
229 | #if 0 /* currently unused */ | 261 | #if 0 /* currently unused */ |
230 | static void | 262 | static void |
@@ -242,16 +274,21 @@ NTLMSSPOWFencrypt(unsigned char passwd[8], | |||
242 | #endif | 274 | #endif |
243 | 275 | ||
244 | /* Does the NT MD4 hash then des encryption. */ | 276 | /* Does the NT MD4 hash then des encryption. */ |
245 | 277 | int | |
246 | void | ||
247 | SMBNTencrypt(unsigned char *passwd, unsigned char *c8, unsigned char *p24) | 278 | SMBNTencrypt(unsigned char *passwd, unsigned char *c8, unsigned char *p24) |
248 | { | 279 | { |
280 | int rc; | ||
249 | unsigned char p21[21]; | 281 | unsigned char p21[21]; |
250 | 282 | ||
251 | memset(p21, '\0', 21); | 283 | memset(p21, '\0', 21); |
252 | 284 | ||
253 | E_md4hash(passwd, p21); | 285 | rc = E_md4hash(passwd, p21); |
286 | if (rc) { | ||
287 | cFYI(1, "%s Can't generate NT hash, error: %d", __func__, rc); | ||
288 | return rc; | ||
289 | } | ||
254 | SMBOWFencrypt(p21, c8, p24); | 290 | SMBOWFencrypt(p21, c8, p24); |
291 | return rc; | ||
255 | } | 292 | } |
256 | 293 | ||
257 | 294 | ||