ReactOS  0.4.15-dev-4869-g35a816a
bcrypt_main.c File Reference
#include <wine/config.h>
#include <wine/port.h>
#include <ntstatus.h>
#include <windef.h>
#include <winbase.h>
#include <ntsecapi.h>
#include <bcrypt.h>
#include <wine/debug.h>
#include <wine/unicode.h>
#include <wine/library.h>
Include dependency graph for bcrypt_main.c:

Go to the source code of this file.

Classes

struct  object
 
struct  algorithm
 

Macros

#define WIN32_NO_STATUS
 
#define MAGIC_ALG   (('A' << 24) | ('L' << 16) | ('G' << 8) | '0')
 
#define MAGIC_HASH   (('H' << 24) | ('A' << 16) | ('S' << 8) | 'H')
 
#define OBJECT_LENGTH_MD5   274
 
#define OBJECT_LENGTH_SHA1   278
 
#define OBJECT_LENGTH_SHA256   286
 
#define OBJECT_LENGTH_SHA384   382
 
#define OBJECT_LENGTH_SHA512   382
 

Enumerations

enum  alg_id {
  ALG_ID_MD5, ALG_ID_RNG, ALG_ID_SHA1, ALG_ID_SHA256,
  ALG_ID_SHA384, ALG_ID_SHA512, ALG_ID_ECDSA_P256, ALG_ID_ECDSA_P384
}
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (bcrypt)
 
NTSTATUS WINAPI BCryptEnumAlgorithms (ULONG dwAlgOperations, ULONG *pAlgCount, BCRYPT_ALGORITHM_IDENTIFIER **ppAlgList, ULONG dwFlags)
 
NTSTATUS WINAPI BCryptGenRandom (BCRYPT_ALG_HANDLE handle, UCHAR *buffer, ULONG count, ULONG flags)
 
NTSTATUS WINAPI BCryptOpenAlgorithmProvider (BCRYPT_ALG_HANDLE *handle, LPCWSTR id, LPCWSTR implementation, DWORD flags)
 
NTSTATUS WINAPI BCryptCloseAlgorithmProvider (BCRYPT_ALG_HANDLE handle, DWORD flags)
 
NTSTATUS WINAPI BCryptGetFipsAlgorithmMode (BOOLEAN *enabled)
 
static NTSTATUS generic_alg_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)
 
static NTSTATUS get_hash_property (enum alg_id id, const WCHAR *prop, UCHAR *buf, ULONG size, ULONG *ret_size)
 
NTSTATUS WINAPI BCryptGetProperty (BCRYPT_HANDLE handle, LPCWSTR prop, UCHAR *buffer, ULONG count, ULONG *res, ULONG flags)
 
NTSTATUS WINAPI BCryptCreateHash (BCRYPT_ALG_HANDLE algorithm, BCRYPT_HASH_HANDLE *handle, UCHAR *object, ULONG objectlen, UCHAR *secret, ULONG secretlen, ULONG flags)
 
NTSTATUS WINAPI BCryptDestroyHash (BCRYPT_HASH_HANDLE handle)
 
NTSTATUS WINAPI BCryptHashData (BCRYPT_HASH_HANDLE handle, UCHAR *input, ULONG size, ULONG flags)
 
NTSTATUS WINAPI BCryptFinishHash (BCRYPT_HASH_HANDLE handle, UCHAR *output, ULONG size, ULONG flags)
 
NTSTATUS WINAPI BCryptHash (BCRYPT_ALG_HANDLE algorithm, UCHAR *secret, ULONG secretlen, UCHAR *input, ULONG inputlen, UCHAR *output, ULONG outputlen)
 
BOOL WINAPI DllMain (HINSTANCE hinst, DWORD reason, LPVOID reserved)
 

Variables

static HINSTANCE instance
 
struct {
   ULONG   hash_length
 
   const WCHAR *   alg_name
 
alg_props []
 

Macro Definition Documentation

◆ MAGIC_ALG

#define MAGIC_ALG   (('A' << 24) | ('L' << 16) | ('G' << 8) | '0')

Definition at line 255 of file bcrypt_main.c.

◆ MAGIC_HASH

#define MAGIC_HASH   (('H' << 24) | ('A' << 16) | ('S' << 8) | 'H')

Definition at line 256 of file bcrypt_main.c.

◆ OBJECT_LENGTH_MD5

#define OBJECT_LENGTH_MD5   274

Definition at line 860 of file bcrypt_main.c.

◆ OBJECT_LENGTH_SHA1

#define OBJECT_LENGTH_SHA1   278

Definition at line 861 of file bcrypt_main.c.

◆ OBJECT_LENGTH_SHA256

#define OBJECT_LENGTH_SHA256   286

Definition at line 862 of file bcrypt_main.c.

◆ OBJECT_LENGTH_SHA384

#define OBJECT_LENGTH_SHA384   382

Definition at line 863 of file bcrypt_main.c.

◆ OBJECT_LENGTH_SHA512

#define OBJECT_LENGTH_SHA512   382

Definition at line 864 of file bcrypt_main.c.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 24 of file bcrypt_main.c.

Enumeration Type Documentation

◆ alg_id

Enumerator
ALG_ID_MD5 
ALG_ID_RNG 
ALG_ID_SHA1 
ALG_ID_SHA256 
ALG_ID_SHA384 
ALG_ID_SHA512 
ALG_ID_ECDSA_P256 
ALG_ID_ECDSA_P384 

Definition at line 262 of file bcrypt_main.c.

Function Documentation

◆ BCryptCloseAlgorithmProvider()

NTSTATUS WINAPI BCryptCloseAlgorithmProvider ( BCRYPT_ALG_HANDLE  handle,
DWORD  flags 
)

Definition at line 380 of file bcrypt_main.c.

381 {
382  struct algorithm *alg = handle;
383 
384  TRACE( "%p, %08x\n", handle, flags );
385 
386  if (!alg || alg->hdr.magic != MAGIC_ALG) return STATUS_INVALID_HANDLE;
387  HeapFree( GetProcessHeap(), 0, alg );
388  return STATUS_SUCCESS;
389 }
#define STATUS_INVALID_HANDLE
Definition: ntstatus.h:245
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED LPLOOKUPSERVICE_COMPLETION_ROUTINE HANDLE * handle
Definition: sock.c:82
#define MAGIC_ALG
Definition: bcrypt_main.c:255
#define TRACE(s)
Definition: solgame.cpp:4
#define GetProcessHeap()
Definition: compat.h:595
GLbitfield flags
Definition: glext.h:7161
struct object hdr
Definition: bcrypt_main.c:290
#define STATUS_SUCCESS
Definition: shellext.h:65
#define HeapFree(x, y, z)
Definition: compat.h:594

Referenced by assembly_get_pubkey_token(), CNG_CalcHash(), CNG_ImportECCPubKey(), test_BcryptHash(), test_md5(), test_rng(), test_sha1(), test_sha256(), test_sha384(), and test_sha512().

◆ BCryptCreateHash()

NTSTATUS WINAPI BCryptCreateHash ( BCRYPT_ALG_HANDLE  algorithm,
BCRYPT_HASH_HANDLE handle,
UCHAR object,
ULONG  objectlen,
UCHAR secret,
ULONG  secretlen,
ULONG  flags 
)

Definition at line 1005 of file bcrypt_main.c.

1007 {
1008  struct algorithm *alg = algorithm;
1009  struct hash *hash;
1010  NTSTATUS status;
1011 
1012  TRACE( "%p, %p, %p, %u, %p, %u, %08x - stub\n", algorithm, handle, object, objectlen,
1013  secret, secretlen, flags );
1014  if (flags)
1015  {
1016  FIXME( "unimplemented flags %08x\n", flags );
1017  return STATUS_NOT_IMPLEMENTED;
1018  }
1019 
1020  if (!alg || alg->hdr.magic != MAGIC_ALG) return STATUS_INVALID_HANDLE;
1021  if (object) FIXME( "ignoring object buffer\n" );
1022 
1023  if (!(hash = HeapAlloc( GetProcessHeap(), 0, sizeof(*hash) ))) return STATUS_NO_MEMORY;
1024  hash->hdr.magic = MAGIC_HASH;
1025  hash->alg_id = alg->id;
1026  hash->hmac = alg->hmac;
1027 
1028  if (hash->hmac)
1029  {
1030  status = hmac_init( hash, secret, secretlen );
1031  }
1032  else
1033  {
1034  status = hash_init( hash );
1035  }
1036 
1037  if (status != STATUS_SUCCESS)
1038  {
1039  HeapFree( GetProcessHeap(), 0, hash );
1040  return status;
1041  }
1042 
1043  *handle = hash;
1044  return STATUS_SUCCESS;
1045 }
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_INVALID_HANDLE
Definition: ntstatus.h:245
static UCHAR ULONG secretlen
Definition: bcrypt.c:29
return STATUS_NOT_IMPLEMENTED
enum alg_id id
Definition: bcrypt_main.c:291
int hash
Definition: main.c:58
#define FIXME(fmt,...)
Definition: debug.h:111
#define MAGIC_ALG
Definition: bcrypt_main.c:255
#define TRACE(s)
Definition: solgame.cpp:4
#define GetProcessHeap()
Definition: compat.h:595
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
GLbitfield flags
Definition: glext.h:7161
static UCHAR * secret
Definition: bcrypt.c:29
struct object hdr
Definition: bcrypt_main.c:290
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
#define STATUS_SUCCESS
Definition: shellext.h:65
Definition: _hash_fun.h:40
static SERVICE_STATUS status
Definition: service.c:31
#define MAGIC_HASH
Definition: bcrypt_main.c:256
#define HeapFree(x, y, z)
Definition: compat.h:594
static FT_Error hash_init(FT_Hash hash, FT_Bool is_num, FT_Memory memory)
Definition: fthash.c:166
Definition: ps.c:97

Referenced by BCryptHash(), CNG_CalcHash(), test_md5(), test_sha1(), test_sha256(), test_sha384(), and test_sha512().

◆ BCryptDestroyHash()

NTSTATUS WINAPI BCryptDestroyHash ( BCRYPT_HASH_HANDLE  handle)

Definition at line 1047 of file bcrypt_main.c.

1048 {
1049  struct hash *hash = handle;
1050 
1051  TRACE( "%p\n", handle );
1052 
1053  if (!hash || hash->hdr.magic != MAGIC_HASH) return STATUS_INVALID_HANDLE;
1054  HeapFree( GetProcessHeap(), 0, hash );
1055  return STATUS_SUCCESS;
1056 }
#define STATUS_INVALID_HANDLE
Definition: ntstatus.h:245
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED LPLOOKUPSERVICE_COMPLETION_ROUTINE HANDLE * handle
Definition: sock.c:82
#define TRACE(s)
Definition: solgame.cpp:4
#define GetProcessHeap()
Definition: compat.h:595
#define STATUS_SUCCESS
Definition: shellext.h:65
Definition: _hash_fun.h:40
#define MAGIC_HASH
Definition: bcrypt_main.c:256
#define HeapFree(x, y, z)
Definition: compat.h:594

Referenced by BCryptHash(), CNG_CalcHash(), test_md5(), test_sha1(), test_sha256(), test_sha384(), and test_sha512().

◆ BCryptEnumAlgorithms()

NTSTATUS WINAPI BCryptEnumAlgorithms ( ULONG  dwAlgOperations,
ULONG pAlgCount,
BCRYPT_ALGORITHM_IDENTIFIER **  ppAlgList,
ULONG  dwFlags 
)

Definition at line 244 of file bcrypt_main.c.

246 {
247  FIXME("%08x, %p, %p, %08x - stub\n", dwAlgOperations, pAlgCount, ppAlgList, dwFlags);
248 
249  *ppAlgList=NULL;
250  *pAlgCount=0;
251 
252  return STATUS_NOT_IMPLEMENTED;
253 }
return STATUS_NOT_IMPLEMENTED
#define FIXME(fmt,...)
Definition: debug.h:111
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
#define NULL
Definition: types.h:112

◆ BCryptFinishHash()

NTSTATUS WINAPI BCryptFinishHash ( BCRYPT_HASH_HANDLE  handle,
UCHAR output,
ULONG  size,
ULONG  flags 
)

Definition at line 1077 of file bcrypt_main.c.

1078 {
1079  struct hash *hash = handle;
1080 
1081  TRACE( "%p, %p, %u, %08x\n", handle, output, size, flags );
1082 
1083  if (!hash || hash->hdr.magic != MAGIC_HASH) return STATUS_INVALID_HANDLE;
1084  if (!output) return STATUS_INVALID_PARAMETER;
1085 
1086  if (hash->hmac)
1087  {
1088  return hmac_finish( hash, output, size );
1089  }
1090  else
1091  {
1092  return hash_finish( hash, output, size );
1093  }
1094 }
static UCHAR ULONG UCHAR ULONG UCHAR * output
Definition: bcrypt.c:29
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_INVALID_HANDLE
Definition: ntstatus.h:245
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED LPLOOKUPSERVICE_COMPLETION_ROUTINE HANDLE * handle
Definition: sock.c:82
#define TRACE(s)
Definition: solgame.cpp:4
GLsizeiptr size
Definition: glext.h:5919
GLbitfield flags
Definition: glext.h:7161
Definition: _hash_fun.h:40
#define MAGIC_HASH
Definition: bcrypt_main.c:256

Referenced by BCryptHash(), CNG_CalcHash(), test_md5(), test_sha1(), test_sha256(), test_sha384(), and test_sha512().

◆ BCryptGenRandom()

NTSTATUS WINAPI BCryptGenRandom ( BCRYPT_ALG_HANDLE  handle,
UCHAR buffer,
ULONG  count,
ULONG  flags 
)

Definition at line 295 of file bcrypt_main.c.

296 {
297  const DWORD supported_flags = BCRYPT_USE_SYSTEM_PREFERRED_RNG;
298  struct algorithm *algorithm = handle;
299 
300  TRACE("%p, %p, %u, %08x - semi-stub\n", handle, buffer, count, flags);
301 
302  if (!algorithm)
303  {
304  /* It's valid to call without an algorithm if BCRYPT_USE_SYSTEM_PREFERRED_RNG
305  * is set. In this case the preferred system RNG is used.
306  */
308  return STATUS_INVALID_HANDLE;
309  }
310  else if (algorithm->hdr.magic != MAGIC_ALG || algorithm->id != ALG_ID_RNG)
311  return STATUS_INVALID_HANDLE;
312 
313  if (!buffer)
315 
316  if (flags & ~supported_flags)
317  FIXME("unsupported flags %08x\n", flags & ~supported_flags);
318 
319  if (algorithm)
320  FIXME("ignoring selected algorithm\n");
321 
322  /* When zero bytes are requested the function returns success too. */
323  if (!count)
324  return STATUS_SUCCESS;
325 
327  {
328  if (RtlGenRandom(buffer, count))
329  return STATUS_SUCCESS;
330  }
331 
332  FIXME("called with unsupported parameters, returning error\n");
333  return STATUS_NOT_IMPLEMENTED;
334 }
#define BCRYPT_USE_SYSTEM_PREFERRED_RNG
Definition: bcrypt.h:171
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLuint buffer
Definition: glext.h:5915
#define STATUS_INVALID_HANDLE
Definition: ntstatus.h:245
return STATUS_NOT_IMPLEMENTED
enum alg_id id
Definition: bcrypt_main.c:291
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED LPLOOKUPSERVICE_COMPLETION_ROUTINE HANDLE * handle
Definition: sock.c:82
#define FIXME(fmt,...)
Definition: debug.h:111
#define MAGIC_ALG
Definition: bcrypt_main.c:255
#define TRACE(s)
Definition: solgame.cpp:4
BOOLEAN WINAPI RtlGenRandom(PVOID, ULONG)
unsigned long DWORD
Definition: ntddk_ex.h:95
GLbitfield flags
Definition: glext.h:7161
struct object hdr
Definition: bcrypt_main.c:290
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by test_BCryptGenRandom(), and test_rng().

◆ BCryptGetFipsAlgorithmMode()

NTSTATUS WINAPI BCryptGetFipsAlgorithmMode ( BOOLEAN enabled)

Definition at line 391 of file bcrypt_main.c.

392 {
393  FIXME("%p - semi-stub\n", enabled);
394 
395  if (!enabled)
397 
398  *enabled = FALSE;
399  return STATUS_SUCCESS;
400 }
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
GLenum GLenum GLsizei const GLuint GLboolean enabled
Definition: glext.h:7750
#define FALSE
Definition: types.h:117
#define FIXME(fmt,...)
Definition: debug.h:111
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by test_BCryptGetFipsAlgorithmMode().

◆ BCryptGetProperty()

NTSTATUS WINAPI BCryptGetProperty ( BCRYPT_HANDLE  handle,
LPCWSTR  prop,
UCHAR buffer,
ULONG  count,
ULONG res,
ULONG  flags 
)

Definition at line 978 of file bcrypt_main.c.

979 {
980  struct object *object = handle;
981 
982  TRACE( "%p, %s, %p, %u, %p, %08x\n", handle, wine_dbgstr_w(prop), buffer, count, res, flags );
983 
984  if (!object) return STATUS_INVALID_HANDLE;
985  if (!prop || !res) return STATUS_INVALID_PARAMETER;
986 
987  switch (object->magic)
988  {
989  case MAGIC_ALG:
990  {
991  const struct algorithm *alg = (const struct algorithm *)object;
992  return get_alg_property( alg->id, prop, buffer, count, res );
993  }
994  case MAGIC_HASH:
995  {
996  const struct hash *hash = (const struct hash *)object;
997  return get_hash_property( hash->alg_id, prop, buffer, count, res );
998  }
999  default:
1000  WARN( "unknown magic %08x\n", object->magic );
1001  return STATUS_INVALID_HANDLE;
1002  }
1003 }
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
char * wine_dbgstr_w(const wchar_t *wstr)
Definition: atltest.h:87
GLuint GLuint GLsizei count
Definition: gl.h:1545
#define WARN(fmt,...)
Definition: debug.h:112
static NTSTATUS get_hash_property(enum alg_id id, const WCHAR *prop, UCHAR *buf, ULONG size, ULONG *ret_size)
Definition: bcrypt_main.c:968
static NTSTATUS get_alg_property(enum alg_id id, const WCHAR *prop, UCHAR *buf, ULONG size, ULONG *ret_size)
Definition: bcrypt_main.c:891
GLuint buffer
Definition: glext.h:5915
ULONG magic
Definition: bcrypt_main.c:259
#define STATUS_INVALID_HANDLE
Definition: ntstatus.h:245
enum alg_id id
Definition: bcrypt_main.c:291
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED LPLOOKUPSERVICE_COMPLETION_ROUTINE HANDLE * handle
Definition: sock.c:82
#define MAGIC_ALG
Definition: bcrypt_main.c:255
#define TRACE(s)
Definition: solgame.cpp:4
GLbitfield flags
Definition: glext.h:7161
GLuint res
Definition: glext.h:9613
Definition: _hash_fun.h:40
#define MAGIC_HASH
Definition: bcrypt_main.c:256

Referenced by _test_alg_name(), _test_hash_length(), CNG_CalcHash(), test_md5(), test_rng(), test_sha1(), test_sha256(), test_sha384(), and test_sha512().

◆ BCryptHash()

NTSTATUS WINAPI BCryptHash ( BCRYPT_ALG_HANDLE  algorithm,
UCHAR secret,
ULONG  secretlen,
UCHAR input,
ULONG  inputlen,
UCHAR output,
ULONG  outputlen 
)

Definition at line 1096 of file bcrypt_main.c.

1098 {
1099  NTSTATUS status;
1101 
1102  TRACE( "%p, %p, %u, %p, %u, %p, %u\n", algorithm, secret, secretlen,
1104 
1106  if (status != STATUS_SUCCESS)
1107  {
1108  return status;
1109  }
1110 
1112  if (status != STATUS_SUCCESS)
1113  {
1115  return status;
1116  }
1117 
1119  if (status != STATUS_SUCCESS)
1120  {
1122  return status;
1123  }
1124 
1125  return BCryptDestroyHash( handle );
1126 }
static UCHAR ULONG UCHAR ULONG UCHAR ULONG outputlen
Definition: bcrypt.c:29
static UCHAR ULONG UCHAR ULONG UCHAR * output
Definition: bcrypt.c:29
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS WINAPI BCryptHashData(BCRYPT_HASH_HANDLE handle, UCHAR *input, ULONG size, ULONG flags)
Definition: bcrypt_main.c:1058
NTSTATUS WINAPI BCryptFinishHash(BCRYPT_HASH_HANDLE handle, UCHAR *output, ULONG size, ULONG flags)
Definition: bcrypt_main.c:1077
static UCHAR ULONG secretlen
Definition: bcrypt.c:29
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED LPLOOKUPSERVICE_COMPLETION_ROUTINE HANDLE * handle
Definition: sock.c:82
#define TRACE(s)
Definition: solgame.cpp:4
static UCHAR * secret
Definition: bcrypt.c:29
GLenum GLenum GLenum input
Definition: glext.h:9031
#define NULL
Definition: types.h:112
static UCHAR ULONG UCHAR ULONG inputlen
Definition: bcrypt.c:29
#define STATUS_SUCCESS
Definition: shellext.h:65
static SERVICE_STATUS status
Definition: service.c:31
NTSTATUS WINAPI BCryptDestroyHash(BCRYPT_HASH_HANDLE handle)
Definition: bcrypt_main.c:1047
NTSTATUS WINAPI BCryptCreateHash(BCRYPT_ALG_HANDLE algorithm, BCRYPT_HASH_HANDLE *handle, UCHAR *object, ULONG objectlen, UCHAR *secret, ULONG secretlen, ULONG flags)
Definition: bcrypt_main.c:1005
Definition: ps.c:97

Referenced by assembly_get_pubkey_token().

◆ BCryptHashData()

NTSTATUS WINAPI BCryptHashData ( BCRYPT_HASH_HANDLE  handle,
UCHAR input,
ULONG  size,
ULONG  flags 
)

Definition at line 1058 of file bcrypt_main.c.

1059 {
1060  struct hash *hash = handle;
1061 
1062  TRACE( "%p, %p, %u, %08x\n", handle, input, size, flags );
1063 
1064  if (!hash || hash->hdr.magic != MAGIC_HASH) return STATUS_INVALID_HANDLE;
1065  if (!input) return STATUS_SUCCESS;
1066 
1067  if (hash->hmac)
1068  {
1069  return hmac_update( hash, input, size );
1070  }
1071  else
1072  {
1073  return hash_update( hash, input, size );
1074  }
1075 }
#define STATUS_INVALID_HANDLE
Definition: ntstatus.h:245
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED LPLOOKUPSERVICE_COMPLETION_ROUTINE HANDLE * handle
Definition: sock.c:82
#define TRACE(s)
Definition: solgame.cpp:4
GLsizeiptr size
Definition: glext.h:5919
GLbitfield flags
Definition: glext.h:7161
GLenum GLenum GLenum input
Definition: glext.h:9031
#define STATUS_SUCCESS
Definition: shellext.h:65
Definition: _hash_fun.h:40
#define MAGIC_HASH
Definition: bcrypt_main.c:256

Referenced by BCryptHash(), CNG_CalcHash(), test_md5(), test_sha1(), test_sha256(), test_sha384(), and test_sha512().

◆ BCryptOpenAlgorithmProvider()

NTSTATUS WINAPI BCryptOpenAlgorithmProvider ( BCRYPT_ALG_HANDLE handle,
LPCWSTR  id,
LPCWSTR  implementation,
DWORD  flags 
)

Definition at line 336 of file bcrypt_main.c.

337 {
338  struct algorithm *alg;
339  enum alg_id alg_id;
340 
341  const DWORD supported_flags = BCRYPT_ALG_HANDLE_HMAC_FLAG;
342 
343  TRACE( "%p, %s, %s, %08x\n", handle, wine_dbgstr_w(id), wine_dbgstr_w(implementation), flags );
344 
345  if (!handle || !id) return STATUS_INVALID_PARAMETER;
346  if (flags & ~supported_flags)
347  {
348  FIXME( "unsupported flags %08x\n", flags & ~supported_flags);
349  return STATUS_NOT_IMPLEMENTED;
350  }
351 
353  else if (!strcmpW( id, BCRYPT_MD5_ALGORITHM )) alg_id = ALG_ID_MD5;
354  else if (!strcmpW( id, BCRYPT_RNG_ALGORITHM )) alg_id = ALG_ID_RNG;
360  else
361  {
362  FIXME( "algorithm %s not supported\n", debugstr_w(id) );
363  return STATUS_NOT_IMPLEMENTED;
364  }
365  if (implementation && strcmpW( implementation, MS_PRIMITIVE_PROVIDER ))
366  {
367  FIXME( "implementation %s not supported\n", debugstr_w(implementation) );
368  return STATUS_NOT_IMPLEMENTED;
369  }
370 
371  if (!(alg = HeapAlloc( GetProcessHeap(), 0, sizeof(*alg) ))) return STATUS_NO_MEMORY;
372  alg->hdr.magic = MAGIC_ALG;
373  alg->id = alg_id;
375 
376  *handle = alg;
377  return STATUS_SUCCESS;
378 }
#define MS_PRIMITIVE_PROVIDER
Definition: bcrypt.h:69
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
char * wine_dbgstr_w(const wchar_t *wstr)
Definition: atltest.h:87
#define BCRYPT_MD5_ALGORITHM
Definition: bcrypt.h:72
#define BCRYPT_SHA256_ALGORITHM
Definition: bcrypt.h:75
#define BCRYPT_ALG_HANDLE_HMAC_FLAG
Definition: bcrypt.h:172
return STATUS_NOT_IMPLEMENTED
enum alg_id id
Definition: bcrypt_main.c:291
#define debugstr_w
Definition: kernel32.h:32
#define FIXME(fmt,...)
Definition: debug.h:111
#define MAGIC_ALG
Definition: bcrypt_main.c:255
#define BCRYPT_ECDSA_P256_ALGORITHM
Definition: bcrypt.h:78
#define TRACE(s)
Definition: solgame.cpp:4
#define GetProcessHeap()
Definition: compat.h:595
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
unsigned long DWORD
Definition: ntddk_ex.h:95
#define BCRYPT_SHA384_ALGORITHM
Definition: bcrypt.h:76
GLbitfield flags
Definition: glext.h:7161
#define BCRYPT_SHA512_ALGORITHM
Definition: bcrypt.h:77
struct object hdr
Definition: bcrypt_main.c:290
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
WINE_UNICODE_INLINE int strcmpW(const WCHAR *str1, const WCHAR *str2)
Definition: unicode.h:229
#define STATUS_SUCCESS
Definition: shellext.h:65
#define BCRYPT_ECDSA_P384_ALGORITHM
Definition: bcrypt.h:79
#define BCRYPT_RNG_ALGORITHM
Definition: bcrypt.h:73
#define BCRYPT_SHA1_ALGORITHM
Definition: bcrypt.h:74
alg_id
Definition: bcrypt_main.c:262

Referenced by assembly_get_pubkey_token(), CNG_CalcHash(), CNG_ImportECCPubKey(), test_BcryptHash(), test_md5(), test_rng(), test_sha1(), test_sha256(), test_sha384(), and test_sha512().

◆ DllMain()

BOOL WINAPI DllMain ( HINSTANCE  hinst,
DWORD  reason,
LPVOID  reserved 
)

Definition at line 1128 of file bcrypt_main.c.

1129 {
1130  switch (reason)
1131  {
1132  case DLL_PROCESS_ATTACH:
1133  instance = hinst;
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();
1139 #endif
1140  break;
1141 
1142  case DLL_PROCESS_DETACH:
1143  if (reserved) break;
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();
1148 #endif
1149  break;
1150  }
1151  return TRUE;
1152 }
#define TRUE
Definition: types.h:120
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
r reserved
Definition: btrfs.c:2975
#define DLL_PROCESS_DETACH
Definition: compat.h:130
static WCHAR reason[MAX_STRING_RESOURCE_LEN]
Definition: object.c:1904
static HINSTANCE instance
Definition: bcrypt_main.c:44
static HINSTANCE hinst
Definition: edit.c:551

◆ generic_alg_property()

static NTSTATUS generic_alg_property ( enum alg_id  id,
const WCHAR prop,
UCHAR buf,
ULONG  size,
ULONG ret_size 
)
static

Definition at line 866 of file bcrypt_main.c.

867 {
868  if (!strcmpW( prop, BCRYPT_HASH_LENGTH ))
869  {
870  *ret_size = sizeof(ULONG);
871  if (size < sizeof(ULONG))
873  if(buf)
874  *(ULONG*)buf = alg_props[id].hash_length;
875  return STATUS_SUCCESS;
876  }
877 
878  if (!strcmpW( prop, BCRYPT_ALGORITHM_NAME ))
879  {
880  *ret_size = (strlenW(alg_props[id].alg_name)+1)*sizeof(WCHAR);
881  if (size < *ret_size)
883  if(buf)
884  memcpy(buf, alg_props[id].alg_name, *ret_size);
885  return STATUS_SUCCESS;
886  }
887 
888  return STATUS_NOT_IMPLEMENTED;
889 }
const WCHAR * alg_name
Definition: bcrypt_main.c:276
WINE_UNICODE_INLINE unsigned int strlenW(const WCHAR *str)
Definition: unicode.h:212
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
ULONG hash_length
Definition: bcrypt_main.c:275
#define BCRYPT_ALGORITHM_NAME
Definition: bcrypt.h:43
return STATUS_NOT_IMPLEMENTED
GLsizeiptr size
Definition: glext.h:5919
__wchar_t WCHAR
Definition: xmlstorage.h:180
static const struct @315 alg_props[]
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
WINE_UNICODE_INLINE int strcmpW(const WCHAR *str1, const WCHAR *str2)
Definition: unicode.h:229
unsigned int ULONG
Definition: retypes.h:1
#define STATUS_SUCCESS
Definition: shellext.h:65
#define BCRYPT_HASH_LENGTH
Definition: bcrypt.h:50

Referenced by get_alg_property(), and get_hash_property().

◆ get_alg_property()

static NTSTATUS get_alg_property ( enum alg_id  id,
const WCHAR prop,
UCHAR buf,
ULONG  size,
ULONG ret_size 
)
static

Definition at line 891 of file bcrypt_main.c.

892 {
894  ULONG value;
895 
896  status = generic_alg_property( id, prop, buf, size, ret_size );
898  return status;
899 
900  switch (id)
901  {
902  case ALG_ID_MD5:
903  if (!strcmpW( prop, BCRYPT_OBJECT_LENGTH ))
904  {
906  break;
907  }
908  FIXME( "unsupported md5 algorithm property %s\n", debugstr_w(prop) );
909  return STATUS_NOT_IMPLEMENTED;
910 
911  case ALG_ID_RNG:
912  if (!strcmpW( prop, BCRYPT_OBJECT_LENGTH )) return STATUS_NOT_SUPPORTED;
913  FIXME( "unsupported rng algorithm property %s\n", debugstr_w(prop) );
914  return STATUS_NOT_IMPLEMENTED;
915 
916  case ALG_ID_SHA1:
917  if (!strcmpW( prop, BCRYPT_OBJECT_LENGTH ))
918  {
920  break;
921  }
922  FIXME( "unsupported sha1 algorithm property %s\n", debugstr_w(prop) );
923  return STATUS_NOT_IMPLEMENTED;
924 
925  case ALG_ID_SHA256:
926  if (!strcmpW( prop, BCRYPT_OBJECT_LENGTH ))
927  {
929  break;
930  }
931  FIXME( "unsupported sha256 algorithm property %s\n", debugstr_w(prop) );
932  return STATUS_NOT_IMPLEMENTED;
933 
934  case ALG_ID_SHA384:
935  if (!strcmpW( prop, BCRYPT_OBJECT_LENGTH ))
936  {
938  break;
939  }
940  FIXME( "unsupported sha384 algorithm property %s\n", debugstr_w(prop) );
941  return STATUS_NOT_IMPLEMENTED;
942 
943  case ALG_ID_SHA512:
944  if (!strcmpW( prop, BCRYPT_OBJECT_LENGTH ))
945  {
947  break;
948  }
949  FIXME( "unsupported sha512 algorithm property %s\n", debugstr_w(prop) );
950  return STATUS_NOT_IMPLEMENTED;
951 
952  default:
953  FIXME( "unsupported algorithm %u\n", id );
954  return STATUS_NOT_IMPLEMENTED;
955  }
956 
957  if (size < sizeof(ULONG))
958  {
959  *ret_size = sizeof(ULONG);
961  }
962  if (buf) *(ULONG *)buf = value;
963  *ret_size = sizeof(ULONG);
964 
965  return STATUS_SUCCESS;
966 }
return STATUS_NOT_SUPPORTED
Definition: pdh_main.c:93
#define OBJECT_LENGTH_MD5
Definition: bcrypt_main.c:860
#define BCRYPT_OBJECT_LENGTH
Definition: bcrypt.h:56
LONG NTSTATUS
Definition: precomp.h:26
#define OBJECT_LENGTH_SHA512
Definition: bcrypt_main.c:864
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
return STATUS_NOT_IMPLEMENTED
#define debugstr_w
Definition: kernel32.h:32
#define FIXME(fmt,...)
Definition: debug.h:111
GLsizeiptr size
Definition: glext.h:5919
#define OBJECT_LENGTH_SHA1
Definition: bcrypt_main.c:861
#define OBJECT_LENGTH_SHA256
Definition: bcrypt_main.c:862
GLsizei const GLfloat * value
Definition: glext.h:6069
#define OBJECT_LENGTH_SHA384
Definition: bcrypt_main.c:863
WINE_UNICODE_INLINE int strcmpW(const WCHAR *str1, const WCHAR *str2)
Definition: unicode.h:229
unsigned int ULONG
Definition: retypes.h:1
#define STATUS_SUCCESS
Definition: shellext.h:65
static SERVICE_STATUS status
Definition: service.c:31
static NTSTATUS generic_alg_property(enum alg_id id, const WCHAR *prop, UCHAR *buf, ULONG size, ULONG *ret_size)
Definition: bcrypt_main.c:866
Definition: ps.c:97

Referenced by BCryptGetProperty().

◆ get_hash_property()

static NTSTATUS get_hash_property ( enum alg_id  id,
const WCHAR prop,
UCHAR buf,
ULONG  size,
ULONG ret_size 
)
static

Definition at line 968 of file bcrypt_main.c.

969 {
971 
972  status = generic_alg_property( id, prop, buf, size, ret_size );
974  FIXME( "unsupported property %s\n", debugstr_w(prop) );
975  return status;
976 }
LONG NTSTATUS
Definition: precomp.h:26
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
return STATUS_NOT_IMPLEMENTED
#define debugstr_w
Definition: kernel32.h:32
#define FIXME(fmt,...)
Definition: debug.h:111
GLsizeiptr size
Definition: glext.h:5919
static SERVICE_STATUS status
Definition: service.c:31
static NTSTATUS generic_alg_property(enum alg_id id, const WCHAR *prop, UCHAR *buf, ULONG size, ULONG *ret_size)
Definition: bcrypt_main.c:866
Definition: ps.c:97

Referenced by BCryptGetProperty().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( bcrypt  )

Variable Documentation

◆ alg_name

const WCHAR* alg_name

Definition at line 276 of file bcrypt_main.c.

Referenced by generic_alg_property().

◆ alg_props

const { ... } alg_props[]
Initial value:
= {
}
#define BCRYPT_MD5_ALGORITHM
Definition: bcrypt.h:72
#define BCRYPT_SHA256_ALGORITHM
Definition: bcrypt.h:75
#define BCRYPT_ECDSA_P256_ALGORITHM
Definition: bcrypt.h:78
#define BCRYPT_SHA384_ALGORITHM
Definition: bcrypt.h:76
#define BCRYPT_SHA512_ALGORITHM
Definition: bcrypt.h:77
#define BCRYPT_ECDSA_P384_ALGORITHM
Definition: bcrypt.h:79
#define BCRYPT_RNG_ALGORITHM
Definition: bcrypt.h:73
#define BCRYPT_SHA1_ALGORITHM
Definition: bcrypt.h:74

Referenced by generic_alg_property().

◆ hash_length

ULONG hash_length

Definition at line 275 of file bcrypt_main.c.

Referenced by generic_alg_property().

◆ instance

HINSTANCE instance
static

Definition at line 44 of file bcrypt_main.c.

Referenced by DllMain().