r7031: Added encrypt/decrypt function for LSA secrets and trusted
authorJeremy Allison <jra@samba.org>
Fri, 27 May 2005 16:15:56 +0000 (16:15 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 15:57:00 +0000 (10:57 -0500)
domain passwords on the wire.
Jeremy.
(This used to be commit f82dcac25faf7876655cb1839846cc5e01e4add7)

source3/libsmb/smbdes.c
source3/libsmb/smbencrypt.c

index ae946b4a66090cba869c1565a965b1f51e3d722d..70581f1b2d06bbb7213a6e58123fd83ac0425cc4 100644 (file)
@@ -276,7 +276,7 @@ static void str_to_key(const unsigned char *str,unsigned char *key)
 }
 
 
-static void smbhash(unsigned char *out, const unsigned char *in, const unsigned char *key, int forw)
+void smbhash(unsigned char *out, const unsigned char *in, const unsigned char *key, int forw)
 {
        int i;
        char outb[64];
index 55e06ffe9720335213ac401d71132a6e637b394f..d3573d0e1e3df429a2d10a99118f1d09089bcd7f 100644 (file)
@@ -513,6 +513,7 @@ BOOL encode_pw_buffer(char buffer[516], const char *password, int string_flags)
  *new_pw_len is the length in bytes of the possibly mulitbyte
  returned password including termination.
 ************************************************************/
+
 BOOL decode_pw_buffer(uint8 in_buffer[516], char *new_pwrd,
                      int new_pwrd_size, uint32 *new_pw_len,
                      int string_flags)
@@ -554,3 +555,31 @@ BOOL decode_pw_buffer(uint8 in_buffer[516], char *new_pwrd,
        
        return True;
 }
+
+/***********************************************************
+ Encrypt/Decrypt used for LSA secrets and trusted domain
+ passwords.
+************************************************************/
+
+void sess_crypt_blob(DATA_BLOB *out, const DATA_BLOB *in, const DATA_BLOB *session_key, int forward)
+{
+       int i, k;
+
+       for (i=0,k=0;
+            i<in->length;
+            i += 8, k += 7) {
+               uint8_t bin[8], bout[8], key[7];
+
+               memset(bin, 0, 8);
+               memcpy(bin,  &in->data[i], MIN(8, in->length-i));
+
+               if (k + 7 > session_key->length) {
+                       k = (session_key->length - k);
+               }
+               memcpy(key, &session_key->data[k], 7);
+
+               smbhash(bout, bin, key, forward?1:0);
+
+               memcpy(&out->data[i], bout, MIN(8, in->length-i));
+        }
+}