]>
Commit | Line | Data |
---|---|---|
3cf6947a CP |
1 | #include "lua.h" |
2 | #include "../lib/sha1.h" | |
3 | #include "../lib/sha2.h" | |
4 | ||
5 | static int crypto_sha1(lua_State *ps) { | |
6 | unsigned char digestbuf[20]; | |
7 | unsigned char hexbuf[sizeof(digestbuf) * 2 + 1]; | |
8 | SHA1_CTX c; | |
9 | ||
10 | char *s = (char *)lua_tostring(ps, 1); | |
11 | int len = lua_strlen(ps, 1); | |
12 | ||
13 | SHA1Init(&c); | |
14 | SHA1Update(&c, s, len); | |
15 | SHA1Final(digestbuf, &c); | |
16 | ||
17 | /* hah */ | |
18 | snprintf(hexbuf, sizeof(hexbuf), "%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x", digestbuf[0], digestbuf[1], digestbuf[2], digestbuf[3], digestbuf[4], digestbuf[5], digestbuf[6], digestbuf[7], digestbuf[8], digestbuf[9], digestbuf[10], digestbuf[11], digestbuf[12], digestbuf[13], digestbuf[14], digestbuf[15], digestbuf[16], digestbuf[17], digestbuf[18], digestbuf[19]); | |
19 | ||
20 | lua_pushstring(ps, hexbuf); | |
21 | return 1; | |
22 | } | |
23 | ||
24 | static int crypto_sha256(lua_State *ps) { | |
25 | unsigned char digestbuf[32]; | |
26 | unsigned char hexbuf[sizeof(digestbuf) * 2 + 1]; | |
27 | SHA256_CTX c; | |
28 | ||
29 | char *s = (char *)lua_tostring(ps, 1); | |
30 | int len = lua_strlen(ps, 1); | |
31 | ||
32 | SHA256_Init(&c); | |
33 | SHA256_Update(&c, s, len); | |
34 | SHA256_Final(digestbuf, &c); | |
35 | ||
36 | /* hahahaha */ | |
37 | snprintf(hexbuf, sizeof(hexbuf), "%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x", digestbuf[0], digestbuf[1], digestbuf[2], digestbuf[3], digestbuf[4], digestbuf[5], digestbuf[6], digestbuf[7], digestbuf[8], digestbuf[9], digestbuf[10], digestbuf[11], digestbuf[12], digestbuf[13], digestbuf[14], digestbuf[15], digestbuf[16], digestbuf[17], digestbuf[18], digestbuf[19], digestbuf[20], digestbuf[21], digestbuf[22], digestbuf[23], digestbuf[24], digestbuf[25], digestbuf[26], digestbuf[27], digestbuf[28], digestbuf[29], digestbuf[30], digestbuf[31]); | |
38 | ||
39 | lua_pushstring(ps, hexbuf); | |
40 | return 1; | |
41 | } | |
42 | ||
43 | static int crypto_sha384(lua_State *ps) { | |
44 | unsigned char digestbuf[48]; | |
45 | unsigned char hexbuf[sizeof(digestbuf) * 2 + 1]; | |
46 | SHA384_CTX c; | |
47 | ||
48 | char *s = (char *)lua_tostring(ps, 1); | |
49 | int len = lua_strlen(ps, 1); | |
50 | ||
51 | SHA384_Init(&c); | |
52 | SHA384_Update(&c, s, len); | |
53 | SHA384_Final(digestbuf, &c); | |
54 | ||
55 | /* hahahahahahahahaa */ | |
56 | snprintf(hexbuf, sizeof(hexbuf), "%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x", digestbuf[0], digestbuf[1], digestbuf[2], digestbuf[3], digestbuf[4], digestbuf[5], digestbuf[6], digestbuf[7], digestbuf[8], digestbuf[9], digestbuf[10], digestbuf[11], digestbuf[12], digestbuf[13], digestbuf[14], digestbuf[15], digestbuf[16], digestbuf[17], digestbuf[18], digestbuf[19], digestbuf[20], digestbuf[21], digestbuf[22], digestbuf[23], digestbuf[24], digestbuf[25], digestbuf[26], digestbuf[27], digestbuf[28], digestbuf[29], digestbuf[30], digestbuf[31], digestbuf[32], digestbuf[33], digestbuf[34], digestbuf[35], digestbuf[36], digestbuf[37], digestbuf[38], digestbuf[39], digestbuf[40], digestbuf[41], digestbuf[42], digestbuf[43], digestbuf[44], digestbuf[45], digestbuf[46], digestbuf[47]); | |
57 | ||
58 | lua_pushstring(ps, hexbuf); | |
59 | return 1; | |
60 | } | |
61 | ||
62 | static int crypto_sha512(lua_State *ps) { | |
63 | unsigned char digestbuf[64]; | |
64 | unsigned char hexbuf[sizeof(digestbuf) * 2 + 1]; | |
65 | SHA512_CTX c; | |
66 | ||
67 | char *s = (char *)lua_tostring(ps, 1); | |
68 | int len = lua_strlen(ps, 1); | |
69 | ||
70 | SHA512_Init(&c); | |
71 | SHA512_Update(&c, s, len); | |
72 | SHA512_Final(digestbuf, &c); | |
73 | ||
74 | /* MUHAHAHAHAHAHAHAHAHAHAAHAHAHAHAHAHHAHAHAAH */ | |
75 | snprintf(hexbuf, sizeof(hexbuf), "%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x", digestbuf[0], digestbuf[1], digestbuf[2], digestbuf[3], digestbuf[4], digestbuf[5], digestbuf[6], digestbuf[7], digestbuf[8], digestbuf[9], digestbuf[10], digestbuf[11], digestbuf[12], digestbuf[13], digestbuf[14], digestbuf[15], digestbuf[16], digestbuf[17], digestbuf[18], digestbuf[19], digestbuf[20], digestbuf[21], digestbuf[22], digestbuf[23], digestbuf[24], digestbuf[25], digestbuf[26], digestbuf[27], digestbuf[28], digestbuf[29], digestbuf[30], digestbuf[31], digestbuf[32], digestbuf[33], digestbuf[34], digestbuf[35], digestbuf[36], digestbuf[37], digestbuf[38], digestbuf[39], digestbuf[40], digestbuf[41], digestbuf[42], digestbuf[43], digestbuf[44], digestbuf[45], digestbuf[46], digestbuf[47], digestbuf[48], digestbuf[49], digestbuf[50], digestbuf[51], digestbuf[52], digestbuf[53], digestbuf[54], digestbuf[55], digestbuf[56], digestbuf[57], digestbuf[58], digestbuf[59], digestbuf[60], digestbuf[61], digestbuf[62], digestbuf[63]); | |
76 | ||
77 | lua_pushstring(ps, hexbuf); | |
78 | return 1; | |
79 | } | |
80 | ||
81 | void lua_registercryptocommands(lua_State *l) { | |
82 | lua_register(l, "crypto_sha1", crypto_sha1); | |
83 | lua_register(l, "crypto_sha256", crypto_sha256); | |
84 | lua_register(l, "crypto_sha384", crypto_sha384); | |
85 | lua_register(l, "crypto_sha512", crypto_sha512); | |
86 | } |