summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/chanserv.c20
-rw-r--r--src/config.c4
-rw-r--r--src/core/cs_getpass.c28
-rw-r--r--src/core/cs_identify.c5
-rw-r--r--src/core/cs_register.c25
-rw-r--r--src/core/cs_sendpass.c68
-rw-r--r--src/core/cs_set.c14
-rw-r--r--src/core/enc_md5.c422
-rw-r--r--src/core/enc_none.c76
-rw-r--r--src/core/enc_old.c451
-rw-r--r--src/core/ns_getpass.c23
-rw-r--r--src/core/ns_ghost.c2
-rw-r--r--src/core/ns_group.c2
-rw-r--r--src/core/ns_identify.c2
-rw-r--r--src/core/ns_recover.c2
-rw-r--r--src/core/ns_register.c28
-rw-r--r--src/core/ns_release.c2
-rw-r--r--src/core/ns_saset.c21
-rw-r--r--src/core/ns_sendpass.c66
-rw-r--r--src/core/ns_set.c17
-rw-r--r--src/core/os_modlist.c22
-rw-r--r--src/encrypt.c457
-rw-r--r--src/init.c4
-rw-r--r--src/main.c3
-rw-r--r--src/misc.c21
-rw-r--r--src/modules.c47
-rw-r--r--src/mysql.c76
-rw-r--r--src/nickserv.c39
-rw-r--r--src/protocol/bahamut.c5
-rw-r--r--src/protocol/charybdis.c4
-rw-r--r--src/protocol/dreamforge.c5
-rw-r--r--src/protocol/hybrid.c4
-rw-r--r--src/protocol/inspircd.c4
-rw-r--r--src/protocol/plexus2.c4
-rw-r--r--src/protocol/plexus3.c4
-rw-r--r--src/protocol/ptlink.c6
-rw-r--r--src/protocol/rageircd.c4
-rw-r--r--src/protocol/ratbox.c5
-rw-r--r--src/protocol/shadowircd.c4
-rw-r--r--src/protocol/solidircd.c6
-rw-r--r--src/protocol/ultimate2.c4
-rw-r--r--src/protocol/ultimate3.c5
-rw-r--r--src/protocol/unreal31.c4
-rw-r--r--src/protocol/unreal32.c4
-rw-r--r--src/protocol/viagra.c4
45 files changed, 1323 insertions, 700 deletions
diff --git a/src/chanserv.c b/src/chanserv.c
index 1b05f8202..908cb1e69 100644
--- a/src/chanserv.c
+++ b/src/chanserv.c
@@ -496,25 +496,7 @@ void load_cs_dbase(void)
SAFE(read_int32(&tmp32, f));
ci->last_topic_time = tmp32;
SAFE(read_int32(&ci->flags, f));
-#ifdef USE_ENCRYPTION
- if (!(ci->flags & (CI_ENCRYPTEDPW | CI_VERBOTEN))) {
- if (debug)
- alog("debug: %s: encrypting password for %s on load",
- s_ChanServ, ci->name);
- if (encrypt_in_place(ci->founderpass, PASSMAX) < 0)
- fatal("%s: load database: Can't encrypt %s password!",
- s_ChanServ, ci->name);
- ci->flags |= CI_ENCRYPTEDPW;
- }
-#else
- if (ci->flags & CI_ENCRYPTEDPW) {
- /* Bail: it makes no sense to continue with encrypted
- * passwords, since we won't be able to verify them */
- fatal("%s: load database: password for %s encrypted "
- "but encryption disabled, aborting",
- s_ChanServ, ci->name);
- }
-#endif
+
/* Leaveops cleanup */
if (ver <= 13 && (ci->flags & 0x00000020))
ci->flags &= ~0x00000020;
diff --git a/src/config.c b/src/config.c
index 50ffab865..b6728f0ca 100644
--- a/src/config.c
+++ b/src/config.c
@@ -19,7 +19,7 @@
/* Configurable variables: */
char *IRCDModule;
-
+char *EncModule;
char *RemoteServer;
int RemotePort;
char *RemotePassword;
@@ -445,6 +445,7 @@ Directive directives[] = {
{{PARAM_STRING, PARAM_RELOAD, &DefConAkillReason}}},
{"DefConOffMessage",
{{PARAM_STRING, PARAM_RELOAD, &DefConOffMessage}}},
+ {"EncModule", {{PARAM_STRING, 0, &EncModule}}},
{"ExceptionDB", {{PARAM_STRING, PARAM_RELOAD, &ExceptionDBName}}},
{"ExceptionExpiry", {{PARAM_TIME, PARAM_RELOAD, &ExceptionExpiry}}},
{"ExpireTimeout", {{PARAM_TIME, PARAM_RELOAD, &ExpireTimeout}}},
@@ -968,6 +969,7 @@ int read_config(int reload)
}
CHECK(IRCDModule);
+ CHECK(EncModule);
CHECK(NetworkName);
if (!reload) {
diff --git a/src/core/cs_getpass.c b/src/core/cs_getpass.c
index ef9ea3cbb..fd1f241e1 100644
--- a/src/core/cs_getpass.c
+++ b/src/core/cs_getpass.c
@@ -38,11 +38,8 @@ int AnopeInit(int argc, char **argv)
moduleAddCommand(CHANSERV, c, MOD_UNIQUE);
moduleSetChanHelp(myChanServHelp);
-#ifdef USE_ENCRYPTION
- return MOD_STOP;
-#else
+
return MOD_CONT;
-#endif
}
/**
@@ -75,6 +72,7 @@ void myChanServHelp(User * u)
int do_getpass(User * u)
{
char *chan = strtok(NULL, " ");
+ char tmp_pass[PASSMAX];
ChannelInfo *ci;
if (!chan) {
@@ -86,15 +84,19 @@ int do_getpass(User * u)
} else if (CSRestrictGetPass && !is_services_root(u)) {
notice_lang(s_ChanServ, u, PERMISSION_DENIED);
} else {
- alog("%s: %s!%s@%s used GETPASS on %s",
- s_ChanServ, u->nick, u->username, u->host, ci->name);
- if (WallGetpass) {
- anope_cmd_global(s_ChanServ,
- "\2%s\2 used GETPASS on channel \2%s\2",
- u->nick, chan);
- }
- notice_lang(s_ChanServ, u, CHAN_GETPASS_PASSWORD_IS,
- chan, ci->founderpass);
+ if(enc_decrypt(ci->founderpass,tmp_pass,PASSMAX)==1) {
+ alog("%s: %s!%s@%s used GETPASS on %s",
+ s_ChanServ, u->nick, u->username, u->host, ci->name);
+ if (WallGetpass) {
+ anope_cmd_global(s_ChanServ,
+ "\2%s\2 used GETPASS on channel \2%s\2",
+ u->nick, chan);
+ }
+ notice_lang(s_ChanServ, u, CHAN_GETPASS_PASSWORD_IS,
+ chan, ci->founderpass);
+ } else {
+ notice_lang(s_ChanServ, u, CHAN_GETPASS_UNAVAILABLE);
+ }
}
return MOD_CONT;
}
diff --git a/src/core/cs_identify.c b/src/core/cs_identify.c
index 33091c01a..6979c0f08 100644
--- a/src/core/cs_identify.c
+++ b/src/core/cs_identify.c
@@ -17,9 +17,6 @@
int do_identify(User * u);
void myChanServHelp(User * u);
-#ifdef _WIN32
-extern MDE int check_password(const char *plaintext, const char *password);
-#endif
/**
* Create the command, and tell anope about it.
@@ -92,7 +89,7 @@ int do_identify(User * u)
} else {
int res;
- if ((res = check_password(pass, ci->founderpass)) == 1) {
+ if ((res = enc_check_password(pass, ci->founderpass)) == 1) {
if (!is_identified(u, ci)) {
uc = scalloc(sizeof(*uc), 1);
uc->next = u->founder_chans;
diff --git a/src/core/cs_register.c b/src/core/cs_register.c
index d480f03c0..6d0167a1d 100644
--- a/src/core/cs_register.c
+++ b/src/core/cs_register.c
@@ -75,9 +75,8 @@ int do_register(User * u)
ChannelInfo *ci;
struct u_chaninfolist *uc;
int is_servadmin = is_services_admin(u);
-#ifdef USE_ENCRYPTION
char founderpass[PASSMAX + 1];
-#endif
+ char tmp_pass[PASSMAX];
if (readonly) {
notice_lang(s_ChanServ, u, CHAN_REGISTER_DISABLED);
@@ -130,15 +129,12 @@ int do_register(User * u)
alog("%s: makechan() failed for REGISTER %s", s_ChanServ, chan);
notice_lang(s_ChanServ, u, CHAN_REGISTRATION_FAILED);
-#ifdef USE_ENCRYPTION
} else if (strscpy(founderpass, pass, PASSMAX + 1),
- encrypt_in_place(founderpass, PASSMAX) < 0) {
+ enc_encrypt_in_place(founderpass, PASSMAX) < 0) {
alog("%s: Couldn't encrypt password for %s (REGISTER)",
s_ChanServ, chan);
notice_lang(s_ChanServ, u, CHAN_REGISTRATION_FAILED);
delchan(ci);
-#endif
-
} else {
c->ci = ci;
ci->c = c;
@@ -148,17 +144,12 @@ int do_register(User * u)
ci->memos.memomax = MSMaxMemos;
ci->last_used = ci->time_registered;
ci->founder = nc;
-#ifdef USE_ENCRYPTION
if (strlen(pass) > PASSMAX)
notice_lang(s_ChanServ, u, PASSWORD_TRUNCATED, PASSMAX);
memset(pass, 0, strlen(pass));
memcpy(ci->founderpass, founderpass, PASSMAX);
- ci->flags |= CI_ENCRYPTEDPW;
-#else
- if (strlen(pass) > PASSMAX - 1) /* -1 for null byte */
- notice_lang(s_ChanServ, u, PASSWORD_TRUNCATED, PASSMAX - 1);
- strscpy(ci->founderpass, pass, PASSMAX);
-#endif
+// ci->flags |= CI_ENCRYPTEDPW;
+//
ci->desc = sstrdup(desc);
if (c->topic) {
ci->last_topic = sstrdup(c->topic);
@@ -174,9 +165,11 @@ int do_register(User * u)
alog("%s: Channel '%s' registered by %s!%s@%s", s_ChanServ, chan,
u->nick, u->username, u->host);
notice_lang(s_ChanServ, u, CHAN_REGISTERED, chan, u->nick);
-#ifndef USE_ENCRYPTION
- notice_lang(s_ChanServ, u, CHAN_PASSWORD_IS, ci->founderpass);
-#endif
+
+ if(enc_decrypt(ci->founderpass,tmp_pass,PASSMAX) == 1) {
+ notice_lang(s_ChanServ, u, CHAN_PASSWORD_IS, ci->founderpass);
+ }
+
uc = scalloc(sizeof(*uc), 1);
uc->next = u->founder_chans;
uc->prev = NULL;
diff --git a/src/core/cs_sendpass.c b/src/core/cs_sendpass.c
index 61eb70524..ee31287df 100644
--- a/src/core/cs_sendpass.c
+++ b/src/core/cs_sendpass.c
@@ -37,15 +37,12 @@ int AnopeInit(int argc, char **argv)
moduleAddCommand(CHANSERV, c, MOD_UNIQUE);
moduleSetChanHelp(myChanServHelp);
-#ifdef USE_ENCRYPTION
- return MOD_STOP;
-#else
+
if (UseMail) {
return MOD_CONT;
} else {
return MOD_STOP;
}
-#endif
}
/**
@@ -89,35 +86,40 @@ int do_sendpass(User * u)
notice_lang(s_ChanServ, u, CHAN_X_FORBIDDEN, chan);
} else {
char buf[BUFSIZE];
- MailInfo *mail;
-
- snprintf(buf, sizeof(buf),
- getstring2(founder, CHAN_SENDPASS_SUBJECT), ci->name);
- mail = MailBegin(u, founder, buf, s_ChanServ);
- if (!mail)
- return MOD_CONT;
-
- fprintf(mail->pipe, getstring2(founder, CHAN_SENDPASS_HEAD));
- fprintf(mail->pipe, "\n\n");
- fprintf(mail->pipe, getstring2(founder, CHAN_SENDPASS_LINE_1),
- ci->name);
- fprintf(mail->pipe, "\n\n");
- fprintf(mail->pipe, getstring2(founder, CHAN_SENDPASS_LINE_2),
- ci->founderpass);
- fprintf(mail->pipe, "\n\n");
- fprintf(mail->pipe, getstring2(founder, CHAN_SENDPASS_LINE_3));
- fprintf(mail->pipe, "\n\n");
- fprintf(mail->pipe, getstring2(founder, CHAN_SENDPASS_LINE_4));
- fprintf(mail->pipe, "\n\n");
- fprintf(mail->pipe, getstring2(founder, CHAN_SENDPASS_LINE_5),
- NetworkName);
- fprintf(mail->pipe, "\n.\n");
-
- MailEnd(mail);
-
- alog("%s: %s!%s@%s used SENDPASS on %s", s_ChanServ, u->nick,
- u->username, u->host, chan);
- notice_lang(s_ChanServ, u, CHAN_SENDPASS_OK, chan);
+ char tmp_pass[PASSMAX];
+ if(enc_decrypt(ci->founderpass,tmp_pass,PASSMAX)==1) {
+ MailInfo *mail;
+
+ snprintf(buf, sizeof(buf),
+ getstring2(founder, CHAN_SENDPASS_SUBJECT), ci->name);
+ mail = MailBegin(u, founder, buf, s_ChanServ);
+ if (!mail)
+ return MOD_CONT;
+
+ fprintf(mail->pipe, getstring2(founder, CHAN_SENDPASS_HEAD));
+ fprintf(mail->pipe, "\n\n");
+ fprintf(mail->pipe, getstring2(founder, CHAN_SENDPASS_LINE_1),
+ ci->name);
+ fprintf(mail->pipe, "\n\n");
+ fprintf(mail->pipe, getstring2(founder, CHAN_SENDPASS_LINE_2),
+ tmp_pass);
+ fprintf(mail->pipe, "\n\n");
+ fprintf(mail->pipe, getstring2(founder, CHAN_SENDPASS_LINE_3));
+ fprintf(mail->pipe, "\n\n");
+ fprintf(mail->pipe, getstring2(founder, CHAN_SENDPASS_LINE_4));
+ fprintf(mail->pipe, "\n\n");
+ fprintf(mail->pipe, getstring2(founder, CHAN_SENDPASS_LINE_5),
+ NetworkName);
+ fprintf(mail->pipe, "\n.\n");
+
+ MailEnd(mail);
+
+ alog("%s: %s!%s@%s used SENDPASS on %s", s_ChanServ, u->nick,
+ u->username, u->host, chan);
+ notice_lang(s_ChanServ, u, CHAN_SENDPASS_OK, chan);
+ } else {
+ notice_lang(s_ChanServ, u, CHAN_SENDPASS_UNAVAILABLE);
+ }
}
return MOD_CONT;
}
diff --git a/src/core/cs_set.c b/src/core/cs_set.c
index 15a0395be..c926ea583 100644
--- a/src/core/cs_set.c
+++ b/src/core/cs_set.c
@@ -14,9 +14,7 @@
/*************************************************************************/
#include "module.h"
-#ifdef USE_ENCRYPTION
#include "encrypt.h"
-#endif
int do_set(User * u);
int do_set_founder(User * u, ChannelInfo * ci, char *param);
@@ -368,14 +366,14 @@ int do_set_password(User * u, ChannelInfo * ci, char *param)
notice_lang(s_ChanServ, u, MORE_OBSCURE_PASSWORD);
return MOD_CONT;
}
-#ifdef USE_ENCRYPTION
+
if (len > PASSMAX) {
len = PASSMAX;
param[len] = 0;
notice_lang(s_ChanServ, u, PASSWORD_TRUNCATED, PASSMAX);
}
- if (encrypt(param, len, ci->founderpass, PASSMAX) < 0) {
+ if (enc_encrypt(param, len, ci->founderpass, PASSMAX) < 0) {
memset(param, 0, strlen(param));
alog("%s: Failed to encrypt password for %s (set)", s_ChanServ,
ci->name);
@@ -386,14 +384,6 @@ int do_set_password(User * u, ChannelInfo * ci, char *param)
memset(param, 0, strlen(param));
notice_lang(s_ChanServ, u, CHAN_PASSWORD_CHANGED, ci->name);
-#else /* !USE_ENCRYPTION */
- if (strlen(param) > PASSMAX - 1) /* -1 for null byte */
- notice_lang(s_ChanServ, u, PASSWORD_TRUNCATED, PASSMAX - 1);
- strscpy(ci->founderpass, param, PASSMAX);
- notice_lang(s_ChanServ, u, CHAN_PASSWORD_CHANGED_TO, ci->name,
- ci->founderpass);
-#endif /* USE_ENCRYPTION */
-
if (get_access(u, ci) < ACCESS_FOUNDER) {
alog("%s: %s!%s@%s set password as Services admin for %s",
s_ChanServ, u->nick, u->username, u->host, ci->name);
diff --git a/src/core/enc_md5.c b/src/core/enc_md5.c
new file mode 100644
index 000000000..411e9f2a4
--- /dev/null
+++ b/src/core/enc_md5.c
@@ -0,0 +1,422 @@
+/* Module for encryption using MD5.
+ *
+ * Modified for Anope.
+ * (C) 2003-2006 Anope Team
+ * Contact us at dev@anope.org
+ *
+ * Taken from IRC Services and is copyright (c) 1996-2002 Andrew Church.
+ * E-mail: <achurch@achurch.org>
+ * Parts written by Andrew Kempe and others.
+ * This program is free but copyrighted software; see the file COPYING for
+ * details.
+ */
+
+#include "module.h"
+
+
+/*************************************************************************/
+
+/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
+rights reserved.
+
+License to copy and use this software is granted provided that it
+is identified as the "RSA Data Security, Inc. MD5 Message-Digest
+Algorithm" in all material mentioning or referencing this software
+or this function.
+
+License is also granted to make and use derivative works provided
+that such works are identified as "derived from the RSA Data
+Security, Inc. MD5 Message-Digest Algorithm" in all material
+mentioning or referencing the derived work.
+
+RSA Data Security, Inc. makes no representations concerning either
+the merchantability of this software or the suitability of this
+software for any particular purpose. It is provided "as is"
+without express or implied warranty of any kind.
+
+These notices must be retained in any copies of any part of this
+documentation and/or software.
+ */
+
+#include <string.h>
+
+typedef unsigned int UINT4;
+
+/* MD5 context. */
+typedef struct {
+ UINT4 state[4]; /* state (ABCD) */
+ UINT4 count[2]; /* number of bits, modulo 2^64 (lsb first) */
+ unsigned char buffer[64]; /* input buffer */
+} MD5_CTX;
+
+/* MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm
+ */
+
+typedef void *POINTER;
+
+/* Constants for MD5Transform routine.
+ */
+#define S11 7
+#define S12 12
+#define S13 17
+#define S14 22
+#define S21 5
+#define S22 9
+#define S23 14
+#define S24 20
+#define S31 4
+#define S32 11
+#define S33 16
+#define S34 23
+#define S41 6
+#define S42 10
+#define S43 15
+#define S44 21
+
+void MD5Transform (UINT4 [4], unsigned char [64]);
+void Encode (unsigned char *, UINT4 *, unsigned int);
+void Decode (UINT4 *, unsigned char *, unsigned int);
+
+static unsigned char PADDING[64] = {
+ 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+};
+
+/* F, G, H and I are basic MD5 functions.
+ */
+#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
+#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
+#define H(x, y, z) ((x) ^ (y) ^ (z))
+#define I(x, y, z) ((y) ^ ((x) | (~z)))
+
+/* ROTATE_LEFT rotates x left n bits.
+ */
+#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
+
+/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
+Rotation is separate from addition to prevent recomputation.
+ */
+#define FF(a, b, c, d, x, s, ac) { \
+ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
+ (a) = ROTATE_LEFT ((a), (s)); \
+ (a) += (b); \
+ }
+#define GG(a, b, c, d, x, s, ac) { \
+ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
+ (a) = ROTATE_LEFT ((a), (s)); \
+ (a) += (b); \
+ }
+#define HH(a, b, c, d, x, s, ac) { \
+ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
+ (a) = ROTATE_LEFT ((a), (s)); \
+ (a) += (b); \
+ }
+#define II(a, b, c, d, x, s, ac) { \
+ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
+ (a) = ROTATE_LEFT ((a), (s)); \
+ (a) += (b); \
+ }
+
+/* MD5 initialization. Begins an MD5 operation, writing a new context.
+ */
+void MD5Init (context)
+MD5_CTX *context; /* context */
+{
+ context->count[0] = context->count[1] = 0;
+ /* Load magic initialization constants.
+*/
+ context->state[0] = 0x67452301;
+ context->state[1] = 0xefcdab89;
+ context->state[2] = 0x98badcfe;
+ context->state[3] = 0x10325476;
+}
+
+/* MD5 block update operation. Continues an MD5 message-digest
+ operation, processing another message block, and updating the
+ context.
+ */
+void MD5Update (context, input, inputLen)
+MD5_CTX *context; /* context */
+unsigned char *input; /* input block */
+unsigned int inputLen; /* length of input block */
+{
+ unsigned int i, index, partLen;
+
+ /* Compute number of bytes mod 64 */
+ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
+
+ /* Update number of bits */
+ if ((context->count[0] += ((UINT4)inputLen << 3))
+ < ((UINT4)inputLen << 3))
+ context->count[1]++;
+ context->count[1] += ((UINT4)inputLen >> 29);
+
+ partLen = 64 - index;
+
+ /* Transform as many times as possible.
+*/
+ if (inputLen >= partLen) {
+ memcpy
+ ((POINTER)&context->buffer[index], (POINTER)input, partLen);
+ MD5Transform (context->state, context->buffer);
+
+ for (i = partLen; i + 63 < inputLen; i += 64)
+ MD5Transform (context->state, &input[i]);
+
+ index = 0;
+ }
+ else
+ i = 0;
+
+ /* Buffer remaining input */
+ memcpy
+ ((POINTER)&context->buffer[index], (POINTER)&input[i],
+ inputLen-i);
+}
+
+/* MD5 finalization. Ends an MD5 message-digest operation, writing the
+ the message digest and zeroizing the context.
+ */
+void MD5Final (digest, context)
+unsigned char digest[16]; /* message digest */
+MD5_CTX *context; /* context */
+{
+ unsigned char bits[8];
+ unsigned int index, padLen;
+
+ /* Save number of bits */
+ Encode (bits, context->count, 8);
+
+ /* Pad out to 56 mod 64.
+*/
+ index = (unsigned int)((context->count[0] >> 3) & 0x3f);
+ padLen = (index < 56) ? (56 - index) : (120 - index);
+ MD5Update (context, PADDING, padLen);
+
+ /* Append length (before padding) */
+ MD5Update (context, bits, 8);
+ /* Store state in digest */
+ Encode (digest, context->state, 16);
+
+ /* Zeroize sensitive information.
+*/
+ memset ((POINTER)context, 0, sizeof (*context));
+}
+
+/* MD5 basic transformation. Transforms state based on block.
+ */
+void MD5Transform (state, block)
+UINT4 state[4];
+unsigned char block[64];
+{
+ UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16];
+
+ Decode (x, block, 64);
+
+ /* Round 1 */
+ FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
+ FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
+ FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
+ FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
+ FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
+ FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
+ FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
+ FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
+ FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
+ FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
+ FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
+ FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
+ FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
+ FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
+ FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
+ FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
+
+ /* Round 2 */
+ GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
+ GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
+ GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
+ GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
+ GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
+ GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */
+ GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
+ GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
+ GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
+ GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
+ GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
+ GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
+ GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
+ GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
+ GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
+ GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
+
+ /* Round 3 */
+ HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
+ HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
+ HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
+ HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
+ HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
+ HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
+ HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
+ HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
+ HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
+ HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
+ HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
+ HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */
+ HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
+ HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
+ HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
+ HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
+
+ /* Round 4 */
+ II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
+ II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
+ II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
+ II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
+ II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
+ II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
+ II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
+ II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
+ II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
+ II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
+ II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
+ II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
+ II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
+ II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
+ II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
+ II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
+
+ state[0] += a;
+ state[1] += b;
+ state[2] += c;
+ state[3] += d;
+
+ /* Zeroize sensitive information.
+*/
+ memset ((POINTER)x, 0, sizeof (x));
+}
+
+/* Encodes input (UINT4) into output (unsigned char). Assumes len is
+ a multiple of 4.
+ */
+void Encode (output, input, len)
+unsigned char *output;
+UINT4 *input;
+unsigned int len;
+{
+ unsigned int i, j;
+
+ for (i = 0, j = 0; j < len; i++, j += 4) {
+ output[j] = (unsigned char)(input[i] & 0xff);
+ output[j+1] = (unsigned char)((input[i] >> 8) & 0xff);
+ output[j+2] = (unsigned char)((input[i] >> 16) & 0xff);
+ output[j+3] = (unsigned char)((input[i] >> 24) & 0xff);
+ }
+}
+
+/* Decodes input (unsigned char) into output (UINT4). Assumes len is
+ a multiple of 4.
+ */
+void Decode (output, input, len)
+UINT4 *output;
+unsigned char *input;
+unsigned int len;
+{
+ unsigned int i, j;
+
+ for (i = 0, j = 0; j < len; i++, j += 4)
+ output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) |
+ (((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24);
+}
+
+/*************************************************************************/
+
+/* Our own high-level routines. See encrypt.h for documentation. */
+
+#define XTOI(c) ((c)>9 ? (c)-'A'+10 : (c)-'0')
+
+int md5_encrypt(const char *src, int len, char *dest, int size)
+{
+ MD5_CTX context;
+ char tmp[33];
+
+ if (size < 16)
+ return -1;
+
+ MD5Init(&context);
+ MD5Update(&context, src, len);
+ MD5Final(dest, &context);
+
+ if(debug) {
+ memset(tmp,0,33);
+ binary_to_hex(dest,tmp,16);
+ alog("enc_md5: Converted [%s] to [%s]",src,tmp);
+ }
+
+ return 0;
+}
+
+
+int md5_encrypt_in_place(char *buf, int size)
+{
+ return md5_encrypt(buf, strlen(buf), buf, size);
+}
+
+
+int md5_encrypt_check_len(int passlen, int bufsize)
+{
+ if (bufsize < 16)
+ fatal("enc_md5: md5_check_len(): buffer too small (%d)", bufsize);
+ return 0;
+}
+
+
+int md5_decrypt(const char *src, char *dest, int size)
+{
+ return 0;
+}
+
+
+int md5_check_password(const char *plaintext, const char *password)
+{
+ char buf[BUFSIZE];
+
+ if (md5_encrypt(plaintext, strlen(plaintext), buf, sizeof(buf)) < 0)
+ return -1;
+ if (memcmp(buf, password, 16) == 0)
+ return 1;
+ return 0;