From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,699b74a173da2862 X-Google-Attributes: gidfee84,public X-Google-ArrivalTime: 1994-10-05 13:24:59 PST Newsgroups: comp.unix.osf.osf1 Path: bga.com!news.sprintlink.net!howland.reston.ans.net!swiss.ans.net!news.dfn.de!Germany.EU.net!EU.net!uknet!comlab.ox.ac.uk!sable.ox.ac.uk!mbeattie From: mbeattie@sable.ox.ac.uk (Malcolm Beattie) Subject: Re: OSF/1 3.0 Prot. Password Encryption Message-ID: <1994Oct5.165507.27227@inca.comlab.ox.ac.uk> Organization: Oxford University Computing Service, 13 Banbury Rd, Oxford, UK References: <36bsmq$37n@portal.gmu.edu> <36edl3$q02@chaos.dac.neu.edu> Date: Wed, 5 Oct 94 16:55:07 BST In article <36edl3$q02@chaos.dac.neu.edu>, David Brady wrote: >Richard L Jackson Jr (rjackson@mason1.gmu.edu) wrote: > >: database appears to fail for passwords that are over 8 characters. The >: limited documentation in the man pages and /usr/include/*.h files >: indicate the encrypted password is generated in segments. WHAT IS THE >: ACTUAL SCHEME DEC USES? > > If you want to use the 24-character encryptions, use the crypt16() call. > > Then, in the user's tcb entry, put in the field u_oldcrypt#1, so that > the password-checking routine will know what you're using a > 24-character length encryption. > > I know it's possible to get even longer encryptions, but I can't > remember how to do it. There's a dreadful lack of documentation on all of this stuff. I've managed to figure out most of it, though, from staring at include files and trial and error. If what you're really after is how to validate logins for daemons such as imap, pop, wu-ftpd and so on then the "proper" interface is via set_auth_parameters, sia_ses_init, sia_ses_authent (to check the password) and sia_ses_estab (to check whether the user is allowed to log in--account locks, expiry and so on). There's also sia_ses_launch which does the appropriate setting of uid, gid and so on but that's usually less useful for daemons which already have code to do that. I posted my patches to pop and imap here yesterday and inspection of that may help. If DEC don't document this stuff soon, I suppose I could put together something and post it here when I have time. Back to the actual question: DEC's algorithm for encrypting passwords. The (undocumented) function which actually lets you do this directly is called bigcrypt in libsecurity.so. Here's an example program: #include #include int main(int argc, char **argv) { char *key; if (argc != 3) { fprintf(stderr, "Usage: bigcrypt salt key\n"); exit(2); } key = argv[2]; /* Don't want the audit log to include what we're crypting */ argv[2] = 0; set_auth_parameters(2, argv); puts(bigcrypt(key, argv[1])); exit(0); } Compile this with cc -o bigcrypt bigcrypt.c -lsecurity We discovered this sometime after a colleague, Paul Leyland (pcl@ox.ac.uk), discovered what the actual algorithm was and rolled-his-own. /usr/include/prot.h says: /* * The size of the ciphertext is the salt at the * beginning, a series of 11-character segments produced by * each call to crypt(), and the trailing end-of-string character. * Each 11-character segment uses the a newly computed salt based * on the previous encrypted value. */ The only thing missing is how it computes the salt for each successive block of 8 characters. In fact, it's simple. It splits the text to be bigcrypted into 8 character chunks. It takes the salt and the first chunk of 8 bits and does crypt(salt, chunk1) using standard crypt. (Notice that this means that passwords with 8 characters or fewer will "work" with ordinary crypt, although not crypt16 which is different again). The first 2 characters of crypt1 are just the salt that you fed in, of course. The following two characters are taken to be the salt for the next block of 8 plaintext characters and crypt is done again. Let crypt'(salt, text) be what the usual crypt returns but omitting the first two characters (which are just the original salt). Then the plaintext is split up into 8 byte blocks, text1, text2, ... Taking the salt required for the whole thing, we do crypt1 = crypt'(salt, text1); salt1 = first_two_chars(crypt1); crypt2 = crypt'(salt1, crypt1); salt2 = first_two_chars(crypt2); crypt3 = crypt'(salt2, crypt2); and so on. The result of the whole process is the concatenaation of salt, crypt1, crypt2, crypt3, ... A concrete example: sable% ./bigcrypt ab 12345678abcdefgh (*) ab1iBa.N.U2C6JI06ws2gRbQ An ordinary crypt of the first 8 bytes (which bigcrypt does identically): sable% ./bigcrypt ab 12345678 ab1iBa.N.U2C6 ^^ original salt ^^ used as salt to next round (1) ^^^^^^^^^^^ used as first 11 bytes of cipher text (ignoring salt) sable% ./bigcrypt 1i abcdefgh 1iJI06ws2gRbQ (2) ^^^^^^^^^^^ used as next 11 bytes of cipher text If you look at the result of bigcrypt above in (*) you'll see it's the concatenation of the original salt (ab) then (1) and (2). --Malcolm -- Malcolm Beattie (note new address) Oxford University Computing Services "Widget. It's got a widget. A lovely widget. A widget it has got." --Jack Dee