source: crypting.c @ bda2975

Last change on this file since bda2975 was 7c9db24, checked in by Wilmer van der Gaast <wilmer@…>, at 2010-03-08T02:10:41Z

Replaced obsolete (useless for the current .xml files) encode/decode tools
with a few command-line options to the BitlBee binary. Type "bitlbee -x"
for more info.

  • Property mode set to 100644
File size: 3.4 KB
RevLine 
[b7d3cc34]1  /********************************************************************\
2  * BitlBee -- An IRC to other IM-networks gateway                     *
3  *                                                                    *
4  * Copyright 2002-2004 Sjoerd Hemminga and others                     *
5  \********************************************************************/
6
7/* A little bit of encryption for the users' passwords                  */
8
9/*
10  This program is free software; you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation; either version 2 of the License, or
13  (at your option) any later version.
14
15  This program is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  GNU General Public License for more details.
19
20  You should have received a copy of the GNU General Public License with
21  the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL;
22  if not, write to the Free Software Foundation, Inc., 59 Temple Place,
23  Suite 330, Boston, MA  02111-1307  USA
24*/
25
26/* [WvG] This file can also be compiled into a stand-alone program
27   which can encode/decode BitlBee account files. The main() will be
28   included if CRYPTING_MAIN is defined. Or just do "make decode" and
29   the programs will be built. */
30
[69ac78c]31#include <bitlbee.h>
[df6d1da]32#include "md5.h"
33#include "crypting.h"
[b7d3cc34]34
35/*\
36 * [SH] Do _not_ call this if it's not entirely sure that it will not cause
37 * harm to another users file, since this does not check the password for
38 * correctness.
39\*/
40
[7cad7b4]41int checkpass (const char *pass, const char *md5sum)
[1eddf6b]42{
[b7d3cc34]43        md5_state_t md5state;
44        md5_byte_t digest[16];
45        int i, j;
46        char digits[3];
47       
48        md5_init (&md5state);
49        md5_append (&md5state, (unsigned char *)pass, strlen (pass));
50        md5_finish (&md5state, digest);
51       
52        for (i = 0, j = 0; i < 16; i++, j += 2) {
53                /* Check password for correctness */
54                g_snprintf (digits, sizeof (digits), "%02x\n", digest[i]);
55               
56                if (digits[0] != md5sum[j]) return (-1);
57                if (digits[1] != md5sum[j + 1]) return (-1);
58        }
[7cad7b4]59
60        return( 0 );
[b7d3cc34]61}
62
[7cad7b4]63
[a301379c]64char *hashpass (const char *password)
65{
[b7d3cc34]66        md5_state_t md5state;
67        md5_byte_t digest[16];
68        int i;
69        char digits[3];
70        char *rv;
71       
[a301379c]72        if (password == NULL) return (NULL);
[b7d3cc34]73       
[a301379c]74        rv = g_new0 (char, 33);
[b7d3cc34]75       
76        md5_init (&md5state);
[a301379c]77        md5_append (&md5state, (const unsigned char *)password, strlen (password));
[b7d3cc34]78        md5_finish (&md5state, digest);
79       
80        for (i = 0; i < 16; i++) {
81                /* Build a hash of the pass */
82                g_snprintf (digits, sizeof (digits), "%02x", digest[i]);
83                strcat (rv, digits);
84        }
85       
86        return (rv);
87}
88
[a301379c]89char *obfucrypt (char *line, const char *password) 
90{
[b7d3cc34]91        int i, j;
92        char *rv;
93       
[a301379c]94        if (password == NULL) return (NULL);
[b7d3cc34]95       
[a301379c]96        rv = g_new0 (char, strlen (line) + 1);
[b7d3cc34]97       
98        i = j = 0;
99        while (*line) {
100                /* Encrypt/obfuscate the line, using the password */
101                if (*(signed char*)line < 0) *line = - (*line);
102               
[a301379c]103                rv[j] = *line + password[i]; /* Overflow intended */
[b7d3cc34]104               
105                line++;
[a301379c]106                if (!password[++i]) i = 0;
[b7d3cc34]107                j++;
108        }
109       
110        return (rv);
111}
112
[a301379c]113char *deobfucrypt (char *line, const char *password) 
114{
[b7d3cc34]115        int i, j;
116        char *rv;
117       
[a301379c]118        if (password == NULL) return (NULL);
[b7d3cc34]119       
[a301379c]120        rv = g_new0 (char, strlen (line) + 1);
[b7d3cc34]121       
122        i = j = 0;
123        while (*line) {
124                /* Decrypt/deobfuscate the line, using the pass */
[a301379c]125                rv[j] = *line - password[i]; /* Overflow intended */
[b7d3cc34]126               
127                line++;
[a301379c]128                if (!password[++i]) i = 0;
[b7d3cc34]129                j++;
130        }
131       
132        return (rv);
133}
Note: See TracBrowser for help on using the repository browser.