diff options
author | Jeremy Allison <jra@samba.org> | 2005-05-27 16:21:19 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 10:57:00 -0500 |
commit | e9b511a32df8e61e34e585d66fc5c4b187da60f0 (patch) | |
tree | 110d300f9be02eafd90eb5b54893d666b5e034d7 | |
parent | 26e12ebd07afbafb29f4d2974a9dd599eec606e0 (diff) | |
download | samba-e9b511a32df8e61e34e585d66fc5c4b187da60f0.tar.gz samba-e9b511a32df8e61e34e585d66fc5c4b187da60f0.tar.bz2 samba-e9b511a32df8e61e34e585d66fc5c4b187da60f0.zip |
r7033: Call a spade a spade :-).
Jeremy.
(This used to be commit f5027f6370bd085a8d4c1a221881eebb0e4ffbab)
-rw-r--r-- | source3/libsmb/smbdes.c | 174 | ||||
-rw-r--r-- | source3/libsmb/smbencrypt.c | 2 |
2 files changed, 85 insertions, 91 deletions
diff --git a/source3/libsmb/smbdes.c b/source3/libsmb/smbdes.c index 70581f1b2d..b7f0cd05c3 100644 --- a/source3/libsmb/smbdes.c +++ b/source3/libsmb/smbdes.c @@ -276,7 +276,7 @@ static void str_to_key(const unsigned char *str,unsigned char *key) } -void smbhash(unsigned char *out, const unsigned char *in, const unsigned char *key, int forw) +void des_crypt56(unsigned char *out, const unsigned char *in, const unsigned char *key, int forw) { int i; char outb[64]; @@ -307,35 +307,35 @@ void smbhash(unsigned char *out, const unsigned char *in, const unsigned char *k void E_P16(const unsigned char *p14,unsigned char *p16) { unsigned char sp8[8] = {0x4b, 0x47, 0x53, 0x21, 0x40, 0x23, 0x24, 0x25}; - smbhash(p16, sp8, p14, 1); - smbhash(p16+8, sp8, p14+7, 1); + des_crypt56(p16, sp8, p14, 1); + des_crypt56(p16+8, sp8, p14+7, 1); } void E_P24(const unsigned char *p21, const unsigned char *c8, unsigned char *p24) { - smbhash(p24, c8, p21, 1); - smbhash(p24+8, c8, p21+7, 1); - smbhash(p24+16, c8, p21+14, 1); + des_crypt56(p24, c8, p21, 1); + des_crypt56(p24+8, c8, p21+7, 1); + des_crypt56(p24+16, c8, p21+14, 1); } void D_P16(const unsigned char *p14, const unsigned char *in, unsigned char *out) { - smbhash(out, in, p14, 0); - smbhash(out+8, in+8, p14+7, 0); + des_crypt56(out, in, p14, 0); + des_crypt56(out+8, in+8, p14+7, 0); } void E_old_pw_hash( unsigned char *p14, const unsigned char *in, unsigned char *out) { - smbhash(out, in, p14, 1); - smbhash(out+8, in+8, p14+7, 1); + des_crypt56(out, in, p14, 1); + des_crypt56(out+8, in+8, p14+7, 1); } void cred_hash1(unsigned char *out, const unsigned char *in, const unsigned char *key) { unsigned char buf[8]; - smbhash(buf, in, key, 1); - smbhash(out, buf, key+9, 1); + des_crypt56(buf, in, key, 1); + des_crypt56(out, buf, key+9, 1); } void cred_hash2(unsigned char *out, const unsigned char *in, const unsigned char *key) @@ -343,98 +343,92 @@ void cred_hash2(unsigned char *out, const unsigned char *in, const unsigned char unsigned char buf[8]; static unsigned char key2[8]; - smbhash(buf, in, key, 1); + des_crypt56(buf, in, key, 1); key2[0] = key[7]; - smbhash(out, buf, key2, 1); + des_crypt56(out, buf, key2, 1); } void cred_hash3(unsigned char *out, unsigned char *in, const unsigned char *key, int forw) { static unsigned char key2[8]; - smbhash(out, in, key, forw); + des_crypt56(out, in, key, forw); key2[0] = key[7]; - smbhash(out + 8, in + 8, key2, forw); + des_crypt56(out + 8, in + 8, key2, forw); } void SamOEMhash( unsigned char *data, const unsigned char *key, int val) { - unsigned char s_box[256]; - unsigned char index_i = 0; - unsigned char index_j = 0; - unsigned char j = 0; - int ind; - - for (ind = 0; ind < 256; ind++) - { - s_box[ind] = (unsigned char)ind; - } - - for( ind = 0; ind < 256; ind++) - { - unsigned char tc; - - j += (s_box[ind] + key[ind%16]); - - tc = s_box[ind]; - s_box[ind] = s_box[j]; - s_box[j] = tc; - } - for( ind = 0; ind < val; ind++) - { - unsigned char tc; - unsigned char t; - - index_i++; - index_j += s_box[index_i]; - - tc = s_box[index_i]; - s_box[index_i] = s_box[index_j]; - s_box[index_j] = tc; - - t = s_box[index_i] + s_box[index_j]; - data[ind] = data[ind] ^ s_box[t]; - } + unsigned char s_box[256]; + unsigned char index_i = 0; + unsigned char index_j = 0; + unsigned char j = 0; + int ind; + + for (ind = 0; ind < 256; ind++) { + s_box[ind] = (unsigned char)ind; + } + + for( ind = 0; ind < 256; ind++) { + unsigned char tc; + + j += (s_box[ind] + key[ind%16]); + + tc = s_box[ind]; + s_box[ind] = s_box[j]; + s_box[j] = tc; + } + for( ind = 0; ind < val; ind++) { + unsigned char tc; + unsigned char t; + + index_i++; + index_j += s_box[index_i]; + + tc = s_box[index_i]; + s_box[index_i] = s_box[index_j]; + s_box[index_j] = tc; + + t = s_box[index_i] + s_box[index_j]; + data[ind] = data[ind] ^ s_box[t]; + } } void SamOEMhashBlob( unsigned char *data, int len, DATA_BLOB *key) { - unsigned char s_box[256]; - unsigned char index_i = 0; - unsigned char index_j = 0; - unsigned char j = 0; - int ind; - - for (ind = 0; ind < 256; ind++) - { - s_box[ind] = (unsigned char)ind; - } - - for( ind = 0; ind < 256; ind++) - { - unsigned char tc; - - j += (s_box[ind] + key->data[ind%key->length]); - - tc = s_box[ind]; - s_box[ind] = s_box[j]; - s_box[j] = tc; - } - for( ind = 0; ind < len; ind++) - { - unsigned char tc; - unsigned char t; - - index_i++; - index_j += s_box[index_i]; - - tc = s_box[index_i]; - s_box[index_i] = s_box[index_j]; - s_box[index_j] = tc; - - t = s_box[index_i] + s_box[index_j]; - data[ind] = data[ind] ^ s_box[t]; - } + unsigned char s_box[256]; + unsigned char index_i = 0; + unsigned char index_j = 0; + unsigned char j = 0; + int ind; + + for (ind = 0; ind < 256; ind++) { + s_box[ind] = (unsigned char)ind; + } + + for( ind = 0; ind < 256; ind++) { + unsigned char tc; + + j += (s_box[ind] + key->data[ind%key->length]); + + tc = s_box[ind]; + s_box[ind] = s_box[j]; + s_box[j] = tc; + } + for( ind = 0; ind < len; ind++) { + unsigned char tc; + unsigned char t; + + index_i++; + index_j += s_box[index_i]; + + tc = s_box[index_i]; + s_box[index_i] = s_box[index_j]; + s_box[index_j] = tc; + + t = s_box[index_i] + s_box[index_j]; + data[ind] = data[ind] ^ s_box[t]; + } } /* Decode a sam password hash into a password. The password hash is the @@ -450,6 +444,6 @@ void sam_pwd_hash(unsigned int rid, const uchar *in, uchar *out, int forw) s[2] = s[6] = s[10] = (uchar)((rid >> 16) & 0xFF); s[3] = s[7] = s[11] = (uchar)((rid >> 24) & 0xFF); - smbhash(out, in, s, forw); - smbhash(out+8, in+8, s+7, forw); + des_crypt56(out, in, s, forw); + des_crypt56(out+8, in+8, s+7, forw); } diff --git a/source3/libsmb/smbencrypt.c b/source3/libsmb/smbencrypt.c index d3573d0e1e..ab61f6b419 100644 --- a/source3/libsmb/smbencrypt.c +++ b/source3/libsmb/smbencrypt.c @@ -578,7 +578,7 @@ void sess_crypt_blob(DATA_BLOB *out, const DATA_BLOB *in, const DATA_BLOB *sessi } memcpy(key, &session_key->data[k], 7); - smbhash(bout, bin, key, forward?1:0); + des_crypt56(bout, bin, key, forward?1:0); memcpy(&out->data[i], bout, MIN(8, in->length-i)); } |