ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/modules/crypto/sorservices.C
Revision: 1.8
Committed: Sat Sep 22 14:27:27 2007 UTC (16 years, 8 months ago) by pippijn
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.7: +4 -3 lines
Log Message:
split up ermyth into ermyth-modules, libermyth (currently just ermyth-util) and ermyth-core

File Contents

# Content
1 /**
2 * sorservices.C: Sorcery services crypto backend.
3 *
4 * Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team
5 * Rights to this code are as documented in COPYING.
6 *
7 *
8 * Portions of this file were derived from sources bearing the following license:
9 * Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team
10 * Rights to this code are as documented in doc/pod/license.pod.
11 *
12 * $Id: sorservices.C,v 1.7 2007-09-16 18:54:43 pippijn Exp $
13 */
14
15 #include "atheme.h"
16 #include <ermyth/crypto.h>
17 #include <util/base64.h>
18 #include <util/md5.h>
19
20 static char const rcsid[] = "$Id: sorservices.C,v 1.7 2007-09-16 18:54:43 pippijn Exp $";
21
22 namespace crypto
23 {
24 namespace impl
25 {
26 static void
27 md5_buffer (char const * const passwd, int len, char *target)
28 {
29 struct MD5Context ctx;
30
31 MD5Init (&ctx);
32 MD5Update (&ctx, (unsigned char *) passwd, len);
33 MD5Final ((unsigned char *) target, &ctx);
34 }
35
36 static char *
37 md5_password (char const * const pw)
38 {
39 static char md5buffer[16 + 1];
40 /* unsigned static char tresult[512]; */
41 /* int cnt = 0, o = 0; */
42 if (!pw)
43 {
44 static char buf[16] = "";
45
46 buf[0] = '\0';
47 return buf;
48 }
49 md5_buffer (pw, strlen (pw), md5buffer);
50 return md5buffer;
51 }
52 } // namespace impl
53
54 struct sorservices : handler
55 {
56 virtual char const *crypt (char const * const key, char const * const salt);
57 };
58
59 char const *
60 sorservices::crypt (char const * const key, char const * const salt)
61 {
62 static char outbuf[BUFSIZE], buf[BUFSIZE];
63 base64::encoder enc;
64 enc.encode (impl::md5_password (key), 16, buf);
65
66 snprintf (outbuf, BUFSIZE, "$%s", buf);
67
68 return outbuf;
69 }
70 } // namespace crypto
71
72 #define FACREG_TYPE crypto::sorservices
73 #define FACREG_TYPE_NAME "sorservices"
74 #define FACREG_INTERFACE_TYPE crypto::handler
75 #include <ermyth/factory_reg.h>