Skip to content

Commit

Permalink
Added Windows Cryptography API: Next Generation based backend
Browse files Browse the repository at this point in the history
  • Loading branch information
mback2k authored and Peter Stuge committed Mar 16, 2014
1 parent 378d0a6 commit 4440e05
Show file tree
Hide file tree
Showing 6 changed files with 2,151 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Makefile.WinCNG.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CRYPTO_CSOURCES = wincng.c
CRYPTO_HHEADERS = wincng.h
30 changes: 30 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ AC_ARG_WITH(openssl,
AC_ARG_WITH(libgcrypt,
AC_HELP_STRING([--with-libgcrypt],[Use libgcrypt for crypto]),
use_libgcrypt=$withval,use_libgcrypt=auto)
AC_ARG_WITH(wincng,
AC_HELP_STRING([--with-wincng],[Use Windows CNG for crypto]),
use_wincng=$withval,use_wincng=auto)
AC_ARG_WITH(libz,
AC_HELP_STRING([--with-libz],[Use zlib for compression]),
use_libz=$withval,use_libz=auto)
Expand Down Expand Up @@ -125,10 +128,37 @@ if test "$ac_cv_libgcrypt" = "yes"; then
fi
AM_CONDITIONAL(LIBGCRYPT, test "$ac_cv_libgcrypt" = "yes")

# Look for Windows Cryptography API: Next Generation
if test "$found_crypto" = "none" && test "$use_wincng" != "no"; then
AC_LIB_HAVE_LINKFLAGS([bcrypt], [], [
#include <windows.h>
#include <bcrypt.h>
])
AC_LIB_HAVE_LINKFLAGS([crypt32], [], [
#include <windows.h>
#include <wincrypt.h>
])
AC_CHECK_HEADERS([ntdef.h ntstatus.h], [], [], [
#include <windows.h>
])
fi
if test "$ac_cv_libbcrypt" = "yes"; then
AC_DEFINE(LIBSSH2_WINCNG, 1, [Use Windows CNG])
LIBSREQUIRED= # wincng doesn't provide a .pc file. sad face.
LIBS="$LIBS -lbcrypt"
if test "$ac_cv_libcrypt32" = "yes"; then
LIBS="$LIBS -lcrypt32"
fi
found_crypto="Windows Cryptography API: Next Generation"
fi
AM_CONDITIONAL(WINCNG, test "$ac_cv_libbcrypt" = "yes")

# Check if crypto library was found
if test "$found_crypto" = "none"; then
AC_MSG_ERROR([No crypto library found!
Try --with-libssl-prefix=PATH\
or --with-libgcrypt-prefix=PATH\
or --with-wincng on Windows\
])
fi

Expand Down
3 changes: 3 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ endif
if LIBGCRYPT
include ../Makefile.libgcrypt.inc
endif
if WINCNG
include ../Makefile.WinCNG.inc
endif

# Makefile.inc provides the CSOURCES and HHEADERS defines
include ../Makefile.inc
Expand Down
4 changes: 4 additions & 0 deletions src/crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
#include "libgcrypt.h"
#endif

#ifdef LIBSSH2_WINCNG
#include "wincng.h"
#endif

int _libssh2_rsa_new(libssh2_rsa_ctx ** rsa,
const unsigned char *edata,
unsigned long elen,
Expand Down
Loading

0 comments on commit 4440e05

Please sign in to comment.