ReactOS  0.4.14-dev-50-g13bb5e2
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
}
 

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 854 of file bcrypt_main.c.

◆ OBJECT_LENGTH_SHA1

#define OBJECT_LENGTH_SHA1   278

Definition at line 855 of file bcrypt_main.c.

◆ OBJECT_LENGTH_SHA256

#define OBJECT_LENGTH_SHA256   286

Definition at line 856 of file bcrypt_main.c.

◆ OBJECT_LENGTH_SHA384

#define OBJECT_LENGTH_SHA384   382

Definition at line 857 of file bcrypt_main.c.

◆ OBJECT_LENGTH_SHA512

#define OBJECT_LENGTH_SHA512   382

Definition at line 858 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 

Definition at line 262 of file bcrypt_main.c.

Function Documentation

◆ BCryptCloseAlgorithmProvider()

NTSTATUS WINAPI BCryptCloseAlgorithmProvider ( BCRYPT_ALG_HANDLE  handle,
DWORD  flags 
)

Definition at line 374 of file bcrypt_main.c.

375 {
376  struct algorithm *alg = handle;
377 
378  TRACE( "%p, %08x\n", handle, flags );
379 
380  if (!alg || alg->hdr.magic != MAGIC_ALG) return STATUS_INVALID_HANDLE;
381  HeapFree( GetProcessHeap(), 0, alg );
382  return STATUS_SUCCESS;
383 }
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED LPLOOKUPSERVICE_COMPLETION_ROUTINE HANDLE * handle
Definition: sock.c:82
#define STATUS_INVALID_HANDLE
Definition: ntstatus.h:231
#define MAGIC_ALG
Definition: bcrypt_main.c:255
#define TRACE(s)
Definition: solgame.cpp:4
#define GetProcessHeap()
Definition: compat.h:395
GLbitfield flags
Definition: glext.h:7161
struct object hdr
Definition: bcrypt_main.c:286
return STATUS_SUCCESS
Definition: btrfs.c:2966
#define HeapFree(x, y, z)
Definition: compat.h:394

Referenced by 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 999 of file bcrypt_main.c.

