summaryrefslogtreecommitdiff
path: root/src/skey/md5.c
diff options
context:
space:
mode:
authorPerberos <[email protected]>2011-11-06 17:13:49 -0300
committerPerberos <[email protected]>2011-11-06 17:13:49 -0300
commit13e6e4ab1290cda9426eaedfeda70f7491b6b083 (patch)
tree2b9b2e1eac4cc6a161bea6f2197de4513ff1ddf7 /src/skey/md5.c
downloadmate-terminal-13e6e4ab1290cda9426eaedfeda70f7491b6b083.tar.bz2
mate-terminal-13e6e4ab1290cda9426eaedfeda70f7491b6b083.tar.xz
initial
Diffstat (limited to 'src/skey/md5.c')
-rw-r--r--src/skey/md5.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/skey/md5.c b/src/skey/md5.c
new file mode 100644
index 0000000..9447c15
--- /dev/null
+++ b/src/skey/md5.c
@@ -0,0 +1,67 @@
+#include <config.h>
+#include <stdlib.h>
+
+#include <string.h>
+#include <glib.h>
+
+#include "skey.h"
+#include "skeyutil.h"
+#include "md5.h"
+
+int MD5Keycrunch(char *result, const char *seed, const char *passhrase)
+{
+ char *buf;
+ gsize len;
+ GChecksum *checksum;
+ guint8 digest[16];
+ gsize digest_len = sizeof (digest);
+ guint32 *results;
+
+ len = strlen(seed) + strlen(passhrase);
+ buf = (char *)g_try_malloc(len+1);
+ if (buf == NULL)
+ return -1;
+
+ strcpy(buf, seed);
+ skey_lowcase(buf);
+ strcat(buf, passhrase);
+ skey_sevenbit(buf);
+
+ checksum = g_checksum_new (G_CHECKSUM_MD5);
+ g_checksum_update (checksum, (const guchar *) buf, len);
+ g_free(buf);
+
+ g_checksum_get_digest (checksum, digest, &digest_len);
+ g_assert (digest_len == 16);
+
+ results = (guint32 *) digest;
+ results[0] ^= results[2];
+ results[1] ^= results[3];
+
+ memcpy((void *)result, (void *)results, SKEY_SIZE);
+
+ g_checksum_free (checksum);
+
+ return 0;
+}
+
+void MD5SKey(char *x)
+{
+ GChecksum *checksum;
+ guint8 digest[16];
+ gsize digest_len = sizeof (digest);
+ guint32 *results;
+
+ checksum = g_checksum_new (G_CHECKSUM_MD5);
+ g_checksum_update (checksum, (const guchar *) x, SKEY_SIZE);
+ g_checksum_get_digest (checksum, digest, &digest_len);
+ g_assert (digest_len == 16);
+
+ results = (guint32 *) digest;
+ results[0] ^= results[2];
+ results[1] ^= results[3];
+
+ memcpy((void *)x, (void *)results, SKEY_SIZE);
+
+ g_checksum_free (checksum);
+}