Index: isakmpd-20041012.orig/GNUmakefile
===================================================================
--- isakmpd-20041012.orig.orig/GNUmakefile	2007-06-04 13:22:39.722816496 +0200
+++ isakmpd-20041012.orig/GNUmakefile	2007-06-04 13:22:40.000774240 +0200
@@ -76,13 +76,14 @@
 		isakmp_fld.c isakmp_fld.h
 MAN=		isakmpd.8 isakmpd.conf.5 isakmpd.policy.5
 
-CFLAGS+=	-O2 ${DEBUG} -Wall -DNEED_SYSDEP_APP \
+CFLAGS+=	${DEBUG} -Wall -DNEED_SYSDEP_APP \
 		-I${.CURDIR} -I${.CURDIR}/sysdep/${OS} -I. \
 
 # Different debugging & profiling suggestions
 
 # Include symbolic debugging info
 DEBUG=		-g
+CFLAGS+=	-g
 
 # Do execution time profiles
 #CFLAGS+=	-pg
@@ -175,6 +176,14 @@
 CFLAGS+=        -DUSE_RAWKEY
 endif
 
+ifdef USE_OPENSSL_MD5
+CFLAGS+=	-DUSE_OPENSSL_MD5
+endif
+
+ifdef USE_OPENSSL_SHA1
+CFLAGS+=	-DUSE_OPENSSL_SHA1
+endif
+
 SRCS+=		${IPSEC_SRCS} ${X509} ${POLICY} ${EC} ${AGGRESSIVE} ${DNSSEC} \
 			$(ISAKMP_CFG) ${DPD} ${NAT_TRAVERSAL}
 CFLAGS+=	${IPSEC_CFLAGS}
Index: isakmpd-20041012.orig/sysdep/common/libsysdep/GNUmakefile
===================================================================
--- isakmpd-20041012.orig.orig/sysdep/common/libsysdep/GNUmakefile	2007-06-04 13:22:38.959932472 +0200
+++ isakmpd-20041012.orig/sysdep/common/libsysdep/GNUmakefile	2007-06-04 13:22:40.000774240 +0200
@@ -31,10 +31,18 @@
 .CURDIR:=	$(shell pwd)
 
 LIB=		sysdep
-SRCS=		arc4random.c blowfish.c cast.c md5.c sha1.c strlcat.c strlcpy.c
+SRCS=		arc4random.c blowfish.c cast.c strlcat.c strlcpy.c
 NOMAN=
 CFLAGS+=	-I${.CURDIR}/.. -I/usr/include/machine
 
+ifeq (,$(findstring USE_OPENSSL_MD5,$(CFLAGS)))
+SRCS+=md5.c
+endif
+
+ifeq (,$(findstring USE_OPENSSL_SHA1,$(CFLAGS)))
+SRCS+=sha1.c
+endif
+
 lib${LIB}.a: ${SRCS:%.c=%.o}
 	ar cq $@ ${SRCS:%.c=%.o}
 
Index: isakmpd-20041012.orig/sysdep/common/libsysdep/md5.c
===================================================================
--- isakmpd-20041012.orig.orig/sysdep/common/libsysdep/md5.c	2007-06-04 13:22:38.964931712 +0200
+++ isakmpd-20041012.orig/sysdep/common/libsysdep/md5.c	2007-06-04 13:22:40.000774240 +0200
@@ -5,6 +5,8 @@
  * changes to accommodate it in the kernel by ji.
  */
 
+#ifndef USE_OPENSSL_MD5
+
 /* MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm
  */
 
@@ -390,3 +392,4 @@
 #endif
 #endif
 
+#endif /* USE_OPENSSL_MD5 */
Index: isakmpd-20041012.orig/sysdep/common/libsysdep/sha1.c
===================================================================
--- isakmpd-20041012.orig.orig/sysdep/common/libsysdep/sha1.c	2007-06-04 13:22:38.970930800 +0200
+++ isakmpd-20041012.orig/sysdep/common/libsysdep/sha1.c	2007-06-04 13:22:40.001774088 +0200
@@ -1,5 +1,7 @@
 /*	$OpenBSD: sha1.c,v 1.2 2001/01/28 22:38:48 niklas Exp $	*/
 
+#ifndef USE_OPENSSL_SHA1
+
 /*
 SHA-1 in C
 By Steve Reid <steve@edmweb.com>
@@ -171,3 +173,5 @@
     SHA1Transform(context->state, context->buffer);
 #endif
 }
+
+#endif /* USE_OPENSSL_SHA1 */
Index: isakmpd-20041012.orig/sysdep/common/md5.h
===================================================================
--- isakmpd-20041012.orig.orig/sysdep/common/md5.h	2007-06-04 13:22:38.976929888 +0200
+++ isakmpd-20041012.orig/sysdep/common/md5.h	2007-06-04 13:22:40.001774088 +0200
@@ -1,5 +1,15 @@
 /*	$OpenBSD: md5.h,v 1.2 2001/01/28 22:38:47 niklas Exp $	*/
 
+#ifdef USE_OPENSSL_MD5
+
+#include <openssl/md5.h>
+
+#define MD5Init		MD5_Init
+#define	MD5Update	MD5_Update
+#define	MD5Final	MD5_Final
+
+#else	/* USE_OPENSSL_MD5 */
+
 /* GLOBAL.H - RSAREF types and constants
  */
 
@@ -71,3 +81,5 @@
 void MD5Final PROTO_LIST ((unsigned char [16], MD5_CTX *));
 
 #define _MD5_H_
+
+#endif	/* USE_OPENSSL_MD5 */
Index: isakmpd-20041012.orig/sysdep/common/sha1.h
===================================================================
--- isakmpd-20041012.orig.orig/sysdep/common/sha1.h	2007-06-04 13:22:38.982928976 +0200
+++ isakmpd-20041012.orig/sysdep/common/sha1.h	2007-06-04 13:22:40.001774088 +0200
@@ -1,5 +1,16 @@
 /*	$OpenBSD: sha1.h,v 1.2 2001/01/28 22:38:47 niklas Exp $	*/
 
+#ifdef USE_OPENSSL_SHA1
+
+#include <openssl/sha.h>
+
+typedef SHA_CTX SHA1_CTX;
+#define	SHA1Init	SHA1_Init
+#define	SHA1Update	SHA1_Update
+#define	SHA1Final	SHA1_Final
+
+#else	/* USE_OPENSSL_SHA1 */
+
 /*
 SHA-1 in C
 By Steve Reid <steve@edmweb.com>
@@ -16,3 +27,5 @@
 void SHA1Init(SHA1_CTX* context);
 void SHA1Update(SHA1_CTX* context, unsigned char* data, unsigned int len);
 void SHA1Final(unsigned char digest[20], SHA1_CTX* context);
+
+#endif	/* USE_OPENSSL_SHA1 */
Index: isakmpd-20041012.orig/sysdep/linux/GNUmakefile.sysdep
===================================================================
--- isakmpd-20041012.orig.orig/sysdep/linux/GNUmakefile.sysdep	2007-06-04 13:22:39.722816496 +0200
+++ isakmpd-20041012.orig/sysdep/linux/GNUmakefile.sysdep	2007-06-04 13:22:40.001774088 +0200
@@ -47,6 +47,8 @@
 USE_LIBCRYPO=	defined
 HAVE_DLOPEN=	defined
 USE_KEYNOTE=	defined
+USE_OPENSSL_MD5=	defined
+USE_OPENSSL_SHA1=	defined
 
 # hack libsysdep.a dependenc
 ${LIBSYSDEPDIR}/.depend ${LIBSYSDEP}:
