Debian Codegraph @

modules/crypto/rawmd5.c

raw
1 /*
2 * Copyright (c) 2009 Atheme Development Group
3 * Rights to this code are as documented in doc/LICENSE.
4 *
5 * Raw MD5 password encryption, as used by e.g. Anope 1.8.
6 * Hash functions are not designed to encrypt passwords directly,
7 * but we need this to convert some Anope databases.
8 */
9
10 #include "atheme.h"
11
12 DECLARE_MODULE_V1
13 (
14 "crypto/rawmd5", false, _modinit, _moddeinit,
15 PACKAGE_STRING,
16 VENDOR_STRING
17 );
18
19 #define RAWMD5_PREFIX "$rawmd5$"
20
21 static const char *rawmd5_crypt_string(const char *key, const char *salt)
22 {
23 static char output[2 * 16 + sizeof(RAWMD5_PREFIX)];
24 md5_state_t ctx;
25 unsigned char digest[16];
26 int i;
27
28 md5_init(&ctx);
29 md5_append(&ctx, (const unsigned char *)key, strlen(key));
30 md5_finish(&ctx, digest);
31
32 strcpy(output, RAWMD5_PREFIX);
33 for (i = 0; i < 16; i++)
34 sprintf(output + sizeof(RAWMD5_PREFIX) - 1 + i * 2, "%02x",
35 255 & digest[i]);
36
37 return output;
38 }
39
40 static crypt_impl_t rawmd5_crypt_impl = {
41 .id = "rawmd5",
42 .crypt = &rawmd5_crypt_string,
43 };
44
45 void _modinit(module_t *m)
46 {
47 crypt_register(&rawmd5_crypt_impl);
48 }
49
50 void _moddeinit(module_unload_intent_t intent)
51 {
52 crypt_unregister(&rawmd5_crypt_impl);
53 }
54
55 /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
56 * vim:ts=8
57 * vim:sw=8
58 * vim:noexpandtab
59 */