From 94f13fd523ed67aef66be996df03f76a83a4ef5d Mon Sep 17 00:00:00 2001 From: pk910 Date: Thu, 17 Jul 2014 00:05:56 +0200 Subject: [PATCH] added MD5 Hash generator --- src/Makefile.am | 1 + src/crypt_md5.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ src/crypt_md5.h | 23 ++++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 src/crypt_md5.c create mode 100644 src/crypt_md5.h diff --git a/src/Makefile.am b/src/Makefile.am index 88b6ac3..e258ea2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 index 0000000..e061cc9 --- /dev/null +++ b/src/crypt_md5.c @@ -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 . + */ + +#include "crypt_md5.h" +#include +#include +#include +#if defined(__APPLE__) +#define COMMON_DIGEST_FOR_OPENSSL +#include +#define SHA1 CC_SHA1 +#else +#include +#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 index 0000000..e926e37 --- /dev/null +++ b/src/crypt_md5.h @@ -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 . + */ + +#ifndef _crypt_md5_h +#define _crypt_md5_h + +unsigned char *crypt_md5_bin(const char *str, int strlen); + +#endif -- 2.20.1