mirror of
https://github.com/3proxy/3proxy.git
synced 2026-09-29 16:55:51 +08:00
Compare commits
No commits in common. "c893e866bd7d929013a4b86005da5ff534f42964" and "de5acb2abd4463346f7da581dccb505014ee3229" have entirely different histories.
c893e866bd
...
de5acb2abd
72
.github/workflows/build-win-msys2-ucrt64.yml
vendored
72
.github/workflows/build-win-msys2-ucrt64.yml
vendored
@ -1,72 +0,0 @@
|
||||
name: Build 3proxy with MSYS2 UCRT64
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
ci:
|
||||
name: "msys2-ucrt64"
|
||||
runs-on: windows-2022
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
- name: Setup MSYS2 (UCRT64)
|
||||
uses: msys2/setup-msys2@v2
|
||||
with:
|
||||
msystem: UCRT64
|
||||
update: true
|
||||
install: >-
|
||||
make
|
||||
mingw-w64-ucrt-x86_64-gcc
|
||||
mingw-w64-ucrt-x86_64-pcre2
|
||||
mingw-w64-ucrt-x86_64-openssl
|
||||
mingw-w64-ucrt-x86_64-zlib
|
||||
- name: set date
|
||||
shell: pwsh
|
||||
run: |
|
||||
$NOW = Get-Date -Format "yyMMddHHmmss"
|
||||
$RELEASE = Get-Content -Path "RELEASE" -Raw
|
||||
echo "NOW=$NOW" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
|
||||
echo "RELEASE=$RELEASE" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
|
||||
- name: make Windows (Makefile.win)
|
||||
shell: msys2 {0}
|
||||
env:
|
||||
LIBSTATIC: 'true'
|
||||
run: make -f Makefile.win
|
||||
- name: make dist dir
|
||||
shell: cmd
|
||||
run: |
|
||||
mkdir dist
|
||||
mkdir dist\3proxy
|
||||
mkdir dist\3proxy\bin
|
||||
mkdir dist\3proxy\cfg
|
||||
mkdir dist\3proxy\cfg\sql
|
||||
mkdir dist\3proxy\doc
|
||||
mkdir dist\3proxy\doc\ru
|
||||
mkdir dist\3proxy\doc\html
|
||||
mkdir dist\3proxy\doc\html\plugins
|
||||
mkdir dist\3proxy\doc\html\man5
|
||||
mkdir dist\3proxy\doc\html\man8
|
||||
mkdir dist\3proxy\doc\html\devel
|
||||
copy bin\3proxy.exe dist\3proxy\bin\
|
||||
copy bin\*.dll dist\3proxy\bin\
|
||||
copy bin\3proxy_crypt.exe dist\3proxy\bin\
|
||||
copy cfg\*.* dist\3proxy\cfg\
|
||||
copy cfg\sql\*.* dist\3proxy\cfg\sql\
|
||||
copy doc\ru\*.* dist\3proxy\doc\ru\
|
||||
copy doc\html\*.* dist\3proxy\doc\html\
|
||||
copy doc\html\plugins\*.* dist\3proxy\doc\html\plugins\
|
||||
copy doc\html\man8\*.* dist\3proxy\doc\html\man8\
|
||||
copy doc\html\man5\*.* dist\3proxy\doc\html\man5\
|
||||
copy doc\html\devel\*.* dist\3proxy\doc\html\devel\
|
||||
copy copying dist\3proxy\
|
||||
copy authors dist\3proxy\
|
||||
copy README.md dist\3proxy\
|
||||
copy rus.3ps dist\3proxy\
|
||||
- name: Get artifact
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: "3proxy-${{ env.RELEASE }}-msys2-ucrt64"
|
||||
path: dist/
|
||||
@ -350,14 +350,6 @@ target_include_directories(common_obj PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
|
||||
add_library(base64_obj OBJECT src/base64.c)
|
||||
target_include_directories(base64_obj PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
|
||||
|
||||
# mdhash object library (MD4/MD5: CAPI on Windows, bundled Solar Designer MD4/MD5 elsewhere)
|
||||
if(WIN32)
|
||||
add_library(mdhash_obj OBJECT src/mdhash.c)
|
||||
else()
|
||||
add_library(mdhash_obj OBJECT src/mdhash.c src/libs/md4.c src/libs/md5.c)
|
||||
endif()
|
||||
target_include_directories(mdhash_obj PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
|
||||
|
||||
# ============================================================================
|
||||
# Object libraries for 3proxy (compiled WITHOUT WITHMAIN)
|
||||
# These are used by the main 3proxy executable
|
||||
@ -419,7 +411,6 @@ add_executable(3proxy
|
||||
$<TARGET_OBJECTS:common_obj>
|
||||
$<TARGET_OBJECTS:udpsockmap_obj>
|
||||
$<TARGET_OBJECTS:base64_obj>
|
||||
$<TARGET_OBJECTS:mdhash_obj>
|
||||
$<TARGET_OBJECTS:ftp_obj>
|
||||
$<TARGET_OBJECTS:3proxy_crypt_obj>
|
||||
)
|
||||
@ -529,7 +520,6 @@ endif()
|
||||
add_executable(3proxy_crypt
|
||||
src/3proxy_crypt.c
|
||||
$<TARGET_OBJECTS:base64_obj>
|
||||
$<TARGET_OBJECTS:mdhash_obj>
|
||||
)
|
||||
target_sources(3proxy_crypt PRIVATE ${MD_SOURCES})
|
||||
target_compile_definitions(3proxy_crypt PRIVATE WITHMAIN)
|
||||
@ -671,18 +661,16 @@ foreach(PROXY_NAME proxy socks pop3p smtpp ftppr tcppm udppm tlspr)
|
||||
endforeach()
|
||||
|
||||
# Install plugins
|
||||
# Use install(DIRECTORY ... FILES_MATCHING) so the glob resolves at install
|
||||
# time, after plugin targets have been built. A configure-time file(GLOB)
|
||||
# would run before any plugin exists and install nothing.
|
||||
file(GLOB PLUGINFILES "${PLUGIN_OUTPUT_DIR}/*${PLUGIN_SUFFIX}")
|
||||
if(WIN32)
|
||||
install(DIRECTORY ${PLUGIN_OUTPUT_DIR}/
|
||||
install(FILES
|
||||
${PLUGINFILES}
|
||||
DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
FILES_MATCHING PATTERN "*${PLUGIN_SUFFIX}"
|
||||
)
|
||||
else()
|
||||
install(DIRECTORY ${PLUGIN_OUTPUT_DIR}/
|
||||
install(FILES
|
||||
${PLUGINFILES}
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/3proxy
|
||||
FILES_MATCHING PATTERN "*${PLUGIN_SUFFIX}"
|
||||
)
|
||||
endif()
|
||||
|
||||
|
||||
@ -66,7 +66,6 @@ ifeq ($(PAM_CHECK), true)
|
||||
PLUGINS += PamAuth
|
||||
endif
|
||||
|
||||
BUNDLED_HASH_OBJS = md4$(OBJSUFFICS) md5$(OBJSUFFICS)
|
||||
include Makefile.inc
|
||||
|
||||
DESTDIR ?=
|
||||
|
||||
@ -69,7 +69,6 @@ PAM_CHECK ?= $(shell echo "\#include <security/pam_appl.h>\\n int main(){return
|
||||
ifeq ($(PAM_CHECK), true)
|
||||
PLUGINS += PamAuth
|
||||
endif
|
||||
BUNDLED_HASH_OBJS = md4$(OBJSUFFICS) md5$(OBJSUFFICS)
|
||||
include Makefile.inc
|
||||
|
||||
allplugins:
|
||||
|
||||
@ -44,7 +44,6 @@ ifeq ($(PCRE_CHECK), true)
|
||||
PCRE_LIBS = -Wl,-Bstatic -lpcre2-8 -Wl,-Bdynamic
|
||||
endif
|
||||
|
||||
BUNDLED_HASH_OBJS = md4$(OBJSUFFICS) md5$(OBJSUFFICS)
|
||||
include Makefile.inc
|
||||
|
||||
allplugins:
|
||||
|
||||
@ -68,7 +68,6 @@ ifeq ($(PAM_CHECK), true)
|
||||
PLUGINS += PamAuth
|
||||
endif
|
||||
|
||||
BUNDLED_HASH_OBJS = md4$(OBJSUFFICS) md5$(OBJSUFFICS)
|
||||
include Makefile.inc
|
||||
|
||||
DESTDIR ?=
|
||||
|
||||
17
Makefile.win
17
Makefile.win
@ -37,28 +37,21 @@ BUILDDATE := $(BUILDDATE)
|
||||
AFTERCLEAN = (find . -type f -name "*.o" -delete && find . -type f -name "*.res" -delete && find src/ -type f -name "Makefile.var" -delete && find bin/ -type f -executable -delete) || true
|
||||
|
||||
ifndef OPENSSL_CHECK
|
||||
ifeq ($(LIBSTATIC), true)
|
||||
STATIC_PREFIX = -Wl,-Bstatic
|
||||
STATIC_SUFFIX = -Wl,-Bdynamic
|
||||
ZLIB = -lz
|
||||
endif
|
||||
OPENSSL_CHECK = $(shell echo "\#include <openssl/ssl.h>\\n int main(){return 0;}" | tr -d '\\\\' | $(CC) -x c $(CFLAGS) $(LDFLAGS) $(STATIC_PREFIX) $(ZLIB) -l crypto -l ssl $(STATIC_SUFFIX) -o testssl - 2>/dev/null && rm testssl && echo true||echo false)
|
||||
OPENSSL_CHECK = $(shell echo "\#include <openssl/ssl.h>\\n int main(){return 0;}" | tr -d '\\\\' | cc -x c $(CFLAGS) $(LDFLAGS) -l crypto -l ssl -o testssl - 2>/dev/null && rm testssl && echo true||echo false)
|
||||
ifeq ($(OPENSSL_CHECK), true)
|
||||
LIBS += $(STATIC_PREFIX) $(ZLIB) -l crypto -l ssl $(STATIC_SUFFIX) -lcrypt32
|
||||
LIBS += -l crypto -l ssl
|
||||
CFLAGS += -DWITH_SSL
|
||||
SSL_OBJS = ssllib$(OBJSUFFICS) ssl$(OBJSUFFICS)
|
||||
else
|
||||
ZLIB :=
|
||||
endif
|
||||
PAM_CHECK = $(shell echo "\#include <security/pam_appl.h>\\n int main(){return 0;}" | tr -d '\\\\' | $(CC) -x c $(CFLAGS) $(LDFLAGS) -l pam -o testpam - 2>/dev/null && rm testpam && echo true||echo false)
|
||||
PAM_CHECK = $(shell echo "\#include <security/pam_appl.h>\\n int main(){return 0;}" | tr -d '\\\\' | cc -x c $(CFLAGS) $(LDFLAGS) -l pam -o testpam - 2>/dev/null && rm testpam && echo true||echo false)
|
||||
ifeq ($(PAM_CHECK), true)
|
||||
PLUGINS += PamAuth
|
||||
endif
|
||||
PCRE_CHECK = $(shell echo "\#define PCRE2_CODE_UNIT_WIDTH 8\\n#include <pcre2.h>\\n int main(){return 0;}" | tr -d '\\\\' | $(CC) -x c $(CFLAGS) $(LDFLAGS) $(STATIC_PREFIX) -lpcre2-8 $(STATIC_SUFFIX) -o testpcre - 2>/dev/null && rm testpcre && echo true||echo false)
|
||||
PCRE_CHECK = $(shell echo "\#define PCRE2_CODE_UNIT_WIDTH 8\\n#include <pcre2.h>\\n int main(){return 0;}" | tr -d '\\\\' | cc -x c $(CFLAGS) $(LDFLAGS) -lpcre2-8 -o testpcre - 2>/dev/null && rm testpcre && echo true||echo false)
|
||||
ifeq ($(PCRE_CHECK), true)
|
||||
CFLAGS += -DWITH_PCRE
|
||||
PCRE_OBJS = pcre$(OBJSUFFICS)
|
||||
PCRE_LIBS = $(STATIC_PREFIX) -lpcre2-8 $(STATIC_SUFFIX)
|
||||
PCRE_LIBS = -lpcre2-8
|
||||
endif
|
||||
endif
|
||||
|
||||
|
||||
@ -6,7 +6,13 @@
|
||||
|
||||
*/
|
||||
#include "libs/blake2.h"
|
||||
#include "mdhash.h"
|
||||
#ifdef WITH_SSL
|
||||
#include <openssl/evp.h>
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
|
||||
#include <openssl/params.h>
|
||||
#include <openssl/core_names.h>
|
||||
#endif
|
||||
#endif
|
||||
#include <string.h>
|
||||
|
||||
#define MD5_SIZE 16
|
||||
@ -22,6 +28,11 @@ static unsigned char itoa64[] =
|
||||
"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
|
||||
|
||||
#if defined(WITH_SSL) && OPENSSL_VERSION_NUMBER >= 0x30000000L
|
||||
EVP_MD *md4_hash = NULL;
|
||||
EVP_MD *md5_hash = NULL;
|
||||
#endif
|
||||
|
||||
void
|
||||
_crypt_to64(unsigned char *s, unsigned long v, int n)
|
||||
{
|
||||
@ -32,13 +43,21 @@ _crypt_to64(unsigned char *s, unsigned long v, int n)
|
||||
}
|
||||
|
||||
|
||||
#ifdef WITH_SSL
|
||||
unsigned char * ntpwdhash (unsigned char *szHash, const unsigned char *szPassword, int ctohex)
|
||||
{
|
||||
unsigned char szUnicodePass[513];
|
||||
unsigned int nPasswordLen;
|
||||
unsigned int len = 16;
|
||||
EVP_MD_CTX *ctx;
|
||||
unsigned int len=sizeof(szUnicodePass);
|
||||
unsigned int i;
|
||||
mdh_ctx *ctx;
|
||||
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
|
||||
const EVP_MD *md4 = md4_hash;
|
||||
#else
|
||||
const EVP_MD *md4 = EVP_md4();
|
||||
#endif
|
||||
if(md4 == NULL) return NULL;
|
||||
|
||||
/*
|
||||
* NT passwords are unicode. Convert plain text password
|
||||
@ -52,14 +71,15 @@ unsigned char * ntpwdhash (unsigned char *szHash, const unsigned char *szPasswor
|
||||
}
|
||||
|
||||
/* Encrypt Unicode password to a 16-byte MD4 hash */
|
||||
ctx = mdh_init(MDH_MD4);
|
||||
ctx = EVP_MD_CTX_new();
|
||||
if(!ctx) return NULL;
|
||||
mdh_update(ctx, szUnicodePass, (nPasswordLen<<1));
|
||||
if(!mdh_final(ctx, szUnicodePass, &len)) {
|
||||
mdh_free(ctx);
|
||||
if(!EVP_DigestInit_ex(ctx, md4, NULL)){
|
||||
EVP_MD_CTX_free(ctx);
|
||||
return NULL;
|
||||
}
|
||||
mdh_free(ctx);
|
||||
EVP_DigestUpdate(ctx, szUnicodePass, (nPasswordLen<<1));
|
||||
EVP_DigestFinal_ex(ctx, szUnicodePass, &len);
|
||||
EVP_MD_CTX_free(ctx);
|
||||
if (ctohex){
|
||||
tohex(szUnicodePass, szHash, 16);
|
||||
}
|
||||
@ -67,6 +87,7 @@ unsigned char * ntpwdhash (unsigned char *szHash, const unsigned char *szPasswor
|
||||
memset(szUnicodePass, 0, sizeof szUnicodePass);
|
||||
return szHash;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
unsigned char * mycrypt(const unsigned char *pw, const unsigned char *salt, unsigned char *passwd){
|
||||
@ -79,44 +100,57 @@ unsigned char * mycrypt(const unsigned char *pw, const unsigned char *salt, unsi
|
||||
int sl;
|
||||
unsigned long l;
|
||||
|
||||
#if defined(WITH_SSL)
|
||||
#ifndef WITHMAIN
|
||||
if(salt[0] == '$' && salt[1] == '1' && salt[2] == '$' && (ep = (unsigned char *)strchr((char *)salt+3, '$'))) {
|
||||
mdh_ctx *ctx, *ctx1;
|
||||
unsigned int len = MD5_SIZE;
|
||||
EVP_MD_CTX *ctx, *ctx1;
|
||||
unsigned int len;
|
||||
int pl, i;
|
||||
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
|
||||
const EVP_MD *md5 = md5_hash;
|
||||
#else
|
||||
const EVP_MD *md5 = EVP_md5();
|
||||
#endif
|
||||
if(md5 == NULL) {
|
||||
*passwd = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sp = salt +3;
|
||||
sl = (int)(ep - sp);
|
||||
magic = (unsigned char *)"$1$";
|
||||
|
||||
ctx = mdh_init(MDH_MD5);
|
||||
ctx = EVP_MD_CTX_new();
|
||||
if(!ctx) {
|
||||
*passwd = 0;
|
||||
return NULL;
|
||||
}
|
||||
EVP_DigestInit_ex(ctx, md5, NULL);
|
||||
|
||||
/* The password first, since that is what is most unknown */
|
||||
mdh_update(ctx, pw, (unsigned int)strlen((char *)pw));
|
||||
EVP_DigestUpdate(ctx,pw,strlen((char *)pw));
|
||||
|
||||
/* Then our magic string */
|
||||
mdh_update(ctx, magic, (unsigned int)strlen((char *)magic));
|
||||
EVP_DigestUpdate(ctx,magic,strlen((char *)magic));
|
||||
|
||||
/* Then the raw salt */
|
||||
mdh_update(ctx, sp, (unsigned int)sl);
|
||||
EVP_DigestUpdate(ctx,sp,sl);
|
||||
|
||||
/* Then just as many unsigned characters of the MD5(pw,salt,pw) */
|
||||
ctx1 = mdh_init(MDH_MD5);
|
||||
ctx1 = EVP_MD_CTX_new();
|
||||
if(!ctx1) {
|
||||
mdh_free(ctx);
|
||||
EVP_MD_CTX_free(ctx);
|
||||
*passwd = 0;
|
||||
return NULL;
|
||||
}
|
||||
mdh_update(ctx1, pw, (unsigned int)strlen((char *)pw));
|
||||
mdh_update(ctx1, sp, (unsigned int)sl);
|
||||
mdh_update(ctx1, pw, (unsigned int)strlen((char *)pw));
|
||||
mdh_final(ctx1, final, &len);
|
||||
EVP_DigestInit_ex(ctx1, md5, NULL);
|
||||
EVP_DigestUpdate(ctx1,pw,strlen((char *)pw));
|
||||
EVP_DigestUpdate(ctx1,sp,sl);
|
||||
EVP_DigestUpdate(ctx1,pw,strlen((char *)pw));
|
||||
EVP_DigestFinal_ex(ctx1,final,&len);
|
||||
for(pl = (int)strlen((char *)pw); pl > 0; pl -= MD5_SIZE)
|
||||
mdh_update(ctx, final, (unsigned int)(pl>MD5_SIZE ? MD5_SIZE : pl));
|
||||
EVP_DigestUpdate(ctx,final,pl>MD5_SIZE ? MD5_SIZE : pl);
|
||||
|
||||
/* Don't leave anything around in vm they could use. */
|
||||
memset(final,0,sizeof final);
|
||||
@ -124,13 +158,13 @@ unsigned char * mycrypt(const unsigned char *pw, const unsigned char *salt, unsi
|
||||
/* Then something really weird... */
|
||||
for (i = (int)strlen((char *)pw); i ; i >>= 1)
|
||||
if(i&1)
|
||||
mdh_update(ctx, final, 1);
|
||||
EVP_DigestUpdate(ctx, final, 1);
|
||||
else
|
||||
mdh_update(ctx, pw, 1);
|
||||
EVP_DigestUpdate(ctx, pw, 1);
|
||||
|
||||
|
||||
mdh_final(ctx, final, &len);
|
||||
mdh_free(ctx);
|
||||
EVP_DigestFinal_ex(ctx,final,&len);
|
||||
EVP_MD_CTX_free(ctx);
|
||||
|
||||
/*
|
||||
* and now, just to make sure things don't run too fast
|
||||
@ -138,29 +172,29 @@ unsigned char * mycrypt(const unsigned char *pw, const unsigned char *salt, unsi
|
||||
* need 30 seconds to build a 1000 entry dictionary...
|
||||
*/
|
||||
for(i=0;i<1000;i++) {
|
||||
mdh_free(ctx1);
|
||||
ctx1 = mdh_init(MDH_MD5);
|
||||
if(!ctx1) { *passwd = 0; return NULL; }
|
||||
EVP_MD_CTX_reset(ctx1);
|
||||
EVP_DigestInit_ex(ctx1, md5, NULL);
|
||||
if(i & 1)
|
||||
mdh_update(ctx1, pw, (unsigned int)strlen((char *)pw));
|
||||
EVP_DigestUpdate(ctx1,pw,strlen((char *)pw));
|
||||
else
|
||||
mdh_update(ctx1, final, MD5_SIZE);
|
||||
EVP_DigestUpdate(ctx1,final,MD5_SIZE);
|
||||
|
||||
if(i % 3)
|
||||
mdh_update(ctx1, sp, (unsigned int)sl);
|
||||
EVP_DigestUpdate(ctx1,sp,sl);
|
||||
|
||||
if(i % 7)
|
||||
mdh_update(ctx1, pw, (unsigned int)strlen((char *)pw));
|
||||
EVP_DigestUpdate(ctx1,pw,strlen((char *)pw));
|
||||
|
||||
if(i & 1)
|
||||
mdh_update(ctx1, final, MD5_SIZE);
|
||||
EVP_DigestUpdate(ctx1,final,MD5_SIZE);
|
||||
else
|
||||
mdh_update(ctx1, pw, (unsigned int)strlen((char *)pw));
|
||||
mdh_final(ctx1, final, &len);
|
||||
EVP_DigestUpdate(ctx1,pw,strlen((char *)pw));
|
||||
EVP_DigestFinal_ex(ctx1,final,&len);
|
||||
}
|
||||
mdh_free(ctx1);
|
||||
EVP_MD_CTX_free(ctx1);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
#endif
|
||||
if(salt[0] == '$' && salt[1] == '3' && salt[2] == '$' && (ep = (unsigned char *)strchr((char *)salt+3, '$'))) {
|
||||
sp = salt +3;
|
||||
@ -204,6 +238,9 @@ unsigned char * mycrypt(const unsigned char *pw, const unsigned char *salt, unsi
|
||||
}
|
||||
|
||||
#ifdef WITHMAIN
|
||||
#if defined(WITH_SSL) && OPENSSL_VERSION_NUMBER >= 0x30000000L
|
||||
#include <openssl/provider.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
int main(int argc, char* argv[]){
|
||||
unsigned char buf1[128];
|
||||
@ -211,17 +248,37 @@ int main(int argc, char* argv[]){
|
||||
unsigned i;
|
||||
if(argc < 2 || argc > 3) {
|
||||
fprintf(stderr, "usage: \n"
|
||||
#ifdef WITH_SSL
|
||||
"\t%s <password>\n"
|
||||
#endif
|
||||
"\t%s <salt> <password>\n"
|
||||
#ifdef WITH_SSL
|
||||
"Performs NT crypt if no salt specified, BLAKE2 crypt with salt\n"
|
||||
#else
|
||||
"Performs BLAKE2 crypt with salt\n"
|
||||
#endif
|
||||
,
|
||||
#ifdef WITH_SSL
|
||||
argv[0],
|
||||
#endif
|
||||
argv[0]);
|
||||
return 1;
|
||||
}
|
||||
#if defined(WITH_SSL) && OPENSSL_VERSION_NUMBER >= 0x30000000L
|
||||
OSSL_PROVIDER_load(NULL, "legacy");
|
||||
OSSL_PROVIDER_load(NULL, "default");
|
||||
md4_hash = EVP_MD_fetch(NULL, "MD4", NULL);
|
||||
if (md4_hash == NULL) {
|
||||
fprintf(stderr, "Error fetching MD4\n");
|
||||
}
|
||||
#endif
|
||||
if(argc == 2) {
|
||||
#ifdef WITH_SSL
|
||||
{ unsigned char *nt = ntpwdhash(buf1, (unsigned char *)argv[1], 1);
|
||||
if(nt) printf("NT:%s\n", nt); }
|
||||
#else
|
||||
fprintf(stderr, "NT crypt not available (compiled without OpenSSL)\n");
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
unsigned char *cr;
|
||||
|
||||
@ -134,7 +134,7 @@ hashtables$(OBJSUFFICS): hashtables.c proxy.h structures.h libs/blake2.h
|
||||
resolve$(OBJSUFFICS): resolve.c proxy.h structures.h
|
||||
$(CC) $(COUT)resolve$(OBJSUFFICS) $(CFLAGS) resolve.c
|
||||
|
||||
authradius$(OBJSUFFICS): authradius.c proxy.h structures.h mdhash.h
|
||||
authradius$(OBJSUFFICS): authradius.c proxy.h structures.h
|
||||
$(CC) $(COUT)authradius$(OBJSUFFICS) $(CFLAGS) authradius.c
|
||||
|
||||
conf$(OBJSUFFICS): conf.c proxy.h structures.h
|
||||
@ -146,26 +146,17 @@ log$(OBJSUFFICS): log.c proxy.h structures.h
|
||||
datatypes$(OBJSUFFICS): datatypes.c proxy.h structures.h
|
||||
$(CC) $(COUT)datatypes$(OBJSUFFICS) $(CFLAGS) datatypes.c
|
||||
|
||||
3proxy_crypt$(OBJSUFFICS): 3proxy_crypt.c libs/blake2.h mdhash.h
|
||||
3proxy_crypt$(OBJSUFFICS): 3proxy_crypt.c libs/blake2.h
|
||||
$(CC) $(COUT)3proxy_crypt$(OBJSUFFICS) $(CFLAGS) 3proxy_crypt.c
|
||||
|
||||
3proxy_cryptmain$(OBJSUFFICS): 3proxy_crypt.c libs/blake2.h mdhash.h
|
||||
3proxy_cryptmain$(OBJSUFFICS): 3proxy_crypt.c libs/blake2.h
|
||||
$(CC) $(COUT)3proxy_cryptmain$(OBJSUFFICS) $(CFLAGS) $(DEFINEOPTION)WITHMAIN 3proxy_crypt.c
|
||||
|
||||
blake2$(OBJSUFFICS): libs/blake2b-ref.c
|
||||
$(CC) $(COUT)blake2$(OBJSUFFICS) $(CFLAGS) libs/blake2b-ref.c
|
||||
|
||||
mdhash$(OBJSUFFICS): mdhash.c mdhash.h proxy.h structures.h
|
||||
$(CC) $(COUT)mdhash$(OBJSUFFICS) $(CFLAGS) mdhash.c
|
||||
|
||||
md4$(OBJSUFFICS): libs/md4.c libs/md4.h
|
||||
$(CC) $(COUT)md4$(OBJSUFFICS) $(CFLAGS) libs/md4.c
|
||||
|
||||
md5$(OBJSUFFICS): libs/md5.c libs/md5.h
|
||||
$(CC) $(COUT)md5$(OBJSUFFICS) $(CFLAGS) libs/md5.c
|
||||
|
||||
$(BUILDDIR)$(CRYPT_PREFIX)crypt$(EXESUFFICS): blake2$(OBJSUFFICS) 3proxy_cryptmain$(OBJSUFFICS) base64$(OBJSUFFICS) mdhash$(OBJSUFFICS) $(BUNDLED_HASH_OBJS)
|
||||
$(LN) $(LNOUT)$(BUILDDIR)$(CRYPT_PREFIX)crypt$(EXESUFFICS) $(LDFLAGS) blake2$(OBJSUFFICS) base64$(OBJSUFFICS) mdhash$(OBJSUFFICS) $(BUNDLED_HASH_OBJS) 3proxy_cryptmain$(OBJSUFFICS) $(LIBS)
|
||||
$(BUILDDIR)$(CRYPT_PREFIX)crypt$(EXESUFFICS): blake2$(OBJSUFFICS) 3proxy_cryptmain$(OBJSUFFICS) base64$(OBJSUFFICS)
|
||||
$(LN) $(LNOUT)$(BUILDDIR)$(CRYPT_PREFIX)crypt$(EXESUFFICS) $(LDFLAGS) blake2$(OBJSUFFICS) base64$(OBJSUFFICS) 3proxy_cryptmain$(OBJSUFFICS) $(LIBS)
|
||||
|
||||
stringtable$(OBJSUFFICS): stringtable.c
|
||||
$(CC) $(COUT)stringtable$(OBJSUFFICS) $(CFLAGS) stringtable.c
|
||||
@ -179,6 +170,6 @@ ssl$(OBJSUFFICS): ssl.c structures.h proxy.h ssl.h
|
||||
pcre$(OBJSUFFICS): pcre.c structures.h
|
||||
$(CC) $(COUT)pcre$(OBJSUFFICS) $(CFLAGS) $(DEFINEOPTION)WITH_PCRE pcre.c
|
||||
|
||||
$(BUILDDIR)3proxy$(EXESUFFICS): 3proxy$(OBJSUFFICS) mainfunc$(OBJSUFFICS) srvproxy$(OBJSUFFICS) srvpop3p$(OBJSUFFICS) srvsmtpp$(OBJSUFFICS) srvftppr$(OBJSUFFICS) srvsocks$(OBJSUFFICS) srvtcppm$(OBJSUFFICS) srvtlspr$(OBJSUFFICS) srvauto$(OBJSUFFICS) srvudppm$(OBJSUFFICS) sockmap$(OBJSUFFICS) udpsockmap$(OBJSUFFICS) sockgetchar$(OBJSUFFICS) common$(OBJSUFFICS) auth$(OBJSUFFICS) acl$(OBJSUFFICS) limiter$(OBJSUFFICS) redirect$(OBJSUFFICS) authradius$(OBJSUFFICS) hash$(OBJSUFFICS) hashtables$(OBJSUFFICS) resolve$(OBJSUFFICS) sql$(OBJSUFFICS) conf$(OBJSUFFICS) log$(OBJSUFFICS) datatypes$(OBJSUFFICS) blake2$(OBJSUFFICS) 3proxy_crypt$(OBJSUFFICS) base64$(OBJSUFFICS) ftp$(OBJSUFFICS) stringtable$(OBJSUFFICS) srvwebadmin$(OBJSUFFICS) srvdnspr$(OBJSUFFICS) plugins$(OBJSUFFICS) mdhash$(OBJSUFFICS) $(BUNDLED_HASH_OBJS) $(SSL_OBJS) $(PCRE_OBJS) $(COMPATLIBS) $(VERSIONDEP)
|
||||
$(LN) $(LNOUT)$(BUILDDIR)3proxy$(EXESUFFICS) $(LDFLAGS) $(VERFILE) 3proxy$(OBJSUFFICS) mainfunc$(OBJSUFFICS) auth$(OBJSUFFICS) acl$(OBJSUFFICS) limiter$(OBJSUFFICS) redirect$(OBJSUFFICS) authradius$(OBJSUFFICS) hash$(OBJSUFFICS) hashtables$(OBJSUFFICS) resolve$(OBJSUFFICS) sql$(OBJSUFFICS) conf$(OBJSUFFICS) datatypes$(OBJSUFFICS) srvauto$(OBJSUFFICS) srvproxy$(OBJSUFFICS) srvpop3p$(OBJSUFFICS) srvsmtpp$(OBJSUFFICS) srvftppr$(OBJSUFFICS) srvsocks$(OBJSUFFICS) srvtcppm$(OBJSUFFICS) srvtlspr$(OBJSUFFICS) srvudppm$(OBJSUFFICS) sockmap$(OBJSUFFICS) udpsockmap$(OBJSUFFICS) sockgetchar$(OBJSUFFICS) common$(OBJSUFFICS) log$(OBJSUFFICS) 3proxy_crypt$(OBJSUFFICS) blake2$(OBJSUFFICS) base64$(OBJSUFFICS) ftp$(OBJSUFFICS) stringtable$(OBJSUFFICS) srvwebadmin$(OBJSUFFICS) srvdnspr$(OBJSUFFICS) plugins$(OBJSUFFICS) mdhash$(OBJSUFFICS) $(BUNDLED_HASH_OBJS) $(SSL_OBJS) $(PCRE_OBJS) $(COMPATLIBS) $(LIBS) $(PCRE_LIBS)
|
||||
$(BUILDDIR)3proxy$(EXESUFFICS): 3proxy$(OBJSUFFICS) mainfunc$(OBJSUFFICS) srvproxy$(OBJSUFFICS) srvpop3p$(OBJSUFFICS) srvsmtpp$(OBJSUFFICS) srvftppr$(OBJSUFFICS) srvsocks$(OBJSUFFICS) srvtcppm$(OBJSUFFICS) srvtlspr$(OBJSUFFICS) srvauto$(OBJSUFFICS) srvudppm$(OBJSUFFICS) sockmap$(OBJSUFFICS) udpsockmap$(OBJSUFFICS) sockgetchar$(OBJSUFFICS) common$(OBJSUFFICS) auth$(OBJSUFFICS) acl$(OBJSUFFICS) limiter$(OBJSUFFICS) redirect$(OBJSUFFICS) authradius$(OBJSUFFICS) hash$(OBJSUFFICS) hashtables$(OBJSUFFICS) resolve$(OBJSUFFICS) sql$(OBJSUFFICS) conf$(OBJSUFFICS) log$(OBJSUFFICS) datatypes$(OBJSUFFICS) blake2$(OBJSUFFICS) 3proxy_crypt$(OBJSUFFICS) base64$(OBJSUFFICS) ftp$(OBJSUFFICS) stringtable$(OBJSUFFICS) srvwebadmin$(OBJSUFFICS) srvdnspr$(OBJSUFFICS) plugins$(OBJSUFFICS) $(SSL_OBJS) $(PCRE_OBJS) $(COMPATLIBS) $(VERSIONDEP)
|
||||
$(LN) $(LNOUT)$(BUILDDIR)3proxy$(EXESUFFICS) $(LDFLAGS) $(VERFILE) 3proxy$(OBJSUFFICS) mainfunc$(OBJSUFFICS) auth$(OBJSUFFICS) acl$(OBJSUFFICS) limiter$(OBJSUFFICS) redirect$(OBJSUFFICS) authradius$(OBJSUFFICS) hash$(OBJSUFFICS) hashtables$(OBJSUFFICS) resolve$(OBJSUFFICS) sql$(OBJSUFFICS) conf$(OBJSUFFICS) datatypes$(OBJSUFFICS) srvauto$(OBJSUFFICS) srvproxy$(OBJSUFFICS) srvpop3p$(OBJSUFFICS) srvsmtpp$(OBJSUFFICS) srvftppr$(OBJSUFFICS) srvsocks$(OBJSUFFICS) srvtcppm$(OBJSUFFICS) srvtlspr$(OBJSUFFICS) srvudppm$(OBJSUFFICS) sockmap$(OBJSUFFICS) udpsockmap$(OBJSUFFICS) sockgetchar$(OBJSUFFICS) common$(OBJSUFFICS) log$(OBJSUFFICS) 3proxy_crypt$(OBJSUFFICS) blake2$(OBJSUFFICS) base64$(OBJSUFFICS) ftp$(OBJSUFFICS) stringtable$(OBJSUFFICS) srvwebadmin$(OBJSUFFICS) srvdnspr$(OBJSUFFICS) plugins$(OBJSUFFICS) $(SSL_OBJS) $(PCRE_OBJS) $(COMPATLIBS) $(LIBS) $(PCRE_LIBS)
|
||||
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
|
||||
#ifndef NORADIUS
|
||||
#include "proxy.h"
|
||||
#include "mdhash.h"
|
||||
#include <openssl/evp.h>
|
||||
|
||||
#define AUTH_VECTOR_LEN 16
|
||||
#define MAX_STRING_LEN 254
|
||||
@ -185,15 +185,25 @@ char *strNcpy(char *dest, const char *src, int n)
|
||||
return dest;
|
||||
}
|
||||
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
|
||||
extern EVP_MD *md4_hash;
|
||||
extern EVP_MD *md5_hash;
|
||||
#endif
|
||||
|
||||
|
||||
void md5_calc(unsigned char *output, unsigned char *input,
|
||||
unsigned int inlen)
|
||||
{
|
||||
mdh_ctx *ctx = mdh_init(MDH_MD5);
|
||||
unsigned int len = 16;
|
||||
if(!ctx) return;
|
||||
mdh_update(ctx, input, inlen);
|
||||
mdh_final(ctx, output, &len);
|
||||
mdh_free(ctx);
|
||||
EVP_MD_CTX *ctx = EVP_MD_CTX_new();
|
||||
unsigned int len = 0;
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
|
||||
EVP_DigestInit_ex(ctx, md5_hash, NULL);
|
||||
#else
|
||||
EVP_DigestInit_ex(ctx, EVP_md5(), NULL);
|
||||
#endif
|
||||
EVP_DigestUpdate(ctx, input, inlen);
|
||||
EVP_DigestFinal_ex(ctx, output, &len);
|
||||
EVP_MD_CTX_free(ctx);
|
||||
}
|
||||
|
||||
|
||||
|
||||
268
src/libs/md4.c
268
src/libs/md4.c
@ -1,268 +0,0 @@
|
||||
/*
|
||||
* This is an OpenSSL API compatible (but not ABI compatible) implementation
|
||||
* of the RSA Data Security, Inc. MD4 Message-Digest Algorithm (RFC 1320).
|
||||
*
|
||||
* Homepage:
|
||||
* https://openwall.info/wiki/people/solar/software/public-domain-source-code/md4
|
||||
*
|
||||
* Author:
|
||||
* Alexander Peslyak, better known as Solar Designer <solar at openwall.com>
|
||||
*
|
||||
* This software was written by Alexander Peslyak in 2001. No copyright is
|
||||
* claimed, and the software is hereby placed in the public domain.
|
||||
* In case this attempt to disclaim copyright and place the software in the
|
||||
* public domain is deemed null and void, then the software is
|
||||
* Copyright (c) 2001 Alexander Peslyak and it is hereby released to the
|
||||
* general public under the following terms:
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted.
|
||||
*
|
||||
* There's ABSOLUTELY NO WARRANTY, express or implied.
|
||||
*
|
||||
* (This is a heavily cut-down "BSD license".)
|
||||
*
|
||||
* This differs from Colin Plumb's older public domain implementation in that
|
||||
* no exactly 32-bit integer data type is required (any 32-bit or wider
|
||||
* unsigned integer data type will do), there's no compile-time endianness
|
||||
* configuration, and the function prototypes match OpenSSL's. No code from
|
||||
* Colin Plumb's implementation has been reused; this comment merely compares
|
||||
* the properties of the two independent implementations.
|
||||
*
|
||||
* The primary goals of this implementation are portability and ease of use.
|
||||
* It is meant to be fast, but not as fast as possible. Some known
|
||||
* optimizations are not included to reduce source code size and avoid
|
||||
* compile-time configuration.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "md4.h"
|
||||
|
||||
/*
|
||||
* The basic MD4 functions.
|
||||
*
|
||||
* F and G are optimized compared to their RFC 1320 definitions, with the
|
||||
* optimization for F borrowed from Colin Plumb's MD5 implementation.
|
||||
*/
|
||||
#define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
|
||||
#define G(x, y, z) (((x) & ((y) | (z))) | ((y) & (z)))
|
||||
#define H(x, y, z) ((x) ^ (y) ^ (z))
|
||||
|
||||
/*
|
||||
* The MD4 transformation for all three rounds.
|
||||
*/
|
||||
#define STEP(f, a, b, c, d, x, s) \
|
||||
(a) += f((b), (c), (d)) + (x); \
|
||||
(a) = (((a) << (s)) | (((a) & 0xffffffff) >> (32 - (s))));
|
||||
|
||||
/*
|
||||
* SET reads 4 input bytes in little-endian byte order and stores them in a
|
||||
* properly aligned word in host byte order.
|
||||
*
|
||||
* The check for little-endian architectures that tolerate unaligned memory
|
||||
* accesses is just an optimization. Nothing will break if it fails to detect
|
||||
* a suitable architecture.
|
||||
*
|
||||
* Unfortunately, this optimization may be a C strict aliasing rules violation
|
||||
* if the caller's data buffer has effective type that cannot be aliased by
|
||||
* MD4_u32plus. In practice, this problem may occur if these MD4 routines are
|
||||
* inlined into a calling function, or with future and dangerously advanced
|
||||
* link-time optimizations. For the time being, keeping these MD4 routines in
|
||||
* their own translation unit avoids the problem.
|
||||
*/
|
||||
#if defined(__i386__) || defined(__x86_64__) || defined(__vax__)
|
||||
#define SET(n) \
|
||||
(*(MD4_u32plus *)&ptr[(n) * 4])
|
||||
#define GET(n) \
|
||||
SET(n)
|
||||
#else
|
||||
#define SET(n) \
|
||||
(ctx->block[(n)] = \
|
||||
(MD4_u32plus)ptr[(n) * 4] | \
|
||||
((MD4_u32plus)ptr[(n) * 4 + 1] << 8) | \
|
||||
((MD4_u32plus)ptr[(n) * 4 + 2] << 16) | \
|
||||
((MD4_u32plus)ptr[(n) * 4 + 3] << 24))
|
||||
#define GET(n) \
|
||||
(ctx->block[(n)])
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This processes one or more 64-byte data blocks, but does NOT update the bit
|
||||
* counters. There are no alignment requirements.
|
||||
*/
|
||||
static const void *body(MD4_CTX *ctx, const void *data, size_t size)
|
||||
{
|
||||
const unsigned char *ptr;
|
||||
MD4_u32plus a, b, c, d;
|
||||
MD4_u32plus saved_a, saved_b, saved_c, saved_d;
|
||||
const MD4_u32plus ac1 = 0x5a827999, ac2 = 0x6ed9eba1;
|
||||
|
||||
ptr = (const unsigned char *)data;
|
||||
|
||||
a = ctx->a;
|
||||
b = ctx->b;
|
||||
c = ctx->c;
|
||||
d = ctx->d;
|
||||
|
||||
do {
|
||||
saved_a = a;
|
||||
saved_b = b;
|
||||
saved_c = c;
|
||||
saved_d = d;
|
||||
|
||||
/* Round 1 */
|
||||
STEP(F, a, b, c, d, SET(0), 3)
|
||||
STEP(F, d, a, b, c, SET(1), 7)
|
||||
STEP(F, c, d, a, b, SET(2), 11)
|
||||
STEP(F, b, c, d, a, SET(3), 19)
|
||||
STEP(F, a, b, c, d, SET(4), 3)
|
||||
STEP(F, d, a, b, c, SET(5), 7)
|
||||
STEP(F, c, d, a, b, SET(6), 11)
|
||||
STEP(F, b, c, d, a, SET(7), 19)
|
||||
STEP(F, a, b, c, d, SET(8), 3)
|
||||
STEP(F, d, a, b, c, SET(9), 7)
|
||||
STEP(F, c, d, a, b, SET(10), 11)
|
||||
STEP(F, b, c, d, a, SET(11), 19)
|
||||
STEP(F, a, b, c, d, SET(12), 3)
|
||||
STEP(F, d, a, b, c, SET(13), 7)
|
||||
STEP(F, c, d, a, b, SET(14), 11)
|
||||
STEP(F, b, c, d, a, SET(15), 19)
|
||||
|
||||
/* Round 2 */
|
||||
STEP(G, a, b, c, d, GET(0) + ac1, 3)
|
||||
STEP(G, d, a, b, c, GET(4) + ac1, 5)
|
||||
STEP(G, c, d, a, b, GET(8) + ac1, 9)
|
||||
STEP(G, b, c, d, a, GET(12) + ac1, 13)
|
||||
STEP(G, a, b, c, d, GET(1) + ac1, 3)
|
||||
STEP(G, d, a, b, c, GET(5) + ac1, 5)
|
||||
STEP(G, c, d, a, b, GET(9) + ac1, 9)
|
||||
STEP(G, b, c, d, a, GET(13) + ac1, 13)
|
||||
STEP(G, a, b, c, d, GET(2) + ac1, 3)
|
||||
STEP(G, d, a, b, c, GET(6) + ac1, 5)
|
||||
STEP(G, c, d, a, b, GET(10) + ac1, 9)
|
||||
STEP(G, b, c, d, a, GET(14) + ac1, 13)
|
||||
STEP(G, a, b, c, d, GET(3) + ac1, 3)
|
||||
STEP(G, d, a, b, c, GET(7) + ac1, 5)
|
||||
STEP(G, c, d, a, b, GET(11) + ac1, 9)
|
||||
STEP(G, b, c, d, a, GET(15) + ac1, 13)
|
||||
|
||||
/* Round 3 */
|
||||
STEP(H, a, b, c, d, GET(0) + ac2, 3)
|
||||
STEP(H, d, a, b, c, GET(8) + ac2, 9)
|
||||
STEP(H, c, d, a, b, GET(4) + ac2, 11)
|
||||
STEP(H, b, c, d, a, GET(12) + ac2, 15)
|
||||
STEP(H, a, b, c, d, GET(2) + ac2, 3)
|
||||
STEP(H, d, a, b, c, GET(10) + ac2, 9)
|
||||
STEP(H, c, d, a, b, GET(6) + ac2, 11)
|
||||
STEP(H, b, c, d, a, GET(14) + ac2, 15)
|
||||
STEP(H, a, b, c, d, GET(1) + ac2, 3)
|
||||
STEP(H, d, a, b, c, GET(9) + ac2, 9)
|
||||
STEP(H, c, d, a, b, GET(5) + ac2, 11)
|
||||
STEP(H, b, c, d, a, GET(13) + ac2, 15)
|
||||
STEP(H, a, b, c, d, GET(3) + ac2, 3)
|
||||
STEP(H, d, a, b, c, GET(11) + ac2, 9)
|
||||
STEP(H, c, d, a, b, GET(7) + ac2, 11)
|
||||
STEP(H, b, c, d, a, GET(15) + ac2, 15)
|
||||
|
||||
a += saved_a;
|
||||
b += saved_b;
|
||||
c += saved_c;
|
||||
d += saved_d;
|
||||
|
||||
ptr += 64;
|
||||
} while (size -= 64);
|
||||
|
||||
ctx->a = a;
|
||||
ctx->b = b;
|
||||
ctx->c = c;
|
||||
ctx->d = d;
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void MD4_Init(MD4_CTX *ctx)
|
||||
{
|
||||
ctx->a = 0x67452301;
|
||||
ctx->b = 0xefcdab89;
|
||||
ctx->c = 0x98badcfe;
|
||||
ctx->d = 0x10325476;
|
||||
|
||||
ctx->lo = 0;
|
||||
ctx->hi = 0;
|
||||
}
|
||||
|
||||
void MD4_Update(MD4_CTX *ctx, const void *data, size_t size)
|
||||
{
|
||||
MD4_u32plus saved_lo;
|
||||
size_t used, available;
|
||||
|
||||
saved_lo = ctx->lo;
|
||||
if ((ctx->lo = (saved_lo + size) & 0x1fffffff) < saved_lo)
|
||||
ctx->hi++;
|
||||
ctx->hi += (MD4_u32plus)(size >> 29);
|
||||
|
||||
used = saved_lo & 0x3f;
|
||||
|
||||
if (used) {
|
||||
available = 64 - used;
|
||||
|
||||
if (size < available) {
|
||||
memcpy(&ctx->buffer[used], data, size);
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(&ctx->buffer[used], data, available);
|
||||
data = (const unsigned char *)data + available;
|
||||
size -= available;
|
||||
body(ctx, ctx->buffer, 64);
|
||||
}
|
||||
|
||||
if (size >= 64) {
|
||||
data = body(ctx, data, size & ~(size_t)0x3f);
|
||||
size &= 0x3f;
|
||||
}
|
||||
|
||||
memcpy(ctx->buffer, data, size);
|
||||
}
|
||||
|
||||
#define OUT(dst, src) \
|
||||
(dst)[0] = (unsigned char)(src); \
|
||||
(dst)[1] = (unsigned char)((src) >> 8); \
|
||||
(dst)[2] = (unsigned char)((src) >> 16); \
|
||||
(dst)[3] = (unsigned char)((src) >> 24);
|
||||
|
||||
void MD4_Final(unsigned char *result, MD4_CTX *ctx)
|
||||
{
|
||||
size_t used, available;
|
||||
|
||||
used = ctx->lo & 0x3f;
|
||||
|
||||
ctx->buffer[used++] = 0x80;
|
||||
|
||||
available = 64 - used;
|
||||
|
||||
if (available < 8) {
|
||||
memset(&ctx->buffer[used], 0, available);
|
||||
body(ctx, ctx->buffer, 64);
|
||||
used = 0;
|
||||
available = 64;
|
||||
}
|
||||
|
||||
memset(&ctx->buffer[used], 0, available - 8);
|
||||
|
||||
ctx->lo <<= 3;
|
||||
OUT(&ctx->buffer[56], ctx->lo)
|
||||
OUT(&ctx->buffer[60], ctx->hi)
|
||||
|
||||
body(ctx, ctx->buffer, 64);
|
||||
|
||||
OUT(&result[0], ctx->a)
|
||||
OUT(&result[4], ctx->b)
|
||||
OUT(&result[8], ctx->c)
|
||||
OUT(&result[12], ctx->d)
|
||||
|
||||
#if 0
|
||||
memset(ctx, 0, sizeof(*ctx));
|
||||
#endif
|
||||
}
|
||||
@ -1,47 +0,0 @@
|
||||
/*
|
||||
* This is an OpenSSL API compatible (but not ABI compatible) implementation
|
||||
* of the RSA Data Security, Inc. MD4 Message-Digest Algorithm (RFC 1320).
|
||||
*
|
||||
* Homepage:
|
||||
* https://openwall.info/wiki/people/solar/software/public-domain-source-code/md4
|
||||
*
|
||||
* Author:
|
||||
* Alexander Peslyak, better known as Solar Designer <solar at openwall.com>
|
||||
*
|
||||
* This software was written by Alexander Peslyak in 2001. No copyright is
|
||||
* claimed, and the software is hereby placed in the public domain.
|
||||
* In case this attempt to disclaim copyright and place the software in the
|
||||
* public domain is deemed null and void, then the software is
|
||||
* Copyright (c) 2001 Alexander Peslyak and it is hereby released to the
|
||||
* general public under the following terms:
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted.
|
||||
*
|
||||
* There's ABSOLUTELY NO WARRANTY, express or implied.
|
||||
*
|
||||
* See md4.c for more information.
|
||||
*/
|
||||
|
||||
#ifndef _MD4_H
|
||||
#define _MD4_H
|
||||
|
||||
#include <stddef.h> /* for size_t */
|
||||
|
||||
/* Any 32-bit or wider unsigned integer data type will do */
|
||||
typedef unsigned int MD4_u32plus;
|
||||
|
||||
typedef struct {
|
||||
MD4_u32plus lo, hi;
|
||||
MD4_u32plus a, b, c, d;
|
||||
unsigned char buffer[64];
|
||||
#if !(defined(__i386__) || defined(__x86_64__) || defined(__vax__))
|
||||
MD4_u32plus block[16];
|
||||
#endif
|
||||
} MD4_CTX;
|
||||
|
||||
extern void MD4_Init(MD4_CTX *ctx);
|
||||
extern void MD4_Update(MD4_CTX *ctx, const void *data, size_t size);
|
||||
extern void MD4_Final(unsigned char *result, MD4_CTX *ctx);
|
||||
|
||||
#endif
|
||||
287
src/libs/md5.c
287
src/libs/md5.c
@ -1,287 +0,0 @@
|
||||
/*
|
||||
* This is an OpenSSL-compatible implementation of the RSA Data Security, Inc.
|
||||
* MD5 Message-Digest Algorithm (RFC 1321).
|
||||
*
|
||||
* Homepage:
|
||||
* http://openwall.info/wiki/people/solar/software/public-domain-source-code/md5
|
||||
*
|
||||
* Author:
|
||||
* Alexander Peslyak, better known as Solar Designer <solar at openwall.com>
|
||||
*
|
||||
* This software was written by Alexander Peslyak in 2001. No copyright is
|
||||
* claimed, and the software is hereby placed in the public domain.
|
||||
* In case this attempt to disclaim copyright and place the software in the
|
||||
* public domain is deemed null and void, then the software is
|
||||
* Copyright (c) 2001 Alexander Peslyak and it is hereby released to the
|
||||
* general public under the following terms:
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted.
|
||||
*
|
||||
* There's ABSOLUTELY NO WARRANTY, express or implied.
|
||||
*
|
||||
* (This is a heavily cut-down "BSD license".)
|
||||
*
|
||||
* This differs from Colin Plumb's older public domain implementation in that
|
||||
* no exactly 32-bit integer data type is required (any 32-bit or wider
|
||||
* unsigned integer data type will do), there's no compile-time endianness
|
||||
* configuration, and the function prototypes match OpenSSL's. No code from
|
||||
* Colin Plumb's implementation has been reused; this comment merely compares
|
||||
* the properties of the two independent implementations.
|
||||
*
|
||||
* The primary goals of this implementation are portability and ease of use.
|
||||
* It is meant to be fast, but not as fast as possible. Some known
|
||||
* optimizations are not included to reduce source code size and avoid
|
||||
* compile-time configuration.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "md5.h"
|
||||
|
||||
/*
|
||||
* The basic MD5 functions.
|
||||
*
|
||||
* F and G are optimized compared to their RFC 1321 definitions for
|
||||
* architectures that lack an AND-NOT instruction, just like in Colin Plumb's
|
||||
* implementation.
|
||||
*/
|
||||
#define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
|
||||
#define G(x, y, z) ((y) ^ ((z) & ((x) ^ (y))))
|
||||
#define H(x, y, z) (((x) ^ (y)) ^ (z))
|
||||
#define H2(x, y, z) ((x) ^ ((y) ^ (z)))
|
||||
#define I(x, y, z) ((y) ^ ((x) | ~(z)))
|
||||
|
||||
/*
|
||||
* The MD5 transformation for all four rounds.
|
||||
*/
|
||||
#define STEP(f, a, b, c, d, x, t, s) \
|
||||
(a) += f((b), (c), (d)) + (x) + (t); \
|
||||
(a) = (((a) << (s)) | (((a) & 0xffffffff) >> (32 - (s)))); \
|
||||
(a) += (b);
|
||||
|
||||
/*
|
||||
* SET reads 4 input bytes in little-endian byte order and stores them in a
|
||||
* properly aligned word in host byte order.
|
||||
*
|
||||
* The check for little-endian architectures that tolerate unaligned memory
|
||||
* accesses is just an optimization. Nothing will break if it fails to detect
|
||||
* a suitable architecture.
|
||||
*
|
||||
* Unfortunately, this optimization may be a C strict aliasing rules violation
|
||||
* if the caller's data buffer has effective type that cannot be aliased by
|
||||
* MD5_u32plus. In practice, this problem may occur if these MD5 routines are
|
||||
* inlined into a calling function, or with future and dangerously advanced
|
||||
* link-time optimizations. For the time being, keeping these MD5 routines in
|
||||
* their own translation unit avoids the problem.
|
||||
*/
|
||||
#if defined(__i386__) || defined(__x86_64__) || defined(__vax__)
|
||||
#define SET(n) \
|
||||
(*(MD5_u32plus *)&ptr[(n) * 4])
|
||||
#define GET(n) \
|
||||
SET(n)
|
||||
#else
|
||||
#define SET(n) \
|
||||
(ctx->block[(n)] = \
|
||||
(MD5_u32plus)ptr[(n) * 4] | \
|
||||
((MD5_u32plus)ptr[(n) * 4 + 1] << 8) | \
|
||||
((MD5_u32plus)ptr[(n) * 4 + 2] << 16) | \
|
||||
((MD5_u32plus)ptr[(n) * 4 + 3] << 24))
|
||||
#define GET(n) \
|
||||
(ctx->block[(n)])
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This processes one or more 64-byte data blocks, but does NOT update the bit
|
||||
* counters. There are no alignment requirements.
|
||||
*/
|
||||
static const void *body(MD5_CTX *ctx, const void *data, unsigned long size)
|
||||
{
|
||||
const unsigned char *ptr;
|
||||
MD5_u32plus a, b, c, d;
|
||||
MD5_u32plus saved_a, saved_b, saved_c, saved_d;
|
||||
|
||||
ptr = (const unsigned char *)data;
|
||||
|
||||
a = ctx->a;
|
||||
b = ctx->b;
|
||||
c = ctx->c;
|
||||
d = ctx->d;
|
||||
|
||||
do {
|
||||
saved_a = a;
|
||||
saved_b = b;
|
||||
saved_c = c;
|
||||
saved_d = d;
|
||||
|
||||
/* Round 1 */
|
||||
STEP(F, a, b, c, d, SET(0), 0xd76aa478, 7)
|
||||
STEP(F, d, a, b, c, SET(1), 0xe8c7b756, 12)
|
||||
STEP(F, c, d, a, b, SET(2), 0x242070db, 17)
|
||||
STEP(F, b, c, d, a, SET(3), 0xc1bdceee, 22)
|
||||
STEP(F, a, b, c, d, SET(4), 0xf57c0faf, 7)
|
||||
STEP(F, d, a, b, c, SET(5), 0x4787c62a, 12)
|
||||
STEP(F, c, d, a, b, SET(6), 0xa8304613, 17)
|
||||
STEP(F, b, c, d, a, SET(7), 0xfd469501, 22)
|
||||
STEP(F, a, b, c, d, SET(8), 0x698098d8, 7)
|
||||
STEP(F, d, a, b, c, SET(9), 0x8b44f7af, 12)
|
||||
STEP(F, c, d, a, b, SET(10), 0xffff5bb1, 17)
|
||||
STEP(F, b, c, d, a, SET(11), 0x895cd7be, 22)
|
||||
STEP(F, a, b, c, d, SET(12), 0x6b901122, 7)
|
||||
STEP(F, d, a, b, c, SET(13), 0xfd987193, 12)
|
||||
STEP(F, c, d, a, b, SET(14), 0xa679438e, 17)
|
||||
STEP(F, b, c, d, a, SET(15), 0x49b40821, 22)
|
||||
|
||||
/* Round 2 */
|
||||
STEP(G, a, b, c, d, GET(1), 0xf61e2562, 5)
|
||||
STEP(G, d, a, b, c, GET(6), 0xc040b340, 9)
|
||||
STEP(G, c, d, a, b, GET(11), 0x265e5a51, 14)
|
||||
STEP(G, b, c, d, a, GET(0), 0xe9b6c7aa, 20)
|
||||
STEP(G, a, b, c, d, GET(5), 0xd62f105d, 5)
|
||||
STEP(G, d, a, b, c, GET(10), 0x02441453, 9)
|
||||
STEP(G, c, d, a, b, GET(15), 0xd8a1e681, 14)
|
||||
STEP(G, b, c, d, a, GET(4), 0xe7d3fbc8, 20)
|
||||
STEP(G, a, b, c, d, GET(9), 0x21e1cde6, 5)
|
||||
STEP(G, d, a, b, c, GET(14), 0xc33707d6, 9)
|
||||
STEP(G, c, d, a, b, GET(3), 0xf4d50d87, 14)
|
||||
STEP(G, b, c, d, a, GET(8), 0x455a14ed, 20)
|
||||
STEP(G, a, b, c, d, GET(13), 0xa9e3e905, 5)
|
||||
STEP(G, d, a, b, c, GET(2), 0xfcefa3f8, 9)
|
||||
STEP(G, c, d, a, b, GET(7), 0x676f02d9, 14)
|
||||
STEP(G, b, c, d, a, GET(12), 0x8d2a4c8a, 20)
|
||||
|
||||
/* Round 3 */
|
||||
STEP(H, a, b, c, d, GET(5), 0xfffa3942, 4)
|
||||
STEP(H2, d, a, b, c, GET(8), 0x8771f681, 11)
|
||||
STEP(H, c, d, a, b, GET(11), 0x6d9d6122, 16)
|
||||
STEP(H2, b, c, d, a, GET(14), 0xfde5380c, 23)
|
||||
STEP(H, a, b, c, d, GET(1), 0xa4beea44, 4)
|
||||
STEP(H2, d, a, b, c, GET(4), 0x4bdecfa9, 11)
|
||||
STEP(H, c, d, a, b, GET(7), 0xf6bb4b60, 16)
|
||||
STEP(H2, b, c, d, a, GET(10), 0xbebfbc70, 23)
|
||||
STEP(H, a, b, c, d, GET(13), 0x289b7ec6, 4)
|
||||
STEP(H2, d, a, b, c, GET(0), 0xeaa127fa, 11)
|
||||
STEP(H, c, d, a, b, GET(3), 0xd4ef3085, 16)
|
||||
STEP(H2, b, c, d, a, GET(6), 0x04881d05, 23)
|
||||
STEP(H, a, b, c, d, GET(9), 0xd9d4d039, 4)
|
||||
STEP(H2, d, a, b, c, GET(12), 0xe6db99e5, 11)
|
||||
STEP(H, c, d, a, b, GET(15), 0x1fa27cf8, 16)
|
||||
STEP(H2, b, c, d, a, GET(2), 0xc4ac5665, 23)
|
||||
|
||||
/* Round 4 */
|
||||
STEP(I, a, b, c, d, GET(0), 0xf4292244, 6)
|
||||
STEP(I, d, a, b, c, GET(7), 0x432aff97, 10)
|
||||
STEP(I, c, d, a, b, GET(14), 0xab9423a7, 15)
|
||||
STEP(I, b, c, d, a, GET(5), 0xfc93a039, 21)
|
||||
STEP(I, a, b, c, d, GET(12), 0x655b59c3, 6)
|
||||
STEP(I, d, a, b, c, GET(3), 0x8f0ccc92, 10)
|
||||
STEP(I, c, d, a, b, GET(10), 0xffeff47d, 15)
|
||||
STEP(I, b, c, d, a, GET(1), 0x85845dd1, 21)
|
||||
STEP(I, a, b, c, d, GET(8), 0x6fa87e4f, 6)
|
||||
STEP(I, d, a, b, c, GET(15), 0xfe2ce6e0, 10)
|
||||
STEP(I, c, d, a, b, GET(6), 0xa3014314, 15)
|
||||
STEP(I, b, c, d, a, GET(13), 0x4e0811a1, 21)
|
||||
STEP(I, a, b, c, d, GET(4), 0xf7537e82, 6)
|
||||
STEP(I, d, a, b, c, GET(11), 0xbd3af235, 10)
|
||||
STEP(I, c, d, a, b, GET(2), 0x2ad7d2bb, 15)
|
||||
STEP(I, b, c, d, a, GET(9), 0xeb86d391, 21)
|
||||
|
||||
a += saved_a;
|
||||
b += saved_b;
|
||||
c += saved_c;
|
||||
d += saved_d;
|
||||
|
||||
ptr += 64;
|
||||
} while (size -= 64);
|
||||
|
||||
ctx->a = a;
|
||||
ctx->b = b;
|
||||
ctx->c = c;
|
||||
ctx->d = d;
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void MD5_Init(MD5_CTX *ctx)
|
||||
{
|
||||
ctx->a = 0x67452301;
|
||||
ctx->b = 0xefcdab89;
|
||||
ctx->c = 0x98badcfe;
|
||||
ctx->d = 0x10325476;
|
||||
|
||||
ctx->lo = 0;
|
||||
ctx->hi = 0;
|
||||
}
|
||||
|
||||
void MD5_Update(MD5_CTX *ctx, const void *data, unsigned long size)
|
||||
{
|
||||
MD5_u32plus saved_lo;
|
||||
unsigned long used, available;
|
||||
|
||||
saved_lo = ctx->lo;
|
||||
if ((ctx->lo = (saved_lo + size) & 0x1fffffff) < saved_lo)
|
||||
ctx->hi++;
|
||||
ctx->hi += size >> 29;
|
||||
|
||||
used = saved_lo & 0x3f;
|
||||
|
||||
if (used) {
|
||||
available = 64 - used;
|
||||
|
||||
if (size < available) {
|
||||
memcpy(&ctx->buffer[used], data, size);
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(&ctx->buffer[used], data, available);
|
||||
data = (const unsigned char *)data + available;
|
||||
size -= available;
|
||||
body(ctx, ctx->buffer, 64);
|
||||
}
|
||||
|
||||
if (size >= 64) {
|
||||
data = body(ctx, data, size & ~(unsigned long)0x3f);
|
||||
size &= 0x3f;
|
||||
}
|
||||
|
||||
memcpy(ctx->buffer, data, size);
|
||||
}
|
||||
|
||||
#define OUT(dst, src) \
|
||||
(dst)[0] = (unsigned char)(src); \
|
||||
(dst)[1] = (unsigned char)((src) >> 8); \
|
||||
(dst)[2] = (unsigned char)((src) >> 16); \
|
||||
(dst)[3] = (unsigned char)((src) >> 24);
|
||||
|
||||
void MD5_Final(unsigned char *result, MD5_CTX *ctx)
|
||||
{
|
||||
unsigned long used, available;
|
||||
|
||||
used = ctx->lo & 0x3f;
|
||||
|
||||
ctx->buffer[used++] = 0x80;
|
||||
|
||||
available = 64 - used;
|
||||
|
||||
if (available < 8) {
|
||||
memset(&ctx->buffer[used], 0, available);
|
||||
body(ctx, ctx->buffer, 64);
|
||||
used = 0;
|
||||
available = 64;
|
||||
}
|
||||
|
||||
memset(&ctx->buffer[used], 0, available - 8);
|
||||
|
||||
ctx->lo <<= 3;
|
||||
OUT(&ctx->buffer[56], ctx->lo)
|
||||
OUT(&ctx->buffer[60], ctx->hi)
|
||||
|
||||
body(ctx, ctx->buffer, 64);
|
||||
|
||||
OUT(&result[0], ctx->a)
|
||||
OUT(&result[4], ctx->b)
|
||||
OUT(&result[8], ctx->c)
|
||||
OUT(&result[12], ctx->d)
|
||||
|
||||
memset(ctx, 0, sizeof(*ctx));
|
||||
}
|
||||
@ -1,43 +0,0 @@
|
||||
/*
|
||||
* This is an OpenSSL-compatible implementation of the RSA Data Security, Inc.
|
||||
* MD5 Message-Digest Algorithm (RFC 1321).
|
||||
*
|
||||
* Homepage:
|
||||
* http://openwall.info/wiki/people/solar/software/public-domain-source-code/md5
|
||||
*
|
||||
* Author:
|
||||
* Alexander Peslyak, better known as Solar Designer <solar at openwall.com>
|
||||
*
|
||||
* This software was written by Alexander Peslyak in 2001. No copyright is
|
||||
* claimed, and the software is hereby placed in the public domain.
|
||||
* In case this attempt to disclaim copyright and place the software in the
|
||||
* public domain is deemed null and void, then the software is
|
||||
* Copyright (c) 2001 Alexander Peslyak and it is hereby released to the
|
||||
* general public under the following terms:
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted.
|
||||
*
|
||||
* There's ABSOLUTELY NO WARRANTY, express or implied.
|
||||
*
|
||||
* See md5.c for more information.
|
||||
*/
|
||||
|
||||
#ifndef _MD5_H
|
||||
#define _MD5_H
|
||||
|
||||
/* Any 32-bit or wider unsigned integer data type will do */
|
||||
typedef unsigned int MD5_u32plus;
|
||||
|
||||
typedef struct {
|
||||
MD5_u32plus lo, hi;
|
||||
MD5_u32plus a, b, c, d;
|
||||
unsigned char buffer[64];
|
||||
MD5_u32plus block[16];
|
||||
} MD5_CTX;
|
||||
|
||||
extern void MD5_Init(MD5_CTX *ctx);
|
||||
extern void MD5_Update(MD5_CTX *ctx, const void *data, unsigned long size);
|
||||
extern void MD5_Final(unsigned char *result, MD5_CTX *ctx);
|
||||
|
||||
#endif
|
||||
132
src/mdhash.c
132
src/mdhash.c
@ -1,132 +0,0 @@
|
||||
/*
|
||||
3APA3A simplest proxy server
|
||||
(c) 2002-2026 by Vladimir Dubrovin <vlad@3proxy.org>
|
||||
|
||||
please read License Agreement
|
||||
|
||||
MD4/MD5 hash implementation.
|
||||
- Windows: CryptoAPI (CAPI). Supports both CALG_MD4 and CALG_MD5.
|
||||
- Other platforms: bundled public-domain MD4/MD5 (Solar Designer, 2001).
|
||||
*/
|
||||
#include "mdhash.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <wincrypt.h>
|
||||
|
||||
struct mdh_ctx {
|
||||
HCRYPTPROV hProv;
|
||||
HCRYPTHASH hHash;
|
||||
};
|
||||
|
||||
mdh_ctx *mdh_init(mdh_alg alg)
|
||||
{
|
||||
mdh_ctx *c;
|
||||
ALG_ID alg_id;
|
||||
|
||||
c = (mdh_ctx *)malloc(sizeof(mdh_ctx));
|
||||
if(!c) return NULL;
|
||||
c->hProv = 0;
|
||||
c->hHash = 0;
|
||||
|
||||
if(!CryptAcquireContext(&c->hProv, NULL, NULL, PROV_RSA_FULL,
|
||||
CRYPT_VERIFYCONTEXT)) {
|
||||
free(c);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
alg_id = (alg == MDH_MD4) ? CALG_MD4 : CALG_MD5;
|
||||
if(!CryptCreateHash(c->hProv, alg_id, 0, 0, &c->hHash)) {
|
||||
CryptReleaseContext(c->hProv, 0);
|
||||
free(c);
|
||||
return NULL;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
int mdh_update(mdh_ctx *c, const void *data, unsigned int len)
|
||||
{
|
||||
if(!c || !c->hHash) return 0;
|
||||
if(len == 0) return 1;
|
||||
return CryptHashData(c->hHash, (BYTE *)data, len, 0) ? 1 : 0;
|
||||
}
|
||||
|
||||
int mdh_final(mdh_ctx *c, unsigned char *out, unsigned int *outlen)
|
||||
{
|
||||
DWORD l;
|
||||
BOOL ok;
|
||||
|
||||
if(!c || !c->hHash || !outlen) return 0;
|
||||
l = (DWORD)*outlen;
|
||||
ok = CryptGetHashParam(c->hHash, HP_HASHVAL, out, &l, 0);
|
||||
if(!ok) return 0;
|
||||
*outlen = (unsigned int)l;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void mdh_free(mdh_ctx *c)
|
||||
{
|
||||
if(!c) return;
|
||||
if(c->hHash) CryptDestroyHash(c->hHash);
|
||||
if(c->hProv) CryptReleaseContext(c->hProv, 0);
|
||||
free(c);
|
||||
}
|
||||
|
||||
#else /* !_WIN32 */
|
||||
|
||||
#include "libs/md4.h"
|
||||
#include "libs/md5.h"
|
||||
#include <string.h>
|
||||
|
||||
struct mdh_ctx {
|
||||
int alg; /* MDH_MD4 or MDH_MD5 */
|
||||
union {
|
||||
MD4_CTX md4;
|
||||
MD5_CTX md5;
|
||||
} u;
|
||||
};
|
||||
|
||||
mdh_ctx *mdh_init(mdh_alg alg)
|
||||
{
|
||||
mdh_ctx *c = (mdh_ctx *)malloc(sizeof(mdh_ctx));
|
||||
if(!c) return NULL;
|
||||
c->alg = alg;
|
||||
if(alg == MDH_MD4)
|
||||
MD4_Init(&c->u.md4);
|
||||
else
|
||||
MD5_Init(&c->u.md5);
|
||||
return c;
|
||||
}
|
||||
|
||||
int mdh_update(mdh_ctx *c, const void *data, unsigned int len)
|
||||
{
|
||||
if(!c) return 0;
|
||||
if(c->alg == MDH_MD4)
|
||||
MD4_Update(&c->u.md4, data, (size_t)len);
|
||||
else
|
||||
MD5_Update(&c->u.md5, data, (unsigned long)len);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int mdh_final(mdh_ctx *c, unsigned char *out, unsigned int *outlen)
|
||||
{
|
||||
if(!c || !outlen) return 0;
|
||||
if(c->alg == MDH_MD4)
|
||||
MD4_Final(out, &c->u.md4);
|
||||
else
|
||||
MD5_Final(out, &c->u.md5);
|
||||
*outlen = 16;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void mdh_free(mdh_ctx *c)
|
||||
{
|
||||
if(!c) return;
|
||||
memset(c, 0, sizeof(*c));
|
||||
free(c);
|
||||
}
|
||||
|
||||
#endif /* _WIN32 */
|
||||
31
src/mdhash.h
31
src/mdhash.h
@ -1,31 +0,0 @@
|
||||
/*
|
||||
3APA3A simplest proxy server
|
||||
(c) 2002-2026 by Vladimir Dubrovin <vlad@3proxy.org>
|
||||
|
||||
please read License Agreement
|
||||
|
||||
Internal MD4/MD5 hash abstraction.
|
||||
- Windows: CryptoAPI (CAPI) backed, no OpenSSL dependency for these hashes.
|
||||
- Other platforms: OpenSSL EVP backed (requires WITH_SSL).
|
||||
*/
|
||||
#ifndef _MDHASH_H
|
||||
#define _MDHASH_H
|
||||
|
||||
typedef enum { MDH_MD4, MDH_MD5 } mdh_alg;
|
||||
|
||||
typedef struct mdh_ctx mdh_ctx;
|
||||
|
||||
/* Returns NULL on failure. */
|
||||
mdh_ctx *mdh_init(mdh_alg alg);
|
||||
|
||||
/* Returns 1 on success, 0 on failure. */
|
||||
int mdh_update(mdh_ctx *c, const void *data, unsigned int len);
|
||||
|
||||
/* outlen is in/out: caller passes buffer size, receives hash length.
|
||||
Returns 1 on success, 0 on failure. */
|
||||
int mdh_final(mdh_ctx *c, unsigned char *out, unsigned int *outlen);
|
||||
|
||||
/* Safe to call with NULL. */
|
||||
void mdh_free(mdh_ctx *c);
|
||||
|
||||
#endif /* _MDHASH_H */
|
||||
@ -240,7 +240,9 @@ extern int paused;
|
||||
extern int demon;
|
||||
|
||||
unsigned char * mycrypt(const unsigned char *key, const unsigned char *salt, unsigned char *buf);
|
||||
#ifdef WITH_SSL
|
||||
unsigned char * ntpwdhash (unsigned char *szHash, const unsigned char *szPassword, int tohex);
|
||||
#endif
|
||||
int de64 (const unsigned char *in, unsigned char *out, int maxlen);
|
||||
unsigned char* en64 (const unsigned char *in, unsigned char *out, int inlen);
|
||||
void tohex(unsigned char *in, unsigned char *out, int len);
|
||||
|
||||
15
src/ssllib.c
15
src/ssllib.c
@ -280,6 +280,12 @@ int ssl_file_init = 0;
|
||||
|
||||
int ssl_init_done = 0;
|
||||
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
|
||||
extern EVP_MD *md4_hash;
|
||||
extern EVP_MD *md5_hash;
|
||||
#endif
|
||||
|
||||
|
||||
void ssl_init()
|
||||
{
|
||||
if(!ssl_init_done){
|
||||
@ -291,7 +297,16 @@ void ssl_init()
|
||||
_3proxy_mutex_init(&ssl_file_mutex);
|
||||
bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
|
||||
OSSL_PROVIDER_load(NULL, "legacy");
|
||||
OSSL_PROVIDER_load(NULL, "default");
|
||||
md4_hash = EVP_MD_fetch(NULL, "MD4", NULL);
|
||||
if (md4_hash == NULL) {
|
||||
fprintf(stderr, "Error fetching MD4\n");
|
||||
}
|
||||
md5_hash = EVP_MD_fetch(NULL, "MD5", NULL);
|
||||
if (md5_hash == NULL) {
|
||||
fprintf(stderr, "Error fetching MD5\n");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user