added MD5 Hash generator
authorpk910 <philipp@zoelle1.de>
Wed, 16 Jul 2014 22:05:56 +0000 (00:05 +0200)
committerpk910 <philipp@zoelle1.de>
Wed, 16 Jul 2014 22:05:56 +0000 (00:05 +0200)
src/Makefile.am
src/crypt_md5.c [new file with mode: 0644]
src/crypt_md5.h [new file with mode: 0644]

index 88b6ac321aa6db9e2de0f1a27cf98a041a0dbc2b..e258ea28fa8abd4c73ecbd7c1d10c1ba5860b5ff 100644 (file)
@@ -16,6 +16,7 @@ nextircd_SOURCES = \
        crypt_base64.c \
        crypt_keypacker.c \
        crypt_rsa.c \
+       crypt_md5.c \
        ircd_config.c \
        ircd_sock.c \
        ircd_client.c \
diff --git a/src/crypt_md5.c b/src/crypt_md5.c
new file mode 100644 (file)
index 0000000..e061cc9
--- /dev/null
@@ -0,0 +1,51 @@
+/* crypt_md5.c - NextIRCd
+ * Copyright (C) 2012-2013  Philipp Kreil (pk910)
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License 
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. 
+ */
+
+#include "crypt_md5.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#if defined(__APPLE__)
+#define COMMON_DIGEST_FOR_OPENSSL
+#include <CommonCrypto/CommonDigest.h>
+#define SHA1 CC_SHA1
+#else
+#include <openssl/md5.h>
+#endif
+
+unsigned char *crypt_md5_bin(const char *str, int strlen) {
+       int n;
+       MD5_CTX c;
+       unsigned char *digest = (char*)malloc(17);
+       
+       MD5_Init(&c);
+       
+       while (strlen > 0) {
+               if (strlen > 512) {
+                       MD5_Update(&c, str, 512);
+               } else {
+                       MD5_Update(&c, str, strlen);
+               }
+               strlen -= 512;
+               str += 512;
+       }
+       
+       MD5_Final(digest, &c);
+       digest[16] = 0;
+       
+       return digest;
+}
diff --git a/src/crypt_md5.h b/src/crypt_md5.h
new file mode 100644 (file)
index 0000000..e926e37
--- /dev/null
@@ -0,0 +1,23 @@
+/* crypt_md5.h - NextIRCd
+ * Copyright (C) 2012-2013  Philipp Kreil (pk910)
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License 
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. 
+ */
+
+#ifndef _crypt_md5_h
+#define _crypt_md5_h
+
+unsigned char *crypt_md5_bin(const char *str, int strlen);
+
+#endif