26 #include <linux/module.h>
27 #include <linux/slab.h>
29 #include <linux/string.h>
30 #include <linux/kernel.h>
31 #include <linux/random.h>
46 #define CVAL(buf,pos) (((unsigned char *)(buf))[pos])
47 #define SSVALX(buf,pos,val) (CVAL(buf,pos)=(val)&0xFF,CVAL(buf,pos+1)=(val)>>8)
48 #define SSVAL(buf,pos,val) SSVALX((buf),(pos),((__u16)(val)))
51 str_to_key(
unsigned char *
str,
unsigned char *
key)
56 key[1] = ((str[0] & 0x01) << 6) | (str[1] >> 2);
57 key[2] = ((str[1] & 0x03) << 5) | (str[2] >> 3);
58 key[3] = ((str[2] & 0x07) << 4) | (str[3] >> 4);
59 key[4] = ((str[3] & 0x0F) << 3) | (str[4] >> 5);
60 key[5] = ((str[4] & 0x1F) << 2) | (str[5] >> 6);
61 key[6] = ((str[5] & 0x3F) << 1) | (str[6] >> 7);
62 key[7] = str[6] & 0x7F;
63 for (i = 0; i < 8; i++)
64 key[i] = (key[i] << 1);
68 smbhash(
unsigned char *
out,
const unsigned char *
in,
unsigned char *
key)
71 unsigned char key2[8];
76 str_to_key(key, key2);
79 if (IS_ERR(tfm_des)) {
80 rc = PTR_ERR(tfm_des);
81 cERROR(1,
"could not allocate des crypto API");
87 crypto_blkcipher_setkey(tfm_des, key2, 8);
92 rc = crypto_blkcipher_encrypt(&
desc, &sgout, &sgin, 8);
94 cERROR(1,
"could not encrypt crypt key rc: %d", rc);
96 crypto_free_blkcipher(tfm_des);
102 E_P16(
unsigned char *p14,
unsigned char *p16)
105 unsigned char sp8[8] =
106 { 0x4b, 0x47, 0x53, 0x21, 0x40, 0x23, 0x24, 0x25 };
108 rc = smbhash(p16, sp8, p14);
111 rc = smbhash(p16 + 8, sp8, p14 + 7);
116 E_P24(
unsigned char *p21,
const unsigned char *c8,
unsigned char *p24)
120 rc = smbhash(p24, c8, p21);
123 rc = smbhash(p24 + 8, c8, p21 + 7);
126 rc = smbhash(p24 + 16, c8, p21 + 14);
132 mdfour(
unsigned char *md4_hash,
unsigned char *link_str,
int link_len)
137 struct sdesc *sdescmd4;
142 cERROR(1,
"%s: Crypto md4 allocation error %d", __func__, rc);
145 size =
sizeof(
struct shash_desc) + crypto_shash_descsize(md4);
149 cERROR(1,
"%s: Memory allocation failure", __func__);
152 sdescmd4->shash.tfm = md4;
153 sdescmd4->shash.
flags = 0x0;
155 rc = crypto_shash_init(&sdescmd4->shash);
157 cERROR(1,
"%s: Could not init md4 shash", __func__);
162 cERROR(1,
"%s: Could not update with link_str", __func__);
167 cERROR(1,
"%s: Could not genereate md4 hash", __func__);
170 crypto_free_shash(md4);
182 SMBencrypt(
unsigned char *passwd,
const unsigned char *c8,
unsigned char *p24)
185 unsigned char p14[14], p16[16], p21[21];
192 rc = E_P16(p14, p16);
197 rc = E_P24(p21, c8, p24);
207 E_md4hash(
const unsigned char *passwd,
unsigned char *p16,
222 rc =
mdfour(p16, (
unsigned char *) wpwd, len *
sizeof(
__le16));
230 SMBNTencrypt(
unsigned char *passwd,
unsigned char *c8,
unsigned char *p24,
234 unsigned char p16[16], p21[21];
241 cFYI(1,
"%s Can't generate NT hash, error: %d", __func__, rc);
245 rc = E_P24(p21, c8, p24);