[7/8] bcrypt: Add support for SHA hashes on Linux using Nettle.
Hans Leidekker
hans at codeweavers.com
Wed Jan 6 07:19:20 CST 2016
Signed-off-by: Hans Leidekker <hans at codeweavers.com>
---
configure.ac | 18 +++++++++
dlls/bcrypt/Makefile.in | 1 +
dlls/bcrypt/bcrypt_main.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 114 insertions(+)
diff --git a/configure.ac b/configure.ac
index 2b1dd81..22eb860 100644
--- a/configure.ac
+++ b/configure.ac
@@ -59,6 +59,7 @@ AC_ARG_WITH(jpeg, AS_HELP_STRING([--without-jpeg],[do not use JPEG]))
AC_ARG_WITH(ldap, AS_HELP_STRING([--without-ldap],[do not use LDAP]),
[if test "x$withval" = "xno"; then ac_cv_header_ldap_h=no; ac_cv_header_lber_h=no; fi])
AC_ARG_WITH(mpg123, AS_HELP_STRING([--without-mpg123],[do not use the mpg123 library]))
+AC_ARG_WITH(nettle, AS_HELP_STRING([--without-nettle],[do not use Nettle]))
AC_ARG_WITH(netapi, AS_HELP_STRING([--without-netapi],[do not use the Samba NetAPI library]))
AC_ARG_WITH(openal, AS_HELP_STRING([--without-openal],[do not use OpenAL]),
[if test "x$withval" = "xno"; then ac_cv_header_AL_al_h=no; ac_cv_header_OpenAL_al_h=no; fi])
@@ -1274,6 +1275,23 @@ fi
WINE_WARNING_WITH(gnutls,[test "x$ac_cv_lib_soname_gnutls" = "x"],
[libgnutls ${notice_platform}development files not found, no schannel support.])
+dnl **** Check for libnettle ***
+if test "x$with_nettle" != "xno"
+then
+ WINE_PACKAGE_FLAGS(NETTLE,[nettle],[-lnettle],,,
+ [AC_CHECK_HEADERS([nettle/sha2.h])
+ if test "$ac_cv_header_nettle_sha2_h" = "yes"
+ then
+ AC_CHECK_LIB(nettle, nettle_sha512_init,
+ [AC_DEFINE(HAVE_NETTLE, 1, [Define if you have Nettle development environment])],[NETTLE_LIBS=""],[$NETTLE_LIBS])
+ else
+ NETTLE_CFLAGS=""
+ NETTLE_LIBS=""
+ fi])
+fi
+WINE_NOTICE_WITH(nettle,[test "$ac_cv_lib_nettle_nettle_sha512_init" != "yes"],
+ [libnettle ${notice_platform}development files not found, no crypto support (bcrypt).])
+
dnl **** Check which curses lib to use ***
CURSES_LIBS=""
if test "$ac_cv_header_ncurses_h" = "yes"
diff --git a/dlls/bcrypt/Makefile.in b/dlls/bcrypt/Makefile.in
index 87e1429..f0271fa 100644
--- a/dlls/bcrypt/Makefile.in
+++ b/dlls/bcrypt/Makefile.in
@@ -1,5 +1,6 @@
MODULE = bcrypt.dll
IMPORTS = advapi32
+EXTRALIBS = $(NETTLE_LIBS)
C_SRCS = \
bcrypt_main.c
diff --git a/dlls/bcrypt/bcrypt_main.c b/dlls/bcrypt/bcrypt_main.c
index 9cc5227..4c567e9 100644
--- a/dlls/bcrypt/bcrypt_main.c
+++ b/dlls/bcrypt/bcrypt_main.c
@@ -22,6 +22,9 @@
#include <stdarg.h>
#ifdef HAVE_COMMONCRYPTO_COMMONDIGEST_H
#include <CommonCrypto/CommonDigest.h>
+#elif HAVE_NETTLE
+#include <nettle/sha1.h>
+#include <nettle/sha2.h>
#endif
#include "ntstatus.h"
@@ -255,6 +258,98 @@ static NTSTATUS hash_finish( struct hash *hash, UCHAR *output, ULONG size )
}
return STATUS_SUCCESS;
}
+#elif HAVE_NETTLE
+struct hash
+{
+ struct object hdr;
+ enum alg_id alg_id;
+ union
+ {
+ struct sha1_ctx sha1_ctx;
+ struct sha256_ctx sha256_ctx;
+ struct sha512_ctx sha512_ctx;
+ } u;
+};
+
+static NTSTATUS hash_init( struct hash *hash )
+{
+ switch (hash->alg_id)
+ {
+ case ALG_ID_SHA1:
+ nettle_sha1_init( &hash->u.sha1_ctx );
+ break;
+
+ case ALG_ID_SHA256:
+ nettle_sha256_init( &hash->u.sha256_ctx );
+ break;
+
+ case ALG_ID_SHA384:
+ nettle_sha384_init( &hash->u.sha512_ctx );
+ break;
+
+ case ALG_ID_SHA512:
+ nettle_sha512_init( &hash->u.sha512_ctx );
+ break;
+
+ default:
+ ERR( "unhandled id %u\n", hash->alg_id );
+ return STATUS_NOT_IMPLEMENTED;
+ }
+ return STATUS_SUCCESS;
+}
+
+static void hash_update( struct hash *hash, UCHAR *input, ULONG size )
+{
+ switch (hash->alg_id)
+ {
+ case ALG_ID_SHA1:
+ nettle_sha1_update( &hash->u.sha1_ctx, size, input );
+ break;
+
+ case ALG_ID_SHA256:
+ nettle_sha256_update( &hash->u.sha256_ctx, size, input );
+ break;
+
+ case ALG_ID_SHA384:
+ nettle_sha512_update( &hash->u.sha512_ctx, size, input );
+ break;
+
+ case ALG_ID_SHA512:
+ nettle_sha512_update( &hash->u.sha512_ctx, size, input );
+ break;
+
+ default:
+ ERR( "unhandled id %u\n", hash->alg_id );
+ break;
+ }
+}
+
+static NTSTATUS hash_finish( struct hash *hash, UCHAR *output, ULONG size )
+{
+ switch (hash->alg_id)
+ {
+ case ALG_ID_SHA1:
+ nettle_sha1_digest( &hash->u.sha1_ctx, size, output );
+ break;
+
+ case ALG_ID_SHA256:
+ nettle_sha256_digest( &hash->u.sha256_ctx, size, output );
+ break;
+
+ case ALG_ID_SHA384:
+ nettle_sha384_digest( &hash->u.sha512_ctx, size, output );
+ break;
+
+ case ALG_ID_SHA512:
+ nettle_sha512_digest( &hash->u.sha512_ctx, size, output );
+ break;
+
+ default:
+ ERR( "unhandled id %u\n", hash->alg_id );
+ break;
+ }
+ return STATUS_SUCCESS;
+}
#else
struct hash
{
--
2.6.4
More information about the wine-patches
mailing list