24#define WIN32_NO_STATUS
31#include <wine/unicode.h>
34#ifdef SONAME_LIBMBEDTLS
46#if defined(HAVE_GNUTLS_HASH) && !defined(HAVE_COMMONCRYPTO_COMMONDIGEST_H)
49static void *libgnutls_handle;
50#define MAKE_FUNCPTR(f) static typeof(f) * p##f
64static void gnutls_log(
int level,
const char *
msg )
69static BOOL gnutls_initialize(
void)
75 ERR_(winediag)(
"failed to load libgnutls, no support for crypto hashes\n" );
79#define LOAD_FUNCPTR(f) \
80 if (!(p##f = wine_dlsym( libgnutls_handle, #f, NULL, 0 ))) \
82 ERR( "failed to load %s\n", #f ); \
99 if ((
ret = pgnutls_global_init()) != GNUTLS_E_SUCCESS)
101 pgnutls_perror(
ret );
107 pgnutls_global_set_log_level( 4 );
108 pgnutls_global_set_log_function( gnutls_log );
115 libgnutls_handle =
NULL;
119static void gnutls_uninitialize(
void)
121 pgnutls_global_deinit();
123 libgnutls_handle =
NULL;
125#elif defined(SONAME_LIBMBEDTLS) && !defined(HAVE_COMMONCRYPTO_COMMONDIGEST_H) && !defined(__REACTOS__)
130#define MAKE_FUNCPTR(f) static typeof(f) * p##f
159#define mbedtls_md_init pmbedtls_md_init
160#define mbedtls_md_setup pmbedtls_md_setup
161#define mbedtls_md_update pmbedtls_md_update
162#define mbedtls_md_hmac_starts pmbedtls_md_hmac_starts
163#define mbedtls_md_hmac_finish pmbedtls_md_hmac_finish
164#define mbedtls_md_free pmbedtls_md_free
165#define mbedtls_md5_init pmbedtls_md5_init
166#define mbedtls_md5_starts pmbedtls_md5_starts
167#define mbedtls_md5_update pmbedtls_md5_update
168#define mbedtls_md5_finish pmbedtls_md5_finish
169#define mbedtls_md5_free pmbedtls_md5_free
170#define mbedtls_sha1_init pmbedtls_sha1_init
171#define mbedtls_sha1_starts pmbedtls_sha1_starts
172#define mbedtls_sha1_update pmbedtls_sha1_update
173#define mbedtls_sha1_finish pmbedtls_sha1_finish
174#define mbedtls_sha1_free pmbedtls_sha1_free
175#define mbedtls_sha256_init pmbedtls_sha256_init
176#define mbedtls_sha256_starts pmbedtls_sha256_starts
177#define mbedtls_sha256_update pmbedtls_sha256_update
178#define mbedtls_sha256_finish pmbedtls_sha256_finish
179#define mbedtls_sha256_free pmbedtls_sha256_free
180#define mbedtls_sha512_init pmbedtls_sha512_init
181#define mbedtls_sha512_starts pmbedtls_sha512_starts
182#define mbedtls_sha512_update pmbedtls_sha512_update
183#define mbedtls_sha512_finish pmbedtls_sha512_finish
184#define mbedtls_sha512_free pmbedtls_sha512_free
186static BOOL mbedtls_initialize(
void)
190 ERR_(winediag)(
"failed to load libmbedtls, no support for crypto hashes\n" );
194#define LOAD_FUNCPTR(f) \
195 if (!(p##f = wine_dlsym( libmbedtls_handle, #f, NULL, 0 ))) \
197 ERR( "failed to load %s\n", #f ); \
237static void mbedtls_uninitialize(
void)
247 FIXME(
"%08x, %p, %p, %08x - stub\n", dwAlgOperations, pAlgCount, ppAlgList,
dwFlags);
255#define MAGIC_ALG (('A' << 24) | ('L' << 16) | ('G' << 8) | '0')
256#define MAGIC_HASH (('H' << 24) | ('A' << 16) | ('S' << 8) | 'H')
316 if (
flags & ~supported_flags)
317 FIXME(
"unsupported flags %08x\n",
flags & ~supported_flags);
320 FIXME(
"ignoring selected algorithm\n");
332 FIXME(
"called with unsupported parameters, returning error\n");
346 if (
flags & ~supported_flags)
348 FIXME(
"unsupported flags %08x\n",
flags & ~supported_flags);
367 FIXME(
"implementation %s not supported\n",
debugstr_w(implementation) );
402#ifdef HAVE_COMMONCRYPTO_COMMONDIGEST_H
411 CC_SHA1_CTX sha1_ctx;
412 CC_SHA256_CTX sha256_ctx;
413 CC_SHA512_CTX sha512_ctx;
414 CCHmacContext hmac_ctx;
420 switch (
hash->alg_id)
423 CC_MD5_Init( &
hash->u.md5_ctx );
427 CC_SHA1_Init( &
hash->u.sha1_ctx );
431 CC_SHA256_Init( &
hash->u.sha256_ctx );
435 CC_SHA384_Init( &
hash->u.sha512_ctx );
439 CC_SHA512_Init( &
hash->u.sha512_ctx );
443 ERR(
"unhandled id %u\n",
hash->alg_id );
451 CCHmacAlgorithm cc_algorithm;
452 switch (
hash->alg_id)
455 cc_algorithm = kCCHmacAlgMD5;
459 cc_algorithm = kCCHmacAlgSHA1;
463 cc_algorithm = kCCHmacAlgSHA256;
467 cc_algorithm = kCCHmacAlgSHA384;
471 cc_algorithm = kCCHmacAlgSHA512;
475 ERR(
"unhandled id %u\n",
hash->alg_id );
479 CCHmacInit( &
hash->u.hmac_ctx, cc_algorithm,
key, key_size );
486 switch (
hash->alg_id)
509 ERR(
"unhandled id %u\n",
hash->alg_id );
523 switch (
hash->alg_id)
526 CC_MD5_Final( output, &
hash->u.md5_ctx );
530 CC_SHA1_Final( output, &
hash->u.sha1_ctx );
534 CC_SHA256_Final( output, &
hash->u.sha256_ctx );
538 CC_SHA384_Final( output, &
hash->u.sha512_ctx );
542 CC_SHA512_Final( output, &
hash->u.sha512_ctx );
546 ERR(
"unhandled id %u\n",
hash->alg_id );
554 CCHmacFinal( &
hash->u.hmac_ctx, output );
558#elif defined(HAVE_GNUTLS_HASH)
566 gnutls_hash_hd_t hash_handle;
567 gnutls_hmac_hd_t hmac_handle;
573 gnutls_digest_algorithm_t alg;
577 switch (
hash->alg_id)
580 alg = GNUTLS_DIG_MD5;
583 alg = GNUTLS_DIG_SHA1;
587 alg = GNUTLS_DIG_SHA256;
591 alg = GNUTLS_DIG_SHA384;
595 alg = GNUTLS_DIG_SHA512;
599 ERR(
"unhandled id %u\n",
hash->alg_id );
609 gnutls_mac_algorithm_t alg;
613 switch (
hash->alg_id)
616 alg = GNUTLS_MAC_MD5;
619 alg = GNUTLS_MAC_SHA1;
623 alg = GNUTLS_MAC_SHA256;
627 alg = GNUTLS_MAC_SHA384;
631 alg = GNUTLS_MAC_SHA512;
635 ERR(
"unhandled id %u\n",
hash->alg_id );
657 pgnutls_hash_deinit(
hash->u.hash_handle, output );
663 pgnutls_hmac_deinit(
hash->u.hmac_handle, output );
666#elif defined(SONAME_LIBMBEDTLS)
687 switch (
hash->alg_id)
711 ERR(
"unhandled id %u\n",
hash->alg_id );
727 switch (
hash->alg_id)
750 ERR(
"unhandled id %u\n",
hash->alg_id);
775 switch (
hash->alg_id)
795 ERR(
"unhandled id %u\n",
hash->alg_id );
817 switch (
hash->alg_id)
841 ERR(
"unhandled id %u\n",
hash->alg_id );
860#define OBJECT_LENGTH_MD5 274
861#define OBJECT_LENGTH_SHA1 278
862#define OBJECT_LENGTH_SHA256 286
863#define OBJECT_LENGTH_SHA384 382
864#define OBJECT_LENGTH_SHA512 382
870 *ret_size =
sizeof(
ULONG);
881 if (
size < *ret_size)
931 FIXME(
"unsupported sha256 algorithm property %s\n",
debugstr_w(prop) );
940 FIXME(
"unsupported sha384 algorithm property %s\n",
debugstr_w(prop) );
949 FIXME(
"unsupported sha512 algorithm property %s\n",
debugstr_w(prop) );
953 FIXME(
"unsupported algorithm %u\n",
id );
959 *ret_size =
sizeof(
ULONG);
963 *ret_size =
sizeof(
ULONG);
982 TRACE(
"%p, %s, %p, %u, %p, %08x\n",
handle,
wine_dbgstr_w(prop),
buffer,
count,
res,
flags );
1012 TRACE(
"%p, %p, %p, %u, %p, %u, %08x - stub\n",
algorithm,
handle,
object, objectlen,
1016 FIXME(
"unimplemented flags %08x\n",
flags );
1021 if (
object)
FIXME(
"ignoring object buffer\n" );
1088 return hmac_finish(
hash, output,
size );
1092 return hash_finish(
hash, output,
size );
1102 TRACE(
"%p, %p, %u, %p, %u, %p, %u\n",
algorithm,
secret, secretlen,
1103 input, inputlen, output, outputlen );
1135#if defined(HAVE_GNUTLS_HASH) && !defined(HAVE_COMMONCRYPTO_COMMONDIGEST_H)
1136 gnutls_initialize();
1137#elif defined(SONAME_LIBMBEDTLS) && !defined(HAVE_COMMONCRYPTO_COMMONDIGEST_H) && !defined(__REACTOS__)
1138 mbedtls_initialize();
1144#if defined(HAVE_GNUTLS_HASH) && !defined(HAVE_COMMONCRYPTO_COMMONDIGEST_H)
1145 gnutls_uninitialize();
1146#elif defined(SONAME_LIBMBEDTLS) && !defined(HAVE_COMMONCRYPTO_COMMONDIGEST_H) && !defined(__REACTOS__)
1147 mbedtls_uninitialize();
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
#define BCRYPT_ECDSA_P384_ALGORITHM
#define BCRYPT_OBJECT_LENGTH
#define BCRYPT_SHA512_ALGORITHM
#define BCRYPT_ALGORITHM_NAME
#define BCRYPT_SHA256_ALGORITHM
#define BCRYPT_ALG_HANDLE_HMAC_FLAG
#define BCRYPT_ECDSA_P256_ALGORITHM
#define BCRYPT_RNG_ALGORITHM
#define BCRYPT_HASH_LENGTH
#define MS_PRIMITIVE_PROVIDER
#define BCRYPT_SHA384_ALGORITHM
#define BCRYPT_SHA1_ALGORITHM
#define BCRYPT_MD5_ALGORITHM
#define BCRYPT_USE_SYSTEM_PREFERRED_RNG
NTSTATUS WINAPI BCryptHash(BCRYPT_ALG_HANDLE algorithm, UCHAR *secret, ULONG secretlen, UCHAR *input, ULONG inputlen, UCHAR *output, ULONG outputlen)
NTSTATUS WINAPI BCryptGenRandom(BCRYPT_ALG_HANDLE handle, UCHAR *buffer, ULONG count, ULONG flags)
NTSTATUS WINAPI BCryptHashData(BCRYPT_HASH_HANDLE handle, UCHAR *input, ULONG size, ULONG flags)
static NTSTATUS generic_alg_property(enum alg_id id, const WCHAR *prop, UCHAR *buf, ULONG size, ULONG *ret_size)
#define OBJECT_LENGTH_SHA384
NTSTATUS WINAPI BCryptGetProperty(BCRYPT_HANDLE handle, LPCWSTR prop, UCHAR *buffer, ULONG count, ULONG *res, ULONG flags)
static const struct @324 alg_props[]
NTSTATUS WINAPI BCryptDestroyHash(BCRYPT_HASH_HANDLE handle)
BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, LPVOID reserved)
static HINSTANCE instance
NTSTATUS WINAPI BCryptEnumAlgorithms(ULONG dwAlgOperations, ULONG *pAlgCount, BCRYPT_ALGORITHM_IDENTIFIER **ppAlgList, ULONG dwFlags)
NTSTATUS WINAPI BCryptOpenAlgorithmProvider(BCRYPT_ALG_HANDLE *handle, LPCWSTR id, LPCWSTR implementation, DWORD flags)
#define OBJECT_LENGTH_SHA256
NTSTATUS WINAPI BCryptCloseAlgorithmProvider(BCRYPT_ALG_HANDLE handle, DWORD flags)
static NTSTATUS get_hash_property(enum alg_id id, const WCHAR *prop, UCHAR *buf, ULONG size, ULONG *ret_size)
static NTSTATUS get_alg_property(enum alg_id id, const WCHAR *prop, UCHAR *buf, ULONG size, ULONG *ret_size)
NTSTATUS WINAPI BCryptCreateHash(BCRYPT_ALG_HANDLE algorithm, BCRYPT_HASH_HANDLE *handle, UCHAR *object, ULONG objectlen, UCHAR *secret, ULONG secretlen, ULONG flags)
#define OBJECT_LENGTH_SHA512
NTSTATUS WINAPI BCryptFinishHash(BCRYPT_HASH_HANDLE handle, UCHAR *output, ULONG size, ULONG flags)
#define OBJECT_LENGTH_SHA1
#define OBJECT_LENGTH_MD5
NTSTATUS WINAPI BCryptGetFipsAlgorithmMode(BOOLEAN *enabled)
#define STATUS_INVALID_HANDLE
#define STATUS_NOT_SUPPORTED
#define STATUS_NOT_IMPLEMENTED
static WCHAR reason[MAX_STRING_RESOURCE_LEN]
#define DLL_PROCESS_ATTACH
#define DLL_PROCESS_DETACH
#define HeapFree(x, y, z)
#define WINE_DECLARE_DEBUG_CHANNEL(x)
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
static FT_Error hash_init(FT_Hash hash, FT_Bool is_num, FT_Memory memory)
GLuint GLuint GLsizei count
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLenum GLuint GLenum GLsizei const GLchar * buf
GLenum GLenum GLenum input
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble * u
void * wine_dlopen(const char *filename, int flag, char *error, size_t errorsize)
int wine_dlclose(void *handle, char *error, size_t errorsize)
This file contains the generic message-digest wrapper.
int mbedtls_md_setup(mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info, int hmac)
This function selects the message digest algorithm to use, and allocates internal structures.
mbedtls_md_type_t
Supported message digests.
int mbedtls_md_hmac_finish(mbedtls_md_context_t *ctx, unsigned char *output)
This function finishes the HMAC operation, and writes the result to the output buffer.
int mbedtls_md_update(mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen)
This function feeds an input buffer into an ongoing message-digest computation.
int mbedtls_md_hmac_starts(mbedtls_md_context_t *ctx, const unsigned char *key, size_t keylen)
This function sets the HMAC key and prepares to authenticate a new message.
void mbedtls_md_init(mbedtls_md_context_t *ctx)
This function initializes a message-digest context without binding it to a particular message-digest ...
void mbedtls_md_free(mbedtls_md_context_t *ctx)
This function clears the internal structure of ctx and frees any embedded internal structure,...
#define memcpy(s1, s2, n)
static DATA_BLOB CRYPTPROTECT_PROMPTSTRUCT DATA_BLOB *static LPWSTR DATA_BLOB CRYPTPROTECT_PROMPTSTRUCT DATA_BLOB *static char secret[]
#define STATUS_INTERNAL_ERROR
static void * libmbedtls_handle
#define mbedtls_md_info_from_type
MD5 message digest algorithm (hash function)
void mbedtls_md5_free(mbedtls_md5_context *ctx)
Clear MD5 context.
MBEDTLS_DEPRECATED void mbedtls_md5_starts(mbedtls_md5_context *ctx)
MD5 context setup.
MBEDTLS_DEPRECATED void mbedtls_md5_finish(mbedtls_md5_context *ctx, unsigned char output[16])
MD5 final digest.
void mbedtls_md5_init(mbedtls_md5_context *ctx)
Initialize MD5 context.
MBEDTLS_DEPRECATED void mbedtls_md5_update(mbedtls_md5_context *ctx, const unsigned char *input, size_t ilen)
MD5 process buffer.
This file contains SHA-1 definitions and functions.
MBEDTLS_DEPRECATED void mbedtls_sha1_finish(mbedtls_sha1_context *ctx, unsigned char output[20])
This function finishes the SHA-1 operation, and writes the result to the output buffer.
void mbedtls_sha1_free(mbedtls_sha1_context *ctx)
This function clears a SHA-1 context.
MBEDTLS_DEPRECATED void mbedtls_sha1_starts(mbedtls_sha1_context *ctx)
This function starts a SHA-1 checksum calculation.
MBEDTLS_DEPRECATED void mbedtls_sha1_update(mbedtls_sha1_context *ctx, const unsigned char *input, size_t ilen)
This function feeds an input buffer into an ongoing SHA-1 checksum calculation.
void mbedtls_sha1_init(mbedtls_sha1_context *ctx)
This function initializes a SHA-1 context.
#define SONAME_LIBMBEDTLS
This file contains SHA-224 and SHA-256 definitions and functions.
void mbedtls_sha256_free(mbedtls_sha256_context *ctx)
This function clears a SHA-256 context.
MBEDTLS_DEPRECATED void mbedtls_sha256_finish(mbedtls_sha256_context *ctx, unsigned char output[32])
This function finishes the SHA-256 operation, and writes the result to the output buffer.
MBEDTLS_DEPRECATED void mbedtls_sha256_update(mbedtls_sha256_context *ctx, const unsigned char *input, size_t ilen)
This function feeds an input buffer into an ongoing SHA-256 checksum calculation.
void mbedtls_sha256_init(mbedtls_sha256_context *ctx)
This function initializes a SHA-256 context.
MBEDTLS_DEPRECATED void mbedtls_sha256_starts(mbedtls_sha256_context *ctx, int is224)
This function starts a SHA-224 or SHA-256 checksum calculation.
This file contains SHA-384 and SHA-512 definitions and functions.
MBEDTLS_DEPRECATED void mbedtls_sha512_finish(mbedtls_sha512_context *ctx, unsigned char output[64])
This function finishes the SHA-512 operation, and writes the result to the output buffer.
MBEDTLS_DEPRECATED void mbedtls_sha512_update(mbedtls_sha512_context *ctx, const unsigned char *input, size_t ilen)
This function feeds an input buffer into an ongoing SHA-512 checksum calculation.
void mbedtls_sha512_free(mbedtls_sha512_context *ctx)
This function clears a SHA-512 context.
MBEDTLS_DEPRECATED void mbedtls_sha512_starts(mbedtls_sha512_context *ctx, int is384)
This function starts a SHA-384 or SHA-512 checksum calculation.
void mbedtls_sha512_init(mbedtls_sha512_context *ctx)
This function initializes a SHA-512 context.
#define STATUS_BUFFER_TOO_SMALL
The SHA-1 context structure.
The SHA-256 context structure.
The SHA-512 context structure.
#define STATUS_INVALID_PARAMETER
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags