chiark / gitweb /
Commit 2.4.5-5 as unpacked
[inn-innduct.git] / authprogs / smbval / smbencrypt.c
1 /* 
2    Unix SMB/Netbios implementation.
3    Version 1.9.
4    SMB parameters and setup
5    Copyright (C) Andrew Tridgell 1992-1997
6    Modified by Jeremy Allison 1995.
7    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include "config.h"
24 #include "clibrary.h"
25 #include <ctype.h>
26
27 #include "smblib-priv.h"
28
29 typedef unsigned char uchar;
30
31 void strupper(char *s);
32
33 /*
34    This implements the X/Open SMB password encryption
35    It takes a password, a 8 byte "crypt key" and puts 24 bytes of 
36    encrypted password into p24 */
37 void SMBencrypt(uchar *passwd, uchar *c8, uchar *p24)
38 {
39   uchar p14[15], p21[21];
40
41   memset(p21,'\0',21);
42   memset(p14,'\0',14);
43   strlcpy((char *) p14, (char *) passwd, sizeof(p14));
44
45   strupper((char *)p14);
46   E_P16(p14, p21); 
47   E_P24(p21, c8, p24);
48 }
49
50 void strupper(char *s)
51 {
52   while (*s)
53   {
54     {
55       if (CTYPE(islower, *s))
56         *s = toupper(*s);
57       s++;
58     }
59   }
60 }