1001 {
1002  struct algorithm *alg = algorithm;
1003  struct hash *hash;
1004  NTSTATUS status;
1005 
1006  TRACE( "%p, %p, %p, %u, %p, %u, %08x - stub\n", algorithm, handle, object, objectlen,
1007  secret, secretlen, flags );
1008  if (flags)
1009  {
1010  FIXME( "unimplemented flags %08x\n", flags );
1011  return STATUS_NOT_IMPLEMENTED;
1012  }
1013 
1014  if (!alg || alg->hdr.magic != MAGIC_ALG) return STATUS_INVALID_HANDLE;
1015  if (object) FIXME( "ignoring object buffer\n" );
1016 
1017  if (!(hash = HeapAlloc( GetProcessHeap(), 0, sizeof(*hash) ))) return STATUS_NO_MEMORY;
1018  hash->hdr.magic = MAGIC_HASH;
1019  hash->alg_id = alg->id;
1020  hash->hmac = alg->hmac;
1021 
1022  if (hash->hmac)
1023  {
1024  status = hmac_init( hash, secret, secretlen );
1025  }
1026  else
1027  {
1028  status = hash_init( hash );
1029  }
1030 
1031  if (status != STATUS_SUCCESS)
1032  {
1033  HeapFree( GetProcessHeap(), 0, hash );
1034  return status;
1035  }
1036 
1037  *handle = hash;
1038  return STATUS_SUCCESS;
1039 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_INVALID_HANDLE
Definition: ntstatus.h:231
static UCHAR ULONG secretlen
Definition: bcrypt.c:29
enum alg_id id
Definition: bcrypt_main.c:287
int hash
Definition: main.c:58
#define FIXME(fmt,...)
Definition: debug.h:110
#define MAGIC_ALG
Definition: bcrypt_main.c:255
#define TRACE(s)
Definition: solgame.cpp:4
#define GetProcessHeap()
Definition: compat.h:395
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:286
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
return STATUS_SUCCESS
Definition: btrfs.c:2966
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:394
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 1041 of file bcrypt_main.c.

1042 {
1043  struct hash *hash = handle;
1044 
1045  TRACE( "%p\n", handle );
1046 
1047  if (!hash || hash->hdr.magic != MAGIC_HASH) return STATUS_INVALID_HANDLE;
1048  HeapFree( GetProcessHeap(), 0, hash );
1049  return STATUS_SUCCESS;
1050 }
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED LPLOOKUPSERVICE_COMPLETION_ROUTINE HANDLE * handle
Definition: sock.c:82
#define STATUS_INVALID_HANDLE
Definition: ntstatus.h:231
#define TRACE(s)
Definition: solgame.cpp:4
#define GetProcessHeap()
Definition: compat.h:395
return STATUS_SUCCESS
Definition: btrfs.c:2966
Definition: _hash_fun.h:40
#define MAGIC_HASH
Definition: bcrypt_main.c:256
#define HeapFree(x, y, z)
Definition: compat.h:394

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 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define FIXME(fmt,...)
Definition: debug.h:110
smooth NULL
Definition: ftsmooth.c:416
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175

◆ BCryptFinishHash()

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

Definition at line 1071 of file bcrypt_main.c.

1072 {
1073  struct hash *hash = handle;
1074 
1075  TRACE( "%p, %p, %u, %08x\n", handle, output, size, flags );
1076 
1077  if (!hash || hash->hdr.magic != MAGIC_HASH) return STATUS_INVALID_HANDLE;
1078  if (!output) return STATUS_INVALID_PARAMETER;
1079 
1080  if (hash->hmac)
1081  {
1082  return hmac_finish( hash, output, size );
1083  }
1084  else
1085  {
1086  return hash_finish( hash, output, size );
1087  }
1088 }
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED LPLOOKUPSERVICE_COMPLETION_ROUTINE HANDLE * handle
Definition: sock.c:82
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:231
#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 291 of file bcrypt_main.c.

292 {
293  const DWORD supported_flags = BCRYPT_USE_SYSTEM_PREFERRED_RNG;
294  struct algorithm *algorithm = handle;
295 
296  TRACE("%p, %p, %u, %08x - semi-stub\n", handle, buffer, count, flags);
297 
298  if (!algorithm)
299  {
300  /* It's valid to call without an algorithm if BCRYPT_USE_SYSTEM_PREFERRED_RNG
301  * is set. In this case the preferred system RNG is used.
302  */
304  return STATUS_INVALID_HANDLE;
305  }
306  else if (algorithm->hdr.magic != MAGIC_ALG || algorithm->id != ALG_ID_RNG)
307  return STATUS_INVALID_HANDLE;
308 
309  if (!buffer)
311 
312  if (flags & ~supported_flags)
313  FIXME("unsupported flags %08x\n", flags & ~supported_flags);
314 
315  if (algorithm)
316  FIXME("ignoring selected algorithm\n");
317 
318  /* When zero bytes are requested the function returns success too. */
319  if (!count)
320  return STATUS_SUCCESS;
321 
323  {
324  if (RtlGenRandom(buffer, count))
325  return STATUS_SUCCESS;
326  }
327 
328  FIXME("called with unsupported parameters, returning error\n");
329  return STATUS_NOT_IMPLEMENTED;
330 }
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED LPLOOKUPSERVICE_COMPLETION_ROUTINE HANDLE * handle
Definition: sock.c:82
#define BCRYPT_USE_SYSTEM_PREFERRED_RNG
Definition: bcrypt.h:171
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#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:231
enum alg_id id
Definition: bcrypt_main.c:287
#define FIXME(fmt,...)
Definition: debug.h:110
#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:286
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by test_BCryptGenRandom(), and test_rng().

◆ BCryptGetFipsAlgorithmMode()

NTSTATUS WINAPI BCryptGetFipsAlgorithmMode ( BOOLEAN enabled)

Definition at line 385 of file bcrypt_main.c.

386 {
387  FIXME("%p - semi-stub\n", enabled);
388 
389  if (!enabled)
391 
392  *enabled = FALSE;
393  return STATUS_SUCCESS;
394 }
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
GLenum GLenum GLsizei const GLuint GLboolean enabled
Definition: glext.h:7750
#define FIXME(fmt,...)
Definition: debug.h:110
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by test_BCryptGetFipsAlgorithmMode().

◆ BCryptGetProperty()

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

Definition at line 972 of file bcrypt_main.c.

973 {
974  struct object *object = handle;
975 
976  TRACE( "%p, %s, %p, %u, %p, %08x\n", handle, wine_dbgstr_w(prop), buffer, count, res, flags );
977 
978  if (!object) return STATUS_INVALID_HANDLE;
979  if (!prop || !res) return STATUS_INVALID_PARAMETER;
980 
981  switch (object->magic)
982  {
983  case MAGIC_ALG:
984  {
985  const struct algorithm *alg = (const struct algorithm *)object;
986  return get_alg_property( alg->id, prop, buffer, count, res );
987  }
988  case MAGIC_HASH:
989  {
990  const struct hash *hash = (const struct hash *)object;
991  return get_hash_property( hash->alg_id, prop, buffer, count, res );
992  }
993  default:
994  WARN( "unknown magic %08x\n", object->magic );
995  return STATUS_INVALID_HANDLE;
996  }
997 }
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED LPLOOKUPSERVICE_COMPLETION_ROUTINE HANDLE * handle
Definition: sock.c:82
#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:111
static NTSTATUS get_hash_property(enum alg_id id, const WCHAR *prop, UCHAR *buf, ULONG size, ULONG *ret_size)
Definition: bcrypt_main.c:962
static NTSTATUS get_alg_property(enum alg_id id, const WCHAR *prop, UCHAR *buf, ULONG size, ULONG *ret_size)
Definition: bcrypt_main.c:885
GLuint buffer
Definition: glext.h:5915
ULONG magic
Definition: bcrypt_main.c:259
#define STATUS_INVALID_HANDLE
Definition: ntstatus.h:231
enum alg_id id
Definition: bcrypt_main.c:287
#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 1090 of file bcrypt_main.c.

1092 {
1093  NTSTATUS status;
1095 
1096  TRACE( "%p, %p, %u, %p, %u, %p, %u\n", algorithm, secret, secretlen,
1098 
1100  if (status != STATUS_SUCCESS)
1101  {
1102  return status;
1103  }
1104 
1106  if (status != STATUS_SUCCESS)
1107  {
1109  return status;
1110  }
1111 
1113  if (status != STATUS_SUCCESS)
1114  {
1116  return status;
1117  }
1118 
1119  return BCryptDestroyHash( handle );
1120 }
static UCHAR ULONG UCHAR ULONG UCHAR ULONG outputlen
Definition: bcrypt.c:29
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED LPLOOKUPSERVICE_COMPLETION_ROUTINE HANDLE * handle
Definition: sock.c:82
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:1052
NTSTATUS WINAPI BCryptFinishHash(BCRYPT_HASH_HANDLE handle, UCHAR *output, ULONG size, ULONG flags)
Definition: bcrypt_main.c:1071
static UCHAR ULONG secretlen
Definition: bcrypt.c:29
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4
static UCHAR * secret
Definition: bcrypt.c:29
GLenum GLenum GLenum input
Definition: glext.h:9031
static UCHAR ULONG UCHAR ULONG inputlen
Definition: bcrypt.c:29
return STATUS_SUCCESS
Definition: btrfs.c:2966
static SERVICE_STATUS status
Definition: service.c:31
NTSTATUS WINAPI BCryptDestroyHash(BCRYPT_HASH_HANDLE handle)
Definition: bcrypt_main.c:1041
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:999
Definition: ps.c:97

◆ BCryptHashData()

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

Definition at line 1052 of file bcrypt_main.c.

1053 {
1054  struct hash *hash = handle;
1055 
1056  TRACE( "%p, %p, %u, %08x\n", handle, input, size, flags );
1057 
1058  if (!hash || hash->hdr.magic != MAGIC_HASH) return STATUS_INVALID_HANDLE;
1059  if (!input) return STATUS_SUCCESS;
1060 
1061  if (hash->hmac)
1062  {
1063  return hmac_update( hash, input, size );
1064  }
1065  else
1066  {
1067  return hash_update( hash, input, size );
1068  }
1069 }
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED LPLOOKUPSERVICE_COMPLETION_ROUTINE HANDLE * handle
Definition: sock.c:82
#define STATUS_INVALID_HANDLE
Definition: ntstatus.h:231
#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
return STATUS_SUCCESS
Definition: btrfs.c:2966
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 332 of file bcrypt_main.c.

333 {
334  struct algorithm *alg;
335  enum alg_id alg_id;
336 
337  const DWORD supported_flags = BCRYPT_ALG_HANDLE_HMAC_FLAG;
338 
339  TRACE( "%p, %s, %s, %08x\n", handle, wine_dbgstr_w(id), wine_dbgstr_w(implementation), flags );
340 
341  if (!handle || !id) return STATUS_INVALID_PARAMETER;
342  if (flags & ~supported_flags)
343  {
344  FIXME( "unsupported flags %08x\n", flags & ~supported_flags);
345  return STATUS_NOT_IMPLEMENTED;
346  }
347 
349  else if (!strcmpW( id, BCRYPT_MD5_ALGORITHM )) alg_id = ALG_ID_MD5;
350  else if (!strcmpW( id, BCRYPT_RNG_ALGORITHM )) alg_id = ALG_ID_RNG;
354  else
355  {
356  FIXME( "algorithm %s not supported\n", debugstr_w(id) );
357  return STATUS_NOT_IMPLEMENTED;
358  }
359  if (implementation && strcmpW( implementation, MS_PRIMITIVE_PROVIDER ))
360  {
361  FIXME( "implementation %s not supported\n", debugstr_w(implementation) );
362  return STATUS_NOT_IMPLEMENTED;
363  }
364 
365  if (!(alg = HeapAlloc( GetProcessHeap(), 0, sizeof(*alg) ))) return STATUS_NO_MEMORY;
366  alg->hdr.magic = MAGIC_ALG;
367  alg->id = alg_id;
369 
370  *handle = alg;
371  return STATUS_SUCCESS;
372 }
#define MS_PRIMITIVE_PROVIDER
Definition: bcrypt.h:69
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#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
enum alg_id id
Definition: bcrypt_main.c:287
#define debugstr_w
Definition: kernel32.h:32
#define FIXME(fmt,...)
Definition: debug.h:110
#define MAGIC_ALG
Definition: bcrypt_main.c:255
#define TRACE(s)
Definition: solgame.cpp:4
#define GetProcessHeap()
Definition: compat.h:395
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:286
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
WINE_UNICODE_INLINE int strcmpW(const WCHAR *str1, const WCHAR *str2)
Definition: unicode.h:229
#define BCRYPT_RNG_ALGORITHM
Definition: bcrypt.h:73
return STATUS_SUCCESS
Definition: btrfs.c:2966
#define BCRYPT_SHA1_ALGORITHM
Definition: bcrypt.h:74
alg_id
Definition: bcrypt_main.c:262

Referenced by 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 1122 of file bcrypt_main.c.

1123 {
1124  switch (reason)
1125  {
1126  case DLL_PROCESS_ATTACH:
1127  instance = hinst;
1129 #if defined(HAVE_GNUTLS_HASH) && !defined(HAVE_COMMONCRYPTO_COMMONDIGEST_H)
1130  gnutls_initialize();
1131 #elif defined(SONAME_LIBMBEDTLS) && !defined(HAVE_COMMONCRYPTO_COMMONDIGEST_H) && !defined(__REACTOS__)
1132  mbedtls_initialize();
1133 #endif
1134  break;
1135 
1136  case DLL_PROCESS_DETACH:
1137  if (reserved) break;
1138 #if defined(HAVE_GNUTLS_HASH) && !defined(HAVE_COMMONCRYPTO_COMMONDIGEST_H)
1139  gnutls_uninitialize();
1140 #elif defined(SONAME_LIBMBEDTLS) && !defined(HAVE_COMMONCRYPTO_COMMONDIGEST_H) && !defined(__REACTOS__)
1141  mbedtls_uninitialize();
1142 #endif
1143  break;
1144  }
1145  return TRUE;
1146 }
#define TRUE
Definition: types.h:120
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
#define DLL_PROCESS_ATTACH
Definition: compat.h:120
r reserved
Definition: btrfs.c:2893
#define DLL_PROCESS_DETACH
Definition: compat.h:119
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 860 of file bcrypt_main.c.

861 {
862  if (!strcmpW( prop, BCRYPT_HASH_LENGTH ))
863  {
864  *ret_size = sizeof(ULONG);
865  if (size < sizeof(ULONG))
867  if(buf)
868  *(ULONG*)buf = alg_props[id].hash_length;
869  return STATUS_SUCCESS;
870  }
871 
872  if (!strcmpW( prop, BCRYPT_ALGORITHM_NAME ))
873  {
874  *ret_size = (strlenW(alg_props[id].alg_name)+1)*sizeof(WCHAR);
875  if (size < *ret_size)
877  if(buf)
878  memcpy(buf, alg_props[id].alg_name, *ret_size);
879  return STATUS_SUCCESS;
880  }
881 
882  return STATUS_NOT_IMPLEMENTED;
883 }
const WCHAR * alg_name
Definition: bcrypt_main.c:274
WINE_UNICODE_INLINE unsigned int strlenW(const WCHAR *str)
Definition: unicode.h:212
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:64
ULONG hash_length
Definition: bcrypt_main.c:273
#define BCRYPT_ALGORITHM_NAME
Definition: bcrypt.h:43
GLsizeiptr size
Definition: glext.h:5919
__wchar_t WCHAR
Definition: xmlstorage.h:180
static const struct @313 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
return STATUS_SUCCESS
Definition: btrfs.c:2966
#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 885 of file bcrypt_main.c.

886 {
888  ULONG value;
889 
890  status = generic_alg_property( id, prop, buf, size, ret_size );
892  return status;
893 
894  switch (id)
895  {
896  case ALG_ID_MD5:
897  if (!strcmpW( prop, BCRYPT_OBJECT_LENGTH ))
898  {
900  break;
901  }
902  FIXME( "unsupported md5 algorithm property %s\n", debugstr_w(prop) );
903  return STATUS_NOT_IMPLEMENTED;
904 
905  case ALG_ID_RNG:
906  if (!strcmpW( prop, BCRYPT_OBJECT_LENGTH )) return STATUS_NOT_SUPPORTED;
907  FIXME( "unsupported rng algorithm property %s\n", debugstr_w(prop) );
908  return STATUS_NOT_IMPLEMENTED;
909 
910  case ALG_ID_SHA1:
911  if (!strcmpW( prop, BCRYPT_OBJECT_LENGTH ))
912  {
914  break;
915  }
916  FIXME( "unsupported sha1 algorithm property %s\n", debugstr_w(prop) );
917  return STATUS_NOT_IMPLEMENTED;
918 
919  case ALG_ID_SHA256:
920  if (!strcmpW( prop, BCRYPT_OBJECT_LENGTH ))
921  {
923  break;
924  }
925  FIXME( "unsupported sha256 algorithm property %s\n", debugstr_w(prop) );
926  return STATUS_NOT_IMPLEMENTED;
927 
928  case ALG_ID_SHA384:
929  if (!strcmpW( prop, BCRYPT_OBJECT_LENGTH ))
930  {
932  break;
933  }
934  FIXME( "unsupported sha384 algorithm property %s\n", debugstr_w(prop) );
935  return STATUS_NOT_IMPLEMENTED;
936 
937  case ALG_ID_SHA512:
938  if (!strcmpW( prop, BCRYPT_OBJECT_LENGTH ))
939  {
941  break;
942  }
943  FIXME( "unsupported sha512 algorithm property %s\n", debugstr_w(prop) );
944  return STATUS_NOT_IMPLEMENTED;
945 
946  default:
947  FIXME( "unsupported algorithm %u\n", id );
948  return STATUS_NOT_IMPLEMENTED;
949  }
950 
951  if (size < sizeof(ULONG))
952  {
953  *ret_size = sizeof(ULONG);
955  }
956  if (buf) *(ULONG *)buf = value;
957  *ret_size = sizeof(ULONG);
958 
959  return STATUS_SUCCESS;
960 }
#define OBJECT_LENGTH_MD5
Definition: bcrypt_main.c:854
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define BCRYPT_OBJECT_LENGTH
Definition: bcrypt.h:56
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
LONG NTSTATUS
Definition: precomp.h:26
#define OBJECT_LENGTH_SHA512
Definition: bcrypt_main.c:858
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:64
#define debugstr_w
Definition: kernel32.h:32
#define FIXME(fmt,...)
Definition: debug.h:110
GLsizeiptr size
Definition: glext.h:5919
#define OBJECT_LENGTH_SHA1
Definition: bcrypt_main.c:855
#define OBJECT_LENGTH_SHA256
Definition: bcrypt_main.c:856
GLsizei const GLfloat * value
Definition: glext.h:6069
#define OBJECT_LENGTH_SHA384
Definition: bcrypt_main.c:857
WINE_UNICODE_INLINE int strcmpW(const WCHAR *str1, const WCHAR *str2)
Definition: unicode.h:229
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:409
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2966
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:860
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 962 of file bcrypt_main.c.

963 {
965 
966  status = generic_alg_property( id, prop, buf, size, ret_size );
968  FIXME( "unsupported property %s\n", debugstr_w(prop) );
969  return status;
970 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
LONG NTSTATUS
Definition: precomp.h:26
#define debugstr_w
Definition: kernel32.h:32
#define FIXME(fmt,...)
Definition: debug.h:110
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:860
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 274 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_SHA384_ALGORITHM
Definition: bcrypt.h:76
#define BCRYPT_SHA512_ALGORITHM
Definition: bcrypt.h:77
#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 273 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().