# Samba 2.2.x: libsmb/smbdes.c ?

Tobbe tnt at home.se
Mon Apr 19 22:02:23 GMT 2004

```Hi,

I've been reading the CIFS Technical Reference about how
the encryption of the passwords are done.

In chapter 2.8.3.2 "LM Session Key" it says:

--------------
S16X = Ex(swab(P14), N8)

Ex(K,D) = the (extended) DES function
P14 = the password
swab(S) = denote the byte string obtained by reversing the order of
the bits in each byte of S, i.e if S is a byte string of length one,
with the value 0x37 then swab(S) is 0xEC
--------------

It is the swab function definition above that I'm interested in.
By looking into the Samba code (2.2.X: source/libsmb/smbdes.c) I
can't find the corresponding function. What I do find (I think),
is the function:

---------------
static void str_to_key(const unsigned char *str,unsigned char *key)
{
int i;

key = str>>1;
key = ((str&0x01)<<6) | (str>>2);
key = ((str&0x03)<<5) | (str>>3);
key = ((str&0x07)<<4) | (str>>4);
key = ((str&0x0F)<<3) | (str>>5);
key = ((str&0x1F)<<2) | (str>>6);
key = ((str&0x3F)<<1) | (str>>7);
key = str&0x7F;
for (i=0;i<8;i++) {
key[i] = (key[i]<<1);
}
}
--------------

which I belive does what the swab function should do (according
to the CIFS definition).

I may be mistaken (I'm not strong in reading C code), but am
I right in that str_to_key/2 corresponds to the swab function ?

If so, what is it that str_to_key/2 does ?
(surely it is not doing a bit reverse of each byte, or...)

Any comments would be appreciated!

Cheers, Tobbe

```

More information about the samba-technical mailing list