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

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

```Hi,

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
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[0] = str[0]>>1;
key[1] = ((str[0]&0x01)<<6) | (str[1]>>2);
key[2] = ((str[1]&0x03)<<5) | (str[2]>>3);
key[3] = ((str[2]&0x07)<<4) | (str[3]>>4);
key[4] = ((str[3]&0x0F)<<3) | (str[4]>>5);
key[5] = ((str[4]&0x1F)<<2) | (str[5]>>6);
key[6] = ((str[5]&0x3F)<<1) | (str[6]>>7);
key[7] = str[6]&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...)