--- /dev/null
+/* 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;
+}
--- /dev/null
+/* 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