/** * sorservices.C: Sorcery services crypto backend. * * Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team * Rights to this code are as documented in COPYING. * * * Portions of this file were derived from sources bearing the following license: * Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team * Rights to this code are as documented in doc/pod/license.pod. * * $Id: sorservices.C,v 1.8 2007/09/22 14:27:27 pippijn Exp $ */ #include "atheme.h" #include #include #include static char const rcsid[] = "$Id: sorservices.C,v 1.8 2007/09/22 14:27:27 pippijn Exp $"; namespace crypto { namespace impl { static void md5_buffer (char const * const passwd, int len, char *target) { struct MD5Context ctx; MD5Init (&ctx); MD5Update (&ctx, (unsigned char *) passwd, len); MD5Final ((unsigned char *) target, &ctx); } static char * md5_password (char const * const pw) { static char md5buffer[16 + 1]; /* unsigned static char tresult[512]; */ /* int cnt = 0, o = 0; */ if (!pw) { static char buf[16] = ""; buf[0] = '\0'; return buf; } md5_buffer (pw, strlen (pw), md5buffer); return md5buffer; } } // namespace impl struct sorservices : handler { virtual char const *crypt (char const * const key, char const * const salt); }; char const * sorservices::crypt (char const * const key, char const * const salt) { static char outbuf[BUFSIZE], buf[BUFSIZE]; base64::encoder enc; enc.encode (impl::md5_password (key), 16, buf); snprintf (outbuf, BUFSIZE, "$%s", buf); return outbuf; } } // namespace crypto #define FACREG_TYPE crypto::sorservices #define FACREG_TYPE_NAME "sorservices" #define FACREG_INTERFACE_TYPE crypto::handler #include