Debian Codegraph @

modules/crypto/rawsha1.c

raw
1 /*
2 * Copyright (c) 2009 Atheme Development Group
3 * Rights to this code are as documented in doc/LICENSE.
4 *
5 * Raw SHA1 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 #ifdef HAVE_OPENSSL
13
14 #include <openssl/sha.h>
15
16 DECLARE_MODULE_V1
17 (
18 "crypto/rawsha1", false, _modinit, _moddeinit,
19 PACKAGE_STRING,
20 VENDOR_STRING
21 );
22
23 #define RAWSHA1_PREFIX "$rawsha1$"
24
25 static const char *rawsha1_crypt_string(const char *key, const char *salt)
26 {
27 static char output[2 * SHA_DIGEST_LENGTH + sizeof(RAWSHA1_PREFIX)];
28 SHA_CTX ctx;
29 unsigned char digest[SHA_DIGEST_LENGTH];
30 int i;
31
32 SHA1_Init(&ctx);
33 SHA1_Update(&ctx, key, strlen(key));
34 SHA1_Final(digest, &ctx);
35
36 strcpy(output, RAWSHA1_PREFIX);
37 for (i = 0; i < SHA_DIGEST_LENGTH; i++)
38 sprintf(output + sizeof(RAWSHA1_PREFIX) - 1 + i * 2, "%02x",
39 255 & digest[i]);
40
41 return output;
42 }
43
44 static crypt_impl_t rawsha1_crypt_impl = {
45 .id = "rawsha1",
46 .crypt = &rawsha1_crypt_string,
47 };
48
49 void _modinit(module_t *m)
50 {
51 crypt_register(&rawsha1_crypt_impl);
52 }
53
54 void _moddeinit(module_unload_intent_t intent)
55 {
56 crypt_unregister(&rawsha1_crypt_impl);
57 }
58
59 #endif /* HAVE_OPENSSL */
60
61 /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
62 * vim:ts=8
63 * vim:sw=8
64 * vim:noexpandtab
65 */