Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-cw
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wine
wine-cw
Commits
2cd8d273
Commit
2cd8d273
authored
Jan 13, 2016
by
Hans Leidekker
Committed by
Alexandre Julliard
Jan 13, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bcrypt: Add support for SHA hashes on Linux using GnuTLS.
Signed-off-by:
Hans Leidekker
<
hans@codeweavers.com
>
Signed-off-by:
Alexandre Julliard
<
julliard@winehq.org
>
parent
9cc07a2b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
163 additions
and
5 deletions
+163
-5
Makefile.in
dlls/bcrypt/Makefile.in
+1
-0
bcrypt_main.c
dlls/bcrypt/bcrypt_main.c
+162
-5
No files found.
dlls/bcrypt/Makefile.in
View file @
2cd8d273
MODULE
=
bcrypt.dll
MODULE
=
bcrypt.dll
IMPORTS
=
advapi32
IMPORTS
=
advapi32
EXTRAINCL
=
$(GNUTLS_CFLAGS)
C_SRCS
=
\
C_SRCS
=
\
bcrypt_main.c
bcrypt_main.c
...
...
dlls/bcrypt/bcrypt_main.c
View file @
2cd8d273
...
@@ -18,10 +18,14 @@
...
@@ -18,10 +18,14 @@
*/
*/
#include "config.h"
#include "config.h"
#include "wine/port.h"
#include <stdarg.h>
#include <stdarg.h>
#ifdef HAVE_COMMONCRYPTO_COMMONDIGEST_H
#ifdef HAVE_COMMONCRYPTO_COMMONDIGEST_H
#include <CommonCrypto/CommonDigest.h>
#include <CommonCrypto/CommonDigest.h>
#elif defined(SONAME_LIBGNUTLS)
#include <gnutls/gnutls.h>
#include <gnutls/crypto.h>
#endif
#endif
#include "ntstatus.h"
#include "ntstatus.h"
...
@@ -32,10 +36,88 @@
...
@@ -32,10 +36,88 @@
#include "bcrypt.h"
#include "bcrypt.h"
#include "wine/debug.h"
#include "wine/debug.h"
#include "wine/library.h"
#include "wine/unicode.h"
#include "wine/unicode.h"
WINE_DEFAULT_DEBUG_CHANNEL
(
bcrypt
);
WINE_DEFAULT_DEBUG_CHANNEL
(
bcrypt
);
static
HINSTANCE
instance
;
#if defined(SONAME_LIBGNUTLS) && !defined(HAVE_COMMONCRYPTO_COMMONDIGEST_H)
WINE_DECLARE_DEBUG_CHANNEL
(
winediag
);
static
void
*
libgnutls_handle
;
#define MAKE_FUNCPTR(f) static typeof(f) * p##f
MAKE_FUNCPTR
(
gnutls_global_deinit
);
MAKE_FUNCPTR
(
gnutls_global_init
);
MAKE_FUNCPTR
(
gnutls_global_set_log_function
);
MAKE_FUNCPTR
(
gnutls_global_set_log_level
);
MAKE_FUNCPTR
(
gnutls_hash
);
MAKE_FUNCPTR
(
gnutls_hash_deinit
);
MAKE_FUNCPTR
(
gnutls_hash_init
);
MAKE_FUNCPTR
(
gnutls_perror
);
#undef MAKE_FUNCPTR
static
void
gnutls_log
(
int
level
,
const
char
*
msg
)
{
TRACE
(
"<%d> %s"
,
level
,
msg
);
}
static
BOOL
gnutls_initialize
(
void
)
{
int
ret
;
if
(
!
(
libgnutls_handle
=
wine_dlopen
(
SONAME_LIBGNUTLS
,
RTLD_NOW
,
NULL
,
0
)))
{
ERR_
(
winediag
)(
"failed to load libgnutls, no support for crypto hashes
\n
"
);
return
FALSE
;
}
#define LOAD_FUNCPTR(f) \
if (!(p##f = wine_dlsym( libgnutls_handle, #f, NULL, 0 ))) \
{ \
ERR( "failed to load %s\n", #f ); \
goto fail; \
}
LOAD_FUNCPTR
(
gnutls_global_deinit
)
LOAD_FUNCPTR
(
gnutls_global_init
)
LOAD_FUNCPTR
(
gnutls_global_set_log_function
)
LOAD_FUNCPTR
(
gnutls_global_set_log_level
)
LOAD_FUNCPTR
(
gnutls_hash
);
LOAD_FUNCPTR
(
gnutls_hash_deinit
);
LOAD_FUNCPTR
(
gnutls_hash_init
);
LOAD_FUNCPTR
(
gnutls_perror
)
#undef LOAD_FUNCPTR
if
((
ret
=
pgnutls_global_init
())
!=
GNUTLS_E_SUCCESS
)
{
pgnutls_perror
(
ret
);
goto
fail
;
}
if
(
TRACE_ON
(
bcrypt
))
{
pgnutls_global_set_log_level
(
4
);
pgnutls_global_set_log_function
(
gnutls_log
);
}
return
TRUE
;
fail:
wine_dlclose
(
libgnutls_handle
,
NULL
,
0
);
libgnutls_handle
=
NULL
;
return
FALSE
;
}
static
void
gnutls_uninitialize
(
void
)
{
pgnutls_global_deinit
();
wine_dlclose
(
libgnutls_handle
,
NULL
,
0
);
libgnutls_handle
=
NULL
;
}
#endif
/* SONAME_LIBGNUTLS && !HAVE_COMMONCRYPTO_COMMONDIGEST_H */
NTSTATUS
WINAPI
BCryptEnumAlgorithms
(
ULONG
dwAlgOperations
,
ULONG
*
pAlgCount
,
NTSTATUS
WINAPI
BCryptEnumAlgorithms
(
ULONG
dwAlgOperations
,
ULONG
*
pAlgCount
,
BCRYPT_ALGORITHM_IDENTIFIER
**
ppAlgList
,
ULONG
dwFlags
)
BCRYPT_ALGORITHM_IDENTIFIER
**
ppAlgList
,
ULONG
dwFlags
)
{
{
...
@@ -203,7 +285,7 @@ static NTSTATUS hash_init( struct hash *hash )
...
@@ -203,7 +285,7 @@ static NTSTATUS hash_init( struct hash *hash )
return
STATUS_SUCCESS
;
return
STATUS_SUCCESS
;
}
}
static
void
hash_update
(
struct
hash
*
hash
,
UCHAR
*
input
,
ULONG
size
)
static
NTSTATUS
hash_update
(
struct
hash
*
hash
,
UCHAR
*
input
,
ULONG
size
)
{
{
switch
(
hash
->
alg_id
)
switch
(
hash
->
alg_id
)
{
{
...
@@ -225,8 +307,9 @@ static void hash_update( struct hash *hash, UCHAR *input, ULONG size )
...
@@ -225,8 +307,9 @@ static void hash_update( struct hash *hash, UCHAR *input, ULONG size )
default:
default:
ERR
(
"unhandled id %u
\n
"
,
hash
->
alg_id
);
ERR
(
"unhandled id %u
\n
"
,
hash
->
alg_id
);
break
;
return
STATUS_NOT_IMPLEMENTED
;
}
}
return
STATUS_SUCCESS
;
}
}
static
NTSTATUS
hash_finish
(
struct
hash
*
hash
,
UCHAR
*
output
,
ULONG
size
)
static
NTSTATUS
hash_finish
(
struct
hash
*
hash
,
UCHAR
*
output
,
ULONG
size
)
...
@@ -255,6 +338,58 @@ static NTSTATUS hash_finish( struct hash *hash, UCHAR *output, ULONG size )
...
@@ -255,6 +338,58 @@ static NTSTATUS hash_finish( struct hash *hash, UCHAR *output, ULONG size )
}
}
return
STATUS_SUCCESS
;
return
STATUS_SUCCESS
;
}
}
#elif defined(SONAME_LIBGNUTLS)
struct
hash
{
struct
object
hdr
;
enum
alg_id
alg_id
;
gnutls_hash_hd_t
handle
;
};
static
NTSTATUS
hash_init
(
struct
hash
*
hash
)
{
gnutls_digest_algorithm_t
alg
;
if
(
!
libgnutls_handle
)
return
STATUS_INTERNAL_ERROR
;
switch
(
hash
->
alg_id
)
{
case
ALG_ID_SHA1
:
alg
=
GNUTLS_DIG_SHA1
;
break
;
case
ALG_ID_SHA256
:
alg
=
GNUTLS_DIG_SHA256
;
break
;
case
ALG_ID_SHA384
:
alg
=
GNUTLS_DIG_SHA384
;
break
;
case
ALG_ID_SHA512
:
alg
=
GNUTLS_DIG_SHA512
;
break
;
default:
ERR
(
"unhandled id %u
\n
"
,
hash
->
alg_id
);
return
STATUS_NOT_IMPLEMENTED
;
}
if
(
pgnutls_hash_init
(
&
hash
->
handle
,
alg
))
return
STATUS_INTERNAL_ERROR
;
return
STATUS_SUCCESS
;
}
static
NTSTATUS
hash_update
(
struct
hash
*
hash
,
UCHAR
*
input
,
ULONG
size
)
{
if
(
pgnutls_hash
(
hash
->
handle
,
input
,
size
))
return
STATUS_INTERNAL_ERROR
;
return
STATUS_SUCCESS
;
}
static
NTSTATUS
hash_finish
(
struct
hash
*
hash
,
UCHAR
*
output
,
ULONG
size
)
{
pgnutls_hash_deinit
(
hash
->
handle
,
output
);
return
STATUS_SUCCESS
;
}
#else
#else
struct
hash
struct
hash
{
{
...
@@ -268,9 +403,10 @@ static NTSTATUS hash_init( struct hash *hash )
...
@@ -268,9 +403,10 @@ static NTSTATUS hash_init( struct hash *hash )
return
STATUS_NOT_IMPLEMENTED
;
return
STATUS_NOT_IMPLEMENTED
;
}
}
static
void
hash_update
(
struct
hash
*
hash
,
UCHAR
*
input
,
ULONG
size
)
static
NTSTATUS
hash_update
(
struct
hash
*
hash
,
UCHAR
*
input
,
ULONG
size
)
{
{
ERR
(
"support for hashes not available at build time
\n
"
);
ERR
(
"support for hashes not available at build time
\n
"
);
return
STATUS_NOT_IMPLEMENTED
;
}
}
static
NTSTATUS
hash_finish
(
struct
hash
*
hash
,
UCHAR
*
output
,
ULONG
size
)
static
NTSTATUS
hash_finish
(
struct
hash
*
hash
,
UCHAR
*
output
,
ULONG
size
)
...
@@ -484,8 +620,7 @@ NTSTATUS WINAPI BCryptHashData( BCRYPT_HASH_HANDLE handle, UCHAR *input, ULONG s
...
@@ -484,8 +620,7 @@ NTSTATUS WINAPI BCryptHashData( BCRYPT_HASH_HANDLE handle, UCHAR *input, ULONG s
if
(
!
hash
||
hash
->
hdr
.
magic
!=
MAGIC_HASH
)
return
STATUS_INVALID_HANDLE
;
if
(
!
hash
||
hash
->
hdr
.
magic
!=
MAGIC_HASH
)
return
STATUS_INVALID_HANDLE
;
if
(
!
input
)
return
STATUS_INVALID_PARAMETER
;
if
(
!
input
)
return
STATUS_INVALID_PARAMETER
;
hash_update
(
hash
,
input
,
size
);
return
hash_update
(
hash
,
input
,
size
);
return
STATUS_SUCCESS
;
}
}
NTSTATUS
WINAPI
BCryptFinishHash
(
BCRYPT_HASH_HANDLE
handle
,
UCHAR
*
output
,
ULONG
size
,
ULONG
flags
)
NTSTATUS
WINAPI
BCryptFinishHash
(
BCRYPT_HASH_HANDLE
handle
,
UCHAR
*
output
,
ULONG
size
,
ULONG
flags
)
...
@@ -499,3 +634,25 @@ NTSTATUS WINAPI BCryptFinishHash( BCRYPT_HASH_HANDLE handle, UCHAR *output, ULON
...
@@ -499,3 +634,25 @@ NTSTATUS WINAPI BCryptFinishHash( BCRYPT_HASH_HANDLE handle, UCHAR *output, ULON
return
hash_finish
(
hash
,
output
,
size
);
return
hash_finish
(
hash
,
output
,
size
);
}
}
BOOL
WINAPI
DllMain
(
HINSTANCE
hinst
,
DWORD
reason
,
LPVOID
reserved
)
{
switch
(
reason
)
{
case
DLL_PROCESS_ATTACH
:
instance
=
hinst
;
DisableThreadLibraryCalls
(
hinst
);
#if defined(SONAME_LIBGNUTLS) && !defined(HAVE_COMMONCRYPTO_COMMONDIGEST_H)
gnutls_initialize
();
#endif
break
;
case
DLL_PROCESS_DETACH
:
if
(
reserved
)
break
;
#if defined(SONAME_LIBGNUTLS) && !defined(HAVE_COMMONCRYPTO_COMMONDIGEST_H)
gnutls_uninitialize
();
#endif
break
;
}
return
TRUE
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment