ReactOS 0.4.17-dev-806-gffa4164
bcrypt.c File Reference
#include <stdio.h>
#include <ntstatus.h>
#include <windows.h>
#include <bcrypt.h>
#include <wincrypt.h>
#include "wine/test.h"
Include dependency graph for bcrypt.c:

Go to the source code of this file.

Classes

struct  hash_test
 

Macros

#define WIN32_NO_STATUS
 
#define test_object_length(a)   _test_object_length(__LINE__,a)
 
#define test_hash_length(a, b)   _test_hash_length(__LINE__,a,b)
 
#define test_alg_name(a, b)   _test_alg_name(__LINE__,a,b)
 
#define RACE_TEST_COUNT   200
 
#define NCRYPT_SCHANNEL_INTERFACE   0x00010002
 

Functions

static NTSTATUS (WINAPI *pBCryptOpenAlgorithmProvider)(BCRYPT_ALG_HANDLE *
 
static void (WINAPI *pBCryptFreeBuffer)(void *)
 
static const WCHAR ULONG CRYPT_CONTEXT_FUNCTIONS **static void test_BCryptGenRandom (void)
 
static void test_BCryptGetFipsAlgorithmMode (void)
 
static void format_hash (const UCHAR *bytes, ULONG size, char *buf)
 
static void _test_object_length (unsigned line, void *handle)
 
static void _test_hash_length (unsigned line, void *handle, ULONG exlen)
 
static void _test_alg_name (unsigned line, void *handle, const WCHAR *exname)
 
static void test_hash (const struct hash_test *test)
 
static void test_hashes (void)
 
static void test_BcryptHash (void)
 
static void test_BcryptDeriveKeyPBKDF2 (void)
 
static void test_rng (void)
 
static void test_aes (void)
 
static void test_3des (void)
 
static void test_BCryptGenerateSymmetricKey (void)
 
static DWORD WINAPI encrypt_race_thread (void *parameter)
 
static void test_BCryptEncrypt (void)
 
static void test_BCryptDecrypt (void)
 
static void test_key_import_export (void)
 
static void test_ECDSA (void)
 
static void test_rsa_encrypt (void)
 
static void test_RSA (void)
 
static void test_RSA_SIGN (void)
 
static void test_ECDH (void)
 
static void test_DH (void)
 
static void test_BCryptEnumContextFunctions (void)
 
static void test_BCryptSignHash (void)
 
static void test_BCryptEnumAlgorithms (void)
 
static void test_aes_vector (void)
 
static void test_BcryptDeriveKeyCapi (void)
 
static void test_DSA (void)
 
static void test_SecretAgreement (void)
 
static void test_RC4 (void)
 
static void test_PBKDF2 (void)
 
 START_TEST (bcrypt)
 

Variables

static LPCWSTR
 
static ULONG
 
static BCRYPT_HASH_HANDLE PUCHAR
 
static ULONGLONG
 
static BCRYPT_KEY_HANDLE
 
static BCRYPT_ALG_HANDLE
 
static UCHAR password [] = "password"
 
static UCHAR salt [] = "salt"
 
static UCHAR long_password [] = "passwordPASSWORDpassword"
 
static UCHAR long_salt [] = "saltSALTsaltSALTsaltSALTsaltSALTsalt"
 
static UCHAR password_NUL [] = "pass\0word"
 
static UCHAR salt_NUL [] = "sa\0lt"
 
static UCHAR dk1 [] = "0c60c80f961f0e71f3a9b524af6012062fe037a6"
 
static UCHAR dk2 [] = "ea6c014dc72d6f8ccd1ed92ace1d41f0d8de8957"
 
static UCHAR dk3 [] = "4b007901b765489abead49d926f721d065a429c1"
 
static UCHAR dk4 [] = "364dd6bc200ec7d197f1b85f4a61769010717124"
 
static UCHAR dk5 [] = "3d2eec4fe41c849b80c8d83662c0e44a8b291a964cf2f07038"
 
static UCHAR dk6 [] = "56fa6aa75548099dcc37d7f03425e0c3"
 
static UCHAR dk7 [] = "8754c32c64b0f524fc50c00f788135de"
 
struct {
   ULONG   pwd_len
 
   ULONG   salt_len
 
   ULONGLONG   iterations
 
   ULONG   dk_len
 
   UCHAR *   pwd
 
   UCHAR *   salt
 
   const UCHAR *   dk
 
rfc6070 []
 
static LONG encrypt_race_start_barrier
 
static BYTE eccPrivkey []
 
static BYTE eccPubkey []
 
static BYTE certHash []
 
static BYTE certSignature []
 
static UCHAR rsaPublicBlob []
 
static UCHAR rsaHash []
 
static UCHAR rsaSignature []
 
static UCHAR rsaPrivateBlob []
 
static UCHAR rsaFullPrivateBlob []
 
struct {
   PUBLICKEYSTRUC   header
 
   RSAPUBKEY   rsapubkey
 
   BYTE   modulus [512/8]
 
   BYTE   prime1 [512/16]
 
   BYTE   prime2 [512/16]
 
   BYTE   exp1 [512/16]
 
   BYTE   exp2 [512/16]
 
   BYTE   coefficient [512/16]
 
   BYTE   private_exp [512/8]
 
rsaLegacyPrivateBlob
 
static UCHAR rsaPublicBlobWithInvalidPublicExpSize []
 
static const UCHAR rsa_encrypted_no_padding []
 
static BYTE eccprivkey []
 
static BYTE ecdh_pubkey []
 
static BYTE ecdh_secret []
 
BCryptBuffer hash_param_buffers []
 
BCryptBufferDesc hash_params
 
static BYTE hashed_secret []
 
static BYTE dh_pubkey []
 
static BYTE dh_privkey []
 
static BYTE dh_secret []
 
static BYTE dh_hashed_secret []
 
BCryptBuffer dh_hash_param_buffers []
 
BCryptBufferDesc dh_hash_params
 
static BYTE rsapublic []
 
static UCHAR dsaHash []
 
static UCHAR dsaSignature []
 
static UCHAR dsaPublicBlob []
 
static UCHAR dssKey []
 

Macro Definition Documentation

◆ NCRYPT_SCHANNEL_INTERFACE

#define NCRYPT_SCHANNEL_INTERFACE   0x00010002

Definition at line 3505 of file bcrypt.c.

◆ RACE_TEST_COUNT

#define RACE_TEST_COUNT   200

Definition at line 1002 of file bcrypt.c.

◆ test_alg_name

#define test_alg_name (   a,
  b 
)    _test_alg_name(__LINE__,a,b)

Definition at line 213 of file bcrypt.c.

◆ test_hash_length

#define test_hash_length (   a,
  b 
)    _test_hash_length(__LINE__,a,b)

Definition at line 201 of file bcrypt.c.

◆ test_object_length

#define test_object_length (   a)    _test_object_length(__LINE__,a)

Definition at line 165 of file bcrypt.c.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 23 of file bcrypt.c.

Function Documentation

◆ _test_alg_name()

static void _test_alg_name ( unsigned  line,
void handle,
const WCHAR exname 
)
static

Definition at line 214 of file bcrypt.c.

215{
216 ULONG size = 0xdeadbeef;
217 UCHAR buf[256];
218 const WCHAR *name = (const WCHAR*)buf;
220
221 status = pBCryptGetProperty(handle, BCRYPT_ALGORITHM_NAME, buf, sizeof(buf), &size, 0);
222 ok_(__FILE__,line)(status == STATUS_SUCCESS, "BCryptGetProperty failed: 0x%08x\n", status);
223 ok_(__FILE__,line)(size == (lstrlenW(exname) + 1) * sizeof(WCHAR), "got %u\n", size);
224 ok_(__FILE__,line)(!lstrcmpW(name, exname), "alg name = %s, expected %s\n", wine_dbgstr_w(name),
225 wine_dbgstr_w(exname));
226}
#define ok_(x1, x2)
Definition: atltest.h:61
LONG NTSTATUS
Definition: precomp.h:26
#define BCRYPT_ALGORITHM_NAME
Definition: bcrypt.h:43
#define lstrlenW
Definition: compat.h:750
int WINAPI lstrcmpW(LPCWSTR str1, LPCWSTR str2)
Definition: locale.c:4152
GLsizeiptr size
Definition: glext.h:5919
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define wine_dbgstr_w
Definition: kernel32.h:34
short WCHAR
Definition: pedump.c:58
#define STATUS_SUCCESS
Definition: shellext.h:65
Definition: parser.c:49
Definition: name.c:39
Definition: ps.c:97
unsigned char UCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59

◆ _test_hash_length()

static void _test_hash_length ( unsigned  line,
void handle,
ULONG  exlen 
)
static

Definition at line 202 of file bcrypt.c.

203{
204 ULONG len = 0xdeadbeef, size = 0xdeadbeef;
206
207 status = pBCryptGetProperty(handle, BCRYPT_HASH_LENGTH, (UCHAR *)&len, sizeof(len), &size, 0);
208 ok_(__FILE__,line)(status == STATUS_SUCCESS, "BCryptGetProperty failed: 0x%08x\n", status);
209 ok_(__FILE__,line)(size == sizeof(len), "got %u\n", size);
210 ok_(__FILE__,line)(len == exlen, "len = %u, expected %u\n", len, exlen);
211}
#define BCRYPT_HASH_LENGTH
Definition: bcrypt.h:50
GLenum GLsizei len
Definition: glext.h:6722

◆ _test_object_length()

static void _test_object_length ( unsigned  line,
void handle 
)
static

Definition at line 166 of file bcrypt.c.

167{
169 ULONG len, size;
170
171 len = size = 0xdeadbeef;
172 status = pBCryptGetProperty(NULL, BCRYPT_OBJECT_LENGTH, (UCHAR *)&len, sizeof(len), &size, 0);
173 ok_(__FILE__,line)(status == STATUS_INVALID_HANDLE, "BCryptGetProperty failed: 0x%x\n", status);
174
175 len = size = 0xdeadbeef;
176 status = pBCryptGetProperty(handle, NULL, (UCHAR *)&len, sizeof(len), &size, 0);
177 ok_(__FILE__,line)(status == STATUS_INVALID_PARAMETER, "BCryptGetProperty failed: 0x%x\n", status);
178
179 len = size = 0xdeadbeef;
180 status = pBCryptGetProperty(handle, BCRYPT_OBJECT_LENGTH, (UCHAR *)&len, sizeof(len), NULL, 0);
181 ok_(__FILE__,line)(status == STATUS_INVALID_PARAMETER, "BCryptGetProperty failed: 0x%x\n", status);
182
183 len = size = 0xdeadbeef;
184 status = pBCryptGetProperty(handle, BCRYPT_OBJECT_LENGTH, NULL, sizeof(len), &size, 0);
185 ok_(__FILE__,line)(status == STATUS_SUCCESS, "BCryptGetProperty failed: 0x%x\n", status);
186 ok_(__FILE__,line)(size == sizeof(len), "got %u\n", size);
187
188 len = size = 0xdeadbeef;
189 status = pBCryptGetProperty(handle, BCRYPT_OBJECT_LENGTH, (UCHAR *)&len, 0, &size, 0);
190 ok_(__FILE__,line)(status == STATUS_BUFFER_TOO_SMALL, "BCryptGetProperty failed: 0x%x\n", status);
191 ok_(__FILE__,line)(len == 0xdeadbeef, "got %u\n", len);
192 ok_(__FILE__,line)(size == sizeof(len), "got %u\n", size);
193
194 len = size = 0xdeadbeef;
195 status = pBCryptGetProperty(handle, BCRYPT_OBJECT_LENGTH, (UCHAR *)&len, sizeof(len), &size, 0);
196 ok_(__FILE__,line)(status == STATUS_SUCCESS, "BCryptGetProperty failed: 0x%x\n", status);
197 ok_(__FILE__,line)(len != 0xdeadbeef, "len not set\n");
198 ok_(__FILE__,line)(size == sizeof(len), "got %u\n", size);
199}
#define BCRYPT_OBJECT_LENGTH
Definition: bcrypt.h:56
#define STATUS_INVALID_HANDLE
Definition: d3dkmdt.h:40
#define NULL
Definition: types.h:112
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135

◆ encrypt_race_thread()

static DWORD WINAPI encrypt_race_thread ( void parameter)
static

Definition at line 1005 of file bcrypt.c.

1006{
1007 static UCHAR nonce[] =
1008 {0x11,0x20,0x30,0x40,0x50,0x60,0x10,0x20,0x30,0x40,0x50,0x60};
1009 static UCHAR auth_data[] =
1010 {0x61,0x50,0x40,0x30,0x20,0x10,0x60,0x50,0x40,0x30,0x20,0x10};
1011 static UCHAR data2[] =
1012 {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
1013 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10};
1014 static UCHAR expected4[] =
1015 {0xb2,0x27,0x19,0x09,0xc7,0x89,0xdc,0x52,0x24,0x83,0x3a,0x55,0x34,0x76,0x2c,0xbf,
1016 0x15,0xa1,0xcb,0x40,0x78,0x11,0xba,0xbc,0xa4,0x76,0x69,0x7c,0x75,0x4f,0x11,0xba};
1017 static UCHAR expected_tag3[] =
1018 {0xef,0xee,0x75,0x99,0xb8,0x12,0xe9,0xf0,0xb4,0xcc,0x65,0x11,0x67,0x60,0x2d,0xe6};
1019
1021 BCRYPT_KEY_HANDLE key = parameter;
1022 UCHAR ciphertext[48], tag[16];
1023 unsigned int i, test;
1024 NTSTATUS ret;
1025 ULONG size;
1026
1027 memset(&auth_info, 0, sizeof(auth_info));
1028 auth_info.cbSize = sizeof(auth_info);
1029 auth_info.dwInfoVersion = 1;
1030 auth_info.pbNonce = nonce;
1031 auth_info.cbNonce = sizeof(nonce);
1032 auth_info.pbTag = tag;
1033 auth_info.cbTag = sizeof(tag);
1034 auth_info.pbAuthData = auth_data;
1035 auth_info.cbAuthData = sizeof(auth_data);
1036
1039 ;
1040
1041 for (test = 0; test < RACE_TEST_COUNT; ++test)
1042 {
1043 size = 0;
1044 memset(ciphertext, 0xff, sizeof(ciphertext));
1045 memset(tag, 0xff, sizeof(tag));
1046 ret = pBCryptEncrypt(key, data2, 32, &auth_info, NULL, 0, ciphertext, 32, &size, 0);
1047 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1048 ok(size == 32, "got %u\n", size);
1049 ok(!memcmp(ciphertext, expected4, sizeof(expected4)), "wrong data\n");
1050 ok(!memcmp(tag, expected_tag3, sizeof(expected_tag3)), "wrong tag\n");
1051 for (i = 0; i < 32; i++)
1052 ok(ciphertext[i] == expected4[i], "%u: %02x != %02x\n", i, ciphertext[i], expected4[i]);
1053 for (i = 0; i < 16; i++)
1054 ok(tag[i] == expected_tag3[i], "%u: %02x != %02x\n", i, tag[i], expected_tag3[i]);
1055 }
1056
1057 return 0;
1058}
#define InterlockedIncrement
Definition: armddk.h:53
#define ok(value,...)
Definition: atltest.h:57
static LONG encrypt_race_start_barrier
Definition: bcrypt.c:1003
#define RACE_TEST_COUNT
Definition: bcrypt.c:1002
_ACRTIMP int __cdecl memcmp(const void *, const void *, size_t)
Definition: string.c:2807
return ret
Definition: mutex.c:147
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 const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define InterlockedCompareExchange
Definition: interlocked.h:119
#define test
Definition: rosglue.h:37
#define memset(x, y, z)
Definition: compat.h:39
Definition: tftpd.h:138
Definition: copy.c:22
Definition: ecma_167.h:138

Referenced by test_BCryptEncrypt().

◆ format_hash()

static void format_hash ( const UCHAR bytes,
ULONG  size,
char buf 
)
static

Definition at line 154 of file bcrypt.c.

155{
156 ULONG i;
157 buf[0] = '\0';
158 for (i = 0; i < size; i++)
159 {
160 sprintf(buf + i * 2, "%02x", bytes[i]);
161 }
162 return;
163}
static unsigned char bytes[4]
Definition: adnsresfilter.c:74
#define sprintf
Definition: sprintf.c:45

Referenced by test_BcryptDeriveKeyPBKDF2(), test_BcryptHash(), and test_hash().

◆ NTSTATUS()

static NTSTATUS ( WINAPI pBCryptOpenAlgorithmProvider)
static

◆ START_TEST()

START_TEST ( bcrypt  )

Definition at line 4526 of file bcrypt.c.

4527{
4529
4530 module = LoadLibraryA("bcrypt.dll");
4531 if (!module)
4532 {
4533 win_skip("bcrypt.dll not found\n");
4534 return;
4535 }
4536
4537 pBCryptOpenAlgorithmProvider = (void *)GetProcAddress(module, "BCryptOpenAlgorithmProvider");
4538 pBCryptCloseAlgorithmProvider = (void *)GetProcAddress(module, "BCryptCloseAlgorithmProvider");
4539 pBCryptGetFipsAlgorithmMode = (void *)GetProcAddress(module, "BCryptGetFipsAlgorithmMode");
4540 pBCryptCreateHash = (void *)GetProcAddress(module, "BCryptCreateHash");
4541 pBCryptHash = (void *)GetProcAddress(module, "BCryptHash");
4542 pBCryptHashData = (void *)GetProcAddress(module, "BCryptHashData");
4543 pBCryptFinishHash = (void *)GetProcAddress(module, "BCryptFinishHash");
4544 pBCryptDestroyHash = (void *)GetProcAddress(module, "BCryptDestroyHash");
4545 pBCryptGenRandom = (void *)GetProcAddress(module, "BCryptGenRandom");
4546 pBCryptGetProperty = (void *)GetProcAddress(module, "BCryptGetProperty");
4547 pBCryptKeyDerivation = (void *)GetProcAddress(module, "BCryptKeyDerivation");
4548 pBCryptDeriveKeyPBKDF2 = (void *)GetProcAddress(module, "BCryptDeriveKeyPBKDF2");
4549 pBCryptSetProperty = (void *)GetProcAddress(module, "BCryptSetProperty");
4550 pBCryptGenerateSymmetricKey = (void *)GetProcAddress(module, "BCryptGenerateSymmetricKey");
4551 pBCryptEncrypt = (void *)GetProcAddress(module, "BCryptEncrypt");
4552 pBCryptDuplicateKey = (void *)GetProcAddress(module, "BCryptDuplicateKey");
4553 pBCryptDestroyKey = (void *)GetProcAddress(module, "BCryptDestroyKey");
4554 pBCryptDecrypt = (void *)GetProcAddress(module, "BCryptDecrypt");
4555 pBCryptImportKey = (void *)GetProcAddress(module, "BCryptImportKey");
4556 pBCryptExportKey = (void *)GetProcAddress(module, "BCryptExportKey");
4557 pBCryptImportKeyPair = (void *)GetProcAddress(module, "BCryptImportKeyPair");
4558 pBCryptVerifySignature = (void *)GetProcAddress(module, "BCryptVerifySignature");
4559 pBCryptGenerateKeyPair = (void *)GetProcAddress(module, "BCryptGenerateKeyPair");
4560 pBCryptFinalizeKeyPair = (void *)GetProcAddress(module, "BCryptFinalizeKeyPair");
4561 pBCryptSignHash = (void *)GetProcAddress(module, "BCryptSignHash");
4562 pBCryptSecretAgreement = (void *)GetProcAddress(module, "BCryptSecretAgreement");
4563 pBCryptDeriveKey = (void *)GetProcAddress(module, "BCryptDeriveKey");
4564 pBCryptDestroySecret = (void *)GetProcAddress(module, "BCryptDestroySecret");
4565 pBCryptEnumAlgorithms = (void *)GetProcAddress(module, "BCryptEnumAlgorithms");
4566 pBCryptFreeBuffer = (void *)GetProcAddress(module, "BCryptFreeBuffer");
4567 pBCryptDeriveKeyCapi = (void *)GetProcAddress(module, "BCryptDeriveKeyCapi");
4568 pBCryptEnumContextFunctions = (void *)GetProcAddress(module, "BCryptEnumContextFunctions");
4569
4572 test_hashes();
4575 test_rng();
4576 test_3des();
4577 test_aes();
4582 test_ECDSA();
4583 test_RSA();
4584 test_RSA_SIGN();
4585 test_ECDH();
4586 test_DH();
4592 test_DSA();
4595 test_RC4();
4596 test_PBKDF2();
4597
4599}
static void test_BCryptDecrypt(void)
Definition: bcrypt.c:1726
static void test_key_import_export(void)
Definition: bcrypt.c:2121
static void test_DH(void)
Definition: bcrypt.c:3349
static void test_ECDH(void)
Definition: bcrypt.c:3102
static void test_BCryptEnumAlgorithms(void)
Definition: bcrypt.c:3642
static void test_aes_vector(void)
Definition: bcrypt.c:3679
static void test_ECDSA(void)
Definition: bcrypt.c:2264
static void test_BcryptHash(void)
Definition: bcrypt.c:461
static void test_DSA(void)
Definition: bcrypt.c:3871
static void test_BCryptGetFipsAlgorithmMode(void)
Definition: bcrypt.c:106
static void test_BCryptSignHash(void)
Definition: bcrypt.c:3539
static void test_RSA(void)
Definition: bcrypt.c:2704
static void test_BcryptDeriveKeyPBKDF2(void)
Definition: bcrypt.c:555
static void test_BCryptEnumContextFunctions(void)
Definition: bcrypt.c:3507
static void test_rsa_encrypt(void)
Definition: bcrypt.c:2529
static void test_aes(void)
Definition: bcrypt.c:628
static void test_RSA_SIGN(void)
Definition: bcrypt.c:2942
static void test_BcryptDeriveKeyCapi(void)
Definition: bcrypt.c:3741
static void test_BCryptEncrypt(void)
Definition: bcrypt.c:1060
static void test_rng(void)
Definition: bcrypt.c:597
static void test_3des(void)
Definition: bcrypt.c:718
static void test_SecretAgreement(void)
Definition: bcrypt.c:3976
static void test_RC4(void)
Definition: bcrypt.c:4395
static const WCHAR ULONG CRYPT_CONTEXT_FUNCTIONS **static void test_BCryptGenRandom(void)
Definition: bcrypt.c:64
static void test_BCryptGenerateSymmetricKey(void)
Definition: bcrypt.c:779
static void test_hashes(void)
Definition: bcrypt.c:400
static void test_PBKDF2(void)
Definition: bcrypt.c:4424
#define GetProcAddress(x, y)
Definition: compat.h:753
#define FreeLibrary(x)
Definition: compat.h:748
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
#define win_skip
Definition: minitest.h:67

◆ test_3des()

static void test_3des ( void  )
static

Definition at line 718 of file bcrypt.c.

719{
720 BCRYPT_KEY_LENGTHS_STRUCT key_lengths;
722 ULONG size, len;
723 UCHAR mode[64];
725
726 alg = NULL;
727 ret = pBCryptOpenAlgorithmProvider(&alg, BCRYPT_3DES_ALGORITHM, MS_PRIMITIVE_PROVIDER, 0);
728 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
729 ok(alg != NULL, "alg not set\n");
730
731 len = size = 0;
732 ret = pBCryptGetProperty(alg, BCRYPT_OBJECT_LENGTH, (UCHAR *)&len, sizeof(len), &size, 0);
733 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
734 ok(len, "expected non-zero len\n");
735 ok(size == sizeof(len), "got %u\n", size);
736
737 len = size = 0;
738 ret = pBCryptGetProperty(alg, BCRYPT_BLOCK_LENGTH, (UCHAR *)&len, sizeof(len), &size, 0);
739 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
740 ok(len == 8, "got %u\n", len);
741 ok(size == sizeof(len), "got %u\n", size);
742
743 size = 0;
744 ret = pBCryptGetProperty(alg, BCRYPT_CHAINING_MODE, mode, 0, &size, 0);
745 ok(ret == STATUS_BUFFER_TOO_SMALL, "got 0x%x\n", ret);
746 ok(size == 64, "got %u\n", size);
747
748 size = 0;
749 ret = pBCryptGetProperty(alg, BCRYPT_CHAINING_MODE, mode, sizeof(mode) - 1, &size, 0);
750 ok(ret == STATUS_BUFFER_TOO_SMALL, "got 0x%x\n", ret);
751 ok(size == 64, "got %u\n", size);
752
753 size = 0;
754 memset(mode, 0, sizeof(mode));
755 ret = pBCryptGetProperty(alg, BCRYPT_CHAINING_MODE, mode, sizeof(mode), &size, 0);
756 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
757 ok(!lstrcmpW((const WCHAR *)mode, BCRYPT_CHAIN_MODE_CBC), "got %s\n", wine_dbgstr_w((const WCHAR *)mode));
758 ok(size == 64, "got %u\n", size);
759
760 size = 0;
761 memset(&key_lengths, 0, sizeof(key_lengths));
762 ret = pBCryptGetProperty(alg, BCRYPT_KEY_LENGTHS, (UCHAR*)&key_lengths, sizeof(key_lengths), &size, 0);
763 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
764 ok(size == sizeof(key_lengths), "got %u\n", size);
765 ok(key_lengths.dwMinLength == 192, "Expected 192, got %u\n", key_lengths.dwMinLength);
766 ok(key_lengths.dwMaxLength == 192, "Expected 192, got %u\n", key_lengths.dwMaxLength);
767 ok(key_lengths.dwIncrement == 0, "Expected 0, got %u\n", key_lengths.dwIncrement);
768
770 ret = pBCryptSetProperty(alg, BCRYPT_CHAINING_MODE, mode, 0, 0);
771 ok(ret == STATUS_NOT_SUPPORTED, "got 0x%x\n", ret);
772
773 test_alg_name(alg, L"3DES");
774
775 ret = pBCryptCloseAlgorithmProvider(alg, 0);
776 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
777}
#define test_alg_name(a, b)
Definition: bcrypt.c:213
#define BCRYPT_KEY_LENGTHS
Definition: bcrypt.h:53
#define BCRYPT_3DES_ALGORITHM
Definition: bcrypt.h:86
#define BCRYPT_CHAIN_MODE_GCM
Definition: bcrypt.h:115
#define BCRYPT_CHAINING_MODE
Definition: bcrypt.h:47
#define BCRYPT_CHAIN_MODE_CBC
Definition: bcrypt.h:111
#define BCRYPT_BLOCK_LENGTH
Definition: bcrypt.h:45
#define MS_PRIMITIVE_PROVIDER
Definition: bcrypt.h:83
#define STATUS_NOT_SUPPORTED
Definition: d3dkmdt.h:48
#define L(x)
Definition: resources.c:13
GLenum mode
Definition: glext.h:6217
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878

Referenced by START_TEST().

◆ test_aes()

static void test_aes ( void  )
static

Definition at line 628 of file bcrypt.c.

629{
630 BCRYPT_KEY_LENGTHS_STRUCT key_lengths;
632 ULONG size, len;
633 UCHAR mode[64];
635
636 alg = NULL;
637 ret = pBCryptOpenAlgorithmProvider(&alg, BCRYPT_AES_ALGORITHM, MS_PRIMITIVE_PROVIDER, 0);
638 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
639 ok(alg != NULL, "alg not set\n");
640
641 len = size = 0;
642 ret = pBCryptGetProperty(alg, BCRYPT_OBJECT_LENGTH, (UCHAR *)&len, sizeof(len), &size, 0);
643 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
644 ok(len, "expected non-zero len\n");
645 ok(size == sizeof(len), "got %u\n", size);
646
647 len = size = 0;
648 ret = pBCryptGetProperty(alg, BCRYPT_BLOCK_LENGTH, (UCHAR *)&len, sizeof(len), &size, 0);
649 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
650 ok(len == 16, "got %u\n", len);
651 ok(size == sizeof(len), "got %u\n", size);
652
653 size = 0;
654 ret = pBCryptGetProperty(alg, BCRYPT_CHAINING_MODE, mode, 0, &size, 0);
655 ok(ret == STATUS_BUFFER_TOO_SMALL, "got 0x%x\n", ret);
656 ok(size == 64, "got %u\n", size);
657
658 size = 0;
659 ret = pBCryptGetProperty(alg, BCRYPT_CHAINING_MODE, mode, sizeof(mode) - 1, &size, 0);
660 ok(ret == STATUS_BUFFER_TOO_SMALL, "got 0x%x\n", ret);
661 ok(size == 64, "got %u\n", size);
662
663 size = 0;
664 memset(mode, 0, sizeof(mode));
665 ret = pBCryptGetProperty(alg, BCRYPT_CHAINING_MODE, mode, sizeof(mode), &size, 0);
666 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
667 ok(!lstrcmpW((const WCHAR *)mode, BCRYPT_CHAIN_MODE_CBC), "got %s\n", wine_dbgstr_w((const WCHAR *)mode));
668 ok(size == 64, "got %u\n", size);
669
670 size = 0;
671 memset(&key_lengths, 0, sizeof(key_lengths));
672 ret = pBCryptGetProperty(alg, BCRYPT_KEY_LENGTHS, (UCHAR*)&key_lengths, sizeof(key_lengths), &size, 0);
673 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
674 ok(size == sizeof(key_lengths), "got %u\n", size);
675 ok(key_lengths.dwMinLength == 128, "Expected 128, got %u\n", key_lengths.dwMinLength);
676 ok(key_lengths.dwMaxLength == 256, "Expected 256, got %u\n", key_lengths.dwMaxLength);
677 ok(key_lengths.dwIncrement == 64, "Expected 64, got %u\n", key_lengths.dwIncrement);
678
679 ret = pBCryptSetProperty(alg, BCRYPT_CHAINING_MODE, (UCHAR *)BCRYPT_CHAIN_MODE_GCM, 0, 0);
680 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
681
682 size = 0;
683 memset(mode, 0, sizeof(mode));
684 ret = pBCryptGetProperty(alg, BCRYPT_CHAINING_MODE, mode, sizeof(mode), &size, 0);
685 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
686 ok(!lstrcmpW((const WCHAR *)mode, BCRYPT_CHAIN_MODE_GCM), "got %s\n", wine_dbgstr_w((const WCHAR *)mode));
687 ok(size == 64, "got %u\n", size);
688
689 ret = pBCryptSetProperty(alg, BCRYPT_CHAINING_MODE, (UCHAR *)BCRYPT_CHAIN_MODE_CFB, 0, 0);
690 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
691
692 size = 0;
693 memset(mode, 0, sizeof(mode));
694 ret = pBCryptGetProperty(alg, BCRYPT_CHAINING_MODE, mode, sizeof(mode), &size, 0);
695 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
696 ok(!lstrcmpW((const WCHAR *)mode, BCRYPT_CHAIN_MODE_CFB), "got %s\n", wine_dbgstr_w((const WCHAR *)mode));
697 ok(size == 64, "got %u\n", size);
698
699 test_alg_name(alg, L"AES");
700
701 ret = pBCryptCloseAlgorithmProvider(alg, 0);
702 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
703
704 if (pBCryptHash)
705 {
707 ok(ret == STATUS_ACCESS_DENIED, "got 0x%x\n", ret);
708
709 size = 0;
710 memset(mode, 0, sizeof(mode));
711 ret = pBCryptGetProperty(BCRYPT_AES_CBC_ALG_HANDLE, BCRYPT_CHAINING_MODE, mode, sizeof(mode), &size, 0);
712 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
713 ok(!lstrcmpW((const WCHAR *)mode, BCRYPT_CHAIN_MODE_CBC), "got %s\n", wine_dbgstr_w((const WCHAR *)mode));
714 ok(size == 64, "got %u\n", size);
715 }
716}
#define BCRYPT_CHAIN_MODE_CFB
Definition: bcrypt.h:113
#define BCRYPT_AES_ALGORITHM
Definition: bcrypt.h:87
#define BCRYPT_AES_CBC_ALG_HANDLE
Definition: bcrypt.h:403
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145

Referenced by START_TEST().

◆ test_aes_vector()

static void test_aes_vector ( void  )
static

Definition at line 3679 of file bcrypt.c.

3680{
3681 static const UCHAR secret[] = {0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10};
3682 static const UCHAR expect[] = {0xb0,0xcb,0xf5,0x80,0xd4,0xe3,0x55,0x23,0x6e,0x19,0x5b,0xdb,0xfe,0xe0,0x6c,0xd3};
3683 static const UCHAR expect2[] = {0x06,0x0c,0x81,0xab,0xd4,0x28,0x80,0x42,0xce,0x30,0x56,0x17,0x15,0x00,0x9e,0xc1};
3684 static const UCHAR expect3[] = {0x3e,0x99,0xbf,0x02,0xf5,0xd3,0xb8,0x81,0x91,0x4d,0x93,0xea,0xd4,0x92,0x93,0x46};
3685 static UCHAR iv[16], input[] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p'};
3686 UCHAR output[16];
3689 UCHAR data[sizeof(BCRYPT_KEY_DATA_BLOB_HEADER) + sizeof(secret)];
3691 ULONG size;
3692 NTSTATUS ret;
3693
3694 ret = pBCryptOpenAlgorithmProvider(&alg, BCRYPT_AES_ALGORITHM, NULL, 0);
3695 ok(!ret, "got 0x%x\n", ret);
3696
3697 size = sizeof(BCRYPT_CHAIN_MODE_CBC);
3698 ret = pBCryptSetProperty(alg, BCRYPT_CHAINING_MODE, (UCHAR *)BCRYPT_CHAIN_MODE_CBC, size, 0);
3699 ok(!ret, "got 0x%x\n", ret);
3700
3703 blob->cbKeyData = sizeof(secret);
3704 memcpy(data + sizeof(*blob), secret, sizeof(secret));
3705 size = sizeof(BCRYPT_KEY_DATA_BLOB_HEADER) + sizeof(secret);
3706 ret = pBCryptImportKey(alg, NULL, BCRYPT_KEY_DATA_BLOB, &key, NULL, 0, data, size, 0);
3707 ok(!ret, "got 0x%x\n", ret);
3708
3709 /* zero initialization vector */
3710 size = 0;
3711 memset(output, 0, sizeof(output));
3712 ret = pBCryptEncrypt(key, input, sizeof(input), NULL, iv, sizeof(iv), output, sizeof(output), &size, 0);
3713 ok(!ret, "got 0x%x\n", ret);
3714 ok(size == 16, "got %u\n", size);
3715 ok(!memcmp(output, expect, sizeof(expect)), "wrong cipher text\n");
3716
3717 /* same initialization vector */
3718 size = 0;
3719 memset(output, 0, sizeof(output));
3720 ret = pBCryptEncrypt(key, input, sizeof(input), NULL, iv, sizeof(iv), output, sizeof(output), &size, 0);
3721 ok(!ret, "got 0x%x\n", ret);
3722 ok(size == 16, "got %u\n", size);
3723 ok(!memcmp(output, expect2, sizeof(expect2)), "wrong cipher text\n");
3724
3725 /* different initialization vector */
3726 iv[0] = 0x1;
3727 size = 0;
3728 memset(output, 0, sizeof(output));
3729 ret = pBCryptEncrypt(key, input, sizeof(input), NULL, iv, sizeof(iv), output, sizeof(output), &size, 0);
3730 ok(!ret, "got 0x%x\n", ret);
3731 ok(size == 16, "got %u\n", size);
3732 ok(!memcmp(output, expect3, sizeof(expect3)), "wrong cipher text\n");
3733
3734 ret = pBCryptDestroyKey(key);
3735 ok(!ret, "got 0x%x\n", ret);
3736
3737 ret = pBCryptCloseAlgorithmProvider(alg, 0);
3738 ok(!ret, "got 0x%x\n", ret);
3739}
#define expect(EXPECTED, GOT)
Definition: SystemMenu.c:483
#define BCRYPT_KEY_DATA_BLOB_MAGIC
Definition: bcrypt.h:367
#define BCRYPT_KEY_DATA_BLOB
Definition: bcrypt.h:63
struct _BCRYPT_KEY_DATA_BLOB_HEADER BCRYPT_KEY_DATA_BLOB_HEADER
#define BCRYPT_KEY_DATA_BLOB_VERSION1
Definition: bcrypt.h:368
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLenum GLenum GLenum input
Definition: glext.h:9031
#define expect2(expected1, expected2, got1, got2)
Definition: listview.c:50
Definition: image.c:134

Referenced by START_TEST().

◆ test_BCryptDecrypt()

static void test_BCryptDecrypt ( void  )
static

Definition at line 1726 of file bcrypt.c.

1727{
1728 static UCHAR nonce[] =
1729 {0x10,0x20,0x30,0x40,0x50,0x60,0x10,0x20,0x30,0x40,0x50,0x60};
1730 static UCHAR auth_data[] =
1731 {0x60,0x50,0x40,0x30,0x20,0x10,0x60,0x50,0x40,0x30,0x20,0x10};
1732 static UCHAR secret[] =
1733 {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f};
1734 static UCHAR iv[] =
1735 {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f};
1736 static UCHAR expected[] =
1737 {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f};
1738 static UCHAR expected2[] =
1739 {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10};
1740 static UCHAR expected3[] =
1741 {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
1742 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10};
1743 static UCHAR expected4[] =
1744 {0x28,0x73,0x3d,0xef,0x84,0x8f,0xb0,0xa6,0x5d,0x1a,0x51,0xb7,0xec,0x8f,0xea,0xe9,
1745 0x10,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f};
1746 static UCHAR expected5[] =
1747 {0x29,0x73,0x3d,0xef,0x84,0x8f,0xb0,0xa6,0x5d,0x1a,0x51,0xb7,0xec,0x8f,0xea,0xe9,
1748 0x10,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f};
1749 static UCHAR ciphertext[32] =
1750 {0xc6,0xa1,0x3b,0x37,0x87,0x8f,0x5b,0x82,0x6f,0x4f,0x81,0x62,0xa1,0xc8,0xd8,0x79,
1751 0x28,0x73,0x3d,0xef,0x84,0x8f,0xb0,0xa6,0x5d,0x1a,0x51,0xb7,0xec,0x8f,0xea,0xe9};
1752 static UCHAR ciphertext2[] =
1753 {0xc6,0xa1,0x3b,0x37,0x87,0x8f,0x5b,0x82,0x6f,0x4f,0x81,0x62,0xa1,0xc8,0xd8,0x79,
1754 0x28,0x73,0x3d,0xef,0x84,0x8f,0xb0,0xa6,0x5d,0x1a,0x51,0xb7,0xec,0x8f,0xea,0xe9};
1755 static UCHAR ciphertext3[] =
1756 {0xc6,0xa1,0x3b,0x37,0x87,0x8f,0x5b,0x82,0x6f,0x4f,0x81,0x62,0xa1,0xc8,0xd8,0x79,
1757 0xb1,0xa2,0x92,0x73,0xbe,0x2c,0x42,0x07,0xa5,0xac,0xe3,0x93,0x39,0x8c,0xb6,0xfb,
1758 0x87,0x5d,0xea,0xa3,0x7e,0x0f,0xde,0xfa,0xd9,0xec,0x6c,0x4e,0x3c,0x76,0x86,0xe4};
1759 static UCHAR ciphertext4[] =
1760 {0xe1,0x82,0xc3,0xc0,0x24,0xfb,0x86,0x85,0xf3,0xf1,0x2b,0x7d,0x09,0xb4,0x73,0x67,
1761 0x86,0x64,0xc3,0xfe,0xa3,0x07,0x61,0xf8,0x16,0xc9,0x78,0x7f,0xe7,0xb1,0xc4,0x94};
1762 static UCHAR ciphertext5[] =
1763 {0x0a,0x94,0x0b,0xb5,0x41,0x6e,0xf0,0x45,0xf1,0xc3,0x94,0x58,0xc6,0x53,0xea,0x5a,
1764 0x84,0x07,0x66,0xb7,0x49,0xc0,0x9b,0x49,0x74,0x28,0x8c,0x10,0xb9,0xc2,0x09,0x70};
1765 static UCHAR ciphertext6[] =
1766 {0x0a,0x94,0x0b,0xb5,0x41,0x6e,0xf0,0x45,0xf1,0xc3,0x94,0x58,0xc6,0x53,0xea,0x5a,
1767 0x95,0x4f,0x64,0xf2,0xe4,0xe8,0x6e,0x9e,0xee,0x82,0xd2,0x02,0x16,0x68,0x48,0x99,
1768 0x95,0x4f,0x64,0xf2,0xe4,0xe8,0x6e,0x9e,0xee,0x82,0xd2,0x02,0x16,0x68,0x48,0x99};
1769 static UCHAR tag[] =
1770 {0x89,0xb3,0x92,0x00,0x39,0x20,0x09,0xb4,0x6a,0xd6,0xaf,0xca,0x4b,0x5b,0xfd,0xd0};
1771 static UCHAR tag2[] =
1772 {0x17,0x9d,0xc0,0x7a,0xf0,0xcf,0xaa,0xd5,0x1c,0x11,0xc4,0x4b,0xd6,0xa3,0x3e,0x77};
1774 BCRYPT_KEY_LENGTHS_STRUCT key_lengths;
1778 UCHAR *buf, plaintext[48], ivbuf[16];
1779 ULONG size, len;
1780 NTSTATUS ret;
1781
1782 ret = pBCryptOpenAlgorithmProvider(&aes, BCRYPT_AES_ALGORITHM, NULL, 0);
1783 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1784
1785 size = 0;
1786 memset(&key_lengths, 0, sizeof(key_lengths));
1787 ret = pBCryptGetProperty(aes, BCRYPT_KEY_LENGTHS, (UCHAR*)&key_lengths, sizeof(key_lengths), &size, 0);
1788 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1789 ok(size == sizeof(key_lengths), "got %u\n", size);
1790 ok(key_lengths.dwMinLength == 128, "Expected 128, got %u\n", key_lengths.dwMinLength);
1791 ok(key_lengths.dwMaxLength == 256, "Expected 256, got %u\n", key_lengths.dwMaxLength);
1792 ok(key_lengths.dwIncrement == 64, "Expected 64, got %u\n", key_lengths.dwIncrement);
1793
1794 /******************
1795 * AES - CBC mode *
1796 ******************/
1797
1798 len = 0xdeadbeef;
1799 size = sizeof(len);
1800 ret = pBCryptGetProperty(aes, BCRYPT_OBJECT_LENGTH, (UCHAR *)&len, sizeof(len), &size, 0);
1801 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1802
1803 key = NULL;
1804 buf = calloc(1, len);
1805 ret = pBCryptGenerateSymmetricKey(aes, &key, buf, len, secret, sizeof(secret), 0);
1806 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1807 ok(key != NULL, "key not set\n");
1808
1809 /* input size is a multiple of block size */
1810 size = 0;
1811 memcpy(ivbuf, iv, sizeof(iv));
1812 ret = pBCryptDecrypt(key, ciphertext, 32, NULL, ivbuf, 16, NULL, 0, &size, 0);
1813 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1814 ok(size == 32, "got %u\n", size);
1815 ok(!memcmp(ivbuf, iv, sizeof(iv)), "wrong iv data.\n");
1816
1817 size = 0;
1818 memcpy(ivbuf, iv, sizeof(iv));
1819 memset(plaintext, 0, sizeof(plaintext));
1820 ret = pBCryptDecrypt(key, ciphertext, 32, NULL, ivbuf, 16, plaintext, 32, &size, 0);
1821 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1822 ok(size == 32, "got %u\n", size);
1823 ok(!memcmp(plaintext, expected, sizeof(expected)), "wrong data\n");
1824 ok(!memcmp(ivbuf, ciphertext + size - sizeof(iv), sizeof(iv)), "wrong iv data.\n");
1825
1826 size = 0;
1827 ++ivbuf[0];
1828 memset(plaintext, 0, sizeof(plaintext));
1829 ret = pBCryptDecrypt(key, ciphertext, 32, NULL, ivbuf, 16, plaintext, 32, &size, 0);
1830 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1831 ok(size == 32, "got %u\n", size);
1832 ok(!memcmp(plaintext, expected5, sizeof(expected)), "wrong data\n");
1833 ok(!memcmp(ivbuf, ciphertext + 32 - 16, sizeof(iv)), "wrong iv data.\n");
1834
1835 size = 0;
1836 memset(plaintext, 0, sizeof(plaintext));
1837 ret = pBCryptDecrypt(key, ciphertext, 32, NULL, NULL, 0, plaintext, 32, &size, 0);
1838 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1839 ok(size == 32, "got %u\n", size);
1840 ok(!memcmp(plaintext, expected4, sizeof(expected4)), "wrong data\n");
1841
1842 /* test with padding smaller than block size */
1843 size = 0;
1844 memcpy(ivbuf, iv, sizeof(iv));
1845 ret = pBCryptDecrypt(key, ciphertext2, 32, NULL, ivbuf, 16, NULL, 0, &size, 0);
1846 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1847 ok(size == 32, "got %u\n", size);
1848 ok(!memcmp(ivbuf, iv, sizeof(iv)), "wrong iv data.\n");
1849
1850 size = 0;
1851 memcpy(ivbuf, iv, sizeof(iv));
1852 memset(plaintext, 0, sizeof(plaintext));
1853 ret = pBCryptDecrypt(key, ciphertext2, 32, NULL, ivbuf, 16, plaintext, 17, &size, BCRYPT_BLOCK_PADDING);
1854 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1855 ok(size == 17, "got %u\n", size);
1856 ok(!memcmp(plaintext, expected2, sizeof(expected2)), "wrong data\n");
1857 ok(!memcmp(ivbuf, ciphertext2 + 32 - sizeof(iv), sizeof(iv)), "wrong iv data.\n");
1858
1859 size = 0;
1860 memset(plaintext, 0, sizeof(plaintext));
1861 ret = pBCryptDecrypt(key, ciphertext2, 32, NULL, ivbuf, 16, plaintext, 17, &size, BCRYPT_BLOCK_PADDING);
1862 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1863 ok(size == 17, "got %u\n", size);
1864 ok(!memcmp(plaintext, expected4, size), "wrong data\n");
1865 ok(!memcmp(ivbuf, ciphertext2 + 32 - 16, sizeof(iv)), "wrong iv data.\n");
1866
1867 /* test with padding of block size */
1868 size = 0;
1869 memcpy(ivbuf, iv, sizeof(iv));
1870 ret = pBCryptDecrypt(key, ciphertext3, 48, NULL, ivbuf, 16, NULL, 0, &size, 0);
1871 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1872 ok(size == 48, "got %u\n", size);
1873 ok(!memcmp(ivbuf, iv, sizeof(iv)), "wrong iv data.\n");
1874
1875 size = 0;
1876 memcpy(ivbuf, iv, sizeof(iv));
1877 memset(plaintext, 0, sizeof(plaintext));
1878 ret = pBCryptDecrypt(key, ciphertext3, 48, NULL, ivbuf, 16, plaintext, 32, &size, BCRYPT_BLOCK_PADDING);
1879 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1880 ok(size == 32, "got %u\n", size);
1881 ok(!memcmp(plaintext, expected3, sizeof(expected3)), "wrong data\n");
1882 ok(!memcmp(ivbuf, ciphertext3 + 48 - 16, sizeof(iv)), "wrong iv data.\n");
1883
1884 /* output size too small */
1885 size = 0;
1886 memcpy(ivbuf, iv, sizeof(iv));
1887 ret = pBCryptDecrypt(key, ciphertext, 32, NULL, ivbuf, 16, plaintext, 31, &size, 0);
1888 ok(ret == STATUS_BUFFER_TOO_SMALL, "got 0x%x\n", ret);
1889 ok(size == 32, "got %u\n", size);
1890
1891 size = 0;
1892 memcpy(ivbuf, iv, sizeof(iv));
1893 ret = pBCryptDecrypt(key, ciphertext2, 32, NULL, ivbuf, 16, plaintext, 15, &size, BCRYPT_BLOCK_PADDING);
1894 ok(ret == STATUS_BUFFER_TOO_SMALL, "got 0x%x\n", ret);
1895 ok(size == 32, "got %u\n", size);
1896
1897 size = 0;
1898 memcpy(ivbuf, iv, sizeof(iv));
1899 ret = pBCryptDecrypt(key, ciphertext2, 32, NULL, ivbuf, 16, plaintext, 16, &size, BCRYPT_BLOCK_PADDING);
1900 ok(ret == STATUS_BUFFER_TOO_SMALL, "got 0x%x\n", ret);
1901 ok(size == 17, "got %u\n", size);
1902
1903 size = 0;
1904 memcpy(ivbuf, iv, sizeof(iv));
1905 ret = pBCryptDecrypt(key, ciphertext3, 48, NULL, ivbuf, 16, plaintext, 31, &size, BCRYPT_BLOCK_PADDING);
1906 ok(ret == STATUS_BUFFER_TOO_SMALL, "got 0x%x\n", ret);
1907 ok(size == 48, "got %u\n", size);
1908
1909 /* input size is not a multiple of block size */
1910 size = 0;
1911 memcpy(ivbuf, iv, sizeof(iv));
1912 ret = pBCryptDecrypt(key, ciphertext, 17, NULL, ivbuf, 16, NULL, 0, &size, 0);
1913 ok(ret == STATUS_INVALID_BUFFER_SIZE, "got 0x%x\n", ret);
1914 ok(size == 17 || broken(size == 0 /* Win < 7 */), "got %u\n", size);
1915
1916 /* input size is not a multiple of block size, block padding set */
1917 size = 0;
1918 memcpy(ivbuf, iv, sizeof(iv));
1919 ret = pBCryptDecrypt(key, ciphertext, 17, NULL, ivbuf, 16, NULL, 0, &size, BCRYPT_BLOCK_PADDING);
1920 ok(ret == STATUS_INVALID_BUFFER_SIZE, "got 0x%x\n", ret);
1921 ok(size == 17 || broken(size == 0 /* Win < 7 */), "got %u\n", size);
1922
1923 ret = pBCryptDestroyKey(key);
1924 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1925 free(buf);
1926
1927 /******************
1928 * AES - GCM mode *
1929 ******************/
1930
1931 ret = pBCryptSetProperty(aes, BCRYPT_CHAINING_MODE, (UCHAR*)BCRYPT_CHAIN_MODE_GCM, sizeof(BCRYPT_CHAIN_MODE_GCM), 0);
1932 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1933
1934 key = NULL;
1935 buf = calloc(1, len);
1936 ret = pBCryptGenerateSymmetricKey(aes, &key, buf, len, secret, sizeof(secret), 0);
1937 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1938 ok(key != NULL, "key not set\n");
1939
1940 ret = pBCryptGetProperty(key, BCRYPT_AUTH_TAG_LENGTH, (UCHAR*)&tag_lengths, sizeof(tag_lengths), &size, 0);
1941 ok(ret == STATUS_NOT_SUPPORTED, "got 0x%x\n", ret);
1942
1943 memset(&auth_info, 0, sizeof(auth_info));
1944 auth_info.cbSize = sizeof(auth_info);
1945 auth_info.dwInfoVersion = 1;
1946 auth_info.pbNonce = nonce;
1947 auth_info.cbNonce = sizeof(nonce);
1948 auth_info.pbTag = tag;
1949 auth_info.cbTag = sizeof(tag);
1950
1951 /* input size is a multiple of block size */
1952 size = 0;
1953 memcpy(ivbuf, iv, sizeof(iv));
1954 memset(plaintext, 0, sizeof(plaintext));
1955 ret = pBCryptDecrypt(key, ciphertext4, 32, &auth_info, ivbuf, 16, plaintext, 32, &size, 0);
1956 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1957 ok(size == 32, "got %u\n", size);
1958 ok(!memcmp(plaintext, expected3, sizeof(expected3)), "wrong data\n");
1959 ok(!memcmp(ivbuf, iv, sizeof(iv)), "wrong iv.\n");
1960
1961 size = 0;
1962 memset(plaintext, 0, sizeof(plaintext));
1963 ret = pBCryptDecrypt(key, ciphertext4, 32, &auth_info, NULL, 0, plaintext, 32, &size, 0);
1964 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1965 ok(size == 32, "got %u\n", size);
1966 ok(!memcmp(plaintext, expected3, sizeof(expected3)), "wrong data\n");
1967
1968 size = 0;
1969 memcpy(ivbuf, iv, sizeof(iv));
1970 ++ivbuf[0];
1971 memset(plaintext, 0, sizeof(plaintext));
1972 ret = pBCryptDecrypt(key, ciphertext4, 32, &auth_info, ivbuf, 16, plaintext, 32, &size, 0);
1973 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1974 ok(size == 32, "got %u\n", size);
1975 ok(!memcmp(plaintext, expected3, sizeof(expected3)), "wrong data\n");
1976 ok(!memcmp(ivbuf + 1, iv + 1, sizeof(iv) - 1), "wrong iv data.\n");
1977 ok(ivbuf[0] == iv[0] + 1, "wrong iv data.\n");
1978
1979 /* test with auth data */
1980 auth_info.pbAuthData = auth_data;
1981 auth_info.cbAuthData = sizeof(auth_data);
1982 auth_info.pbTag = tag2;
1983 auth_info.cbTag = sizeof(tag2);
1984
1985 size = 0;
1986 memcpy(ivbuf, iv, sizeof(iv));
1987 memset(plaintext, 0, sizeof(plaintext));
1988 ret = pBCryptDecrypt(key, ciphertext4, 32, &auth_info, ivbuf, 16, plaintext, 32, &size, 0);
1989 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1990 ok(size == 32, "got %u\n", size);
1991 ok(!memcmp(plaintext, expected3, sizeof(expected3)), "wrong data\n");
1992 ok(!memcmp(ivbuf, iv, sizeof(iv)), "wrong iv.\n");
1993
1994 /* test with wrong tag */
1995 memcpy(ivbuf, iv, sizeof(iv));
1996 auth_info.pbTag = iv; /* wrong tag */
1997 ret = pBCryptDecrypt(key, ciphertext4, 32, &auth_info, ivbuf, 16, plaintext, 32, &size, 0);
1998 ok(ret == STATUS_AUTH_TAG_MISMATCH, "got 0x%x\n", ret);
1999 ok(size == 32, "got %u\n", size);
2000 ok(!memcmp(ivbuf, iv, sizeof(iv)), "wrong iv data.\n");
2001
2002 ret = pBCryptDestroyKey(key);
2003 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2004 free(buf);
2005
2006 /******************
2007 * AES - ECB mode *
2008 ******************/
2009
2010 ret = pBCryptSetProperty(aes, BCRYPT_CHAINING_MODE, (UCHAR*)BCRYPT_CHAIN_MODE_ECB, sizeof(BCRYPT_CHAIN_MODE_ECB), 0);
2011 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2012
2013 len = 0xdeadbeef;
2014 size = sizeof(len);
2015 ret = pBCryptGetProperty(aes, BCRYPT_OBJECT_LENGTH, (UCHAR *)&len, sizeof(len), &size, 0);
2016 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2017
2018 buf = calloc(1, len);
2019 ret = pBCryptGenerateSymmetricKey(aes, &key, buf, len, secret, sizeof(secret), 0);
2020 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2021
2022 /* initialization vector is not allowed */
2023 size = 0;
2024 memcpy(ivbuf, iv, sizeof(iv));
2025 ret = pBCryptDecrypt(key, ciphertext5, 32, NULL, ivbuf, 16, plaintext, 32, &size, 0);
2026 ok(ret == STATUS_INVALID_PARAMETER, "got 0x%x\n", ret);
2027 ok(size == 32, "got %u\n", size);
2028
2029 /* input size is a multiple of block size */
2030 size = 0;
2031 ret = pBCryptDecrypt(key, ciphertext5, 32, NULL, NULL, 16, NULL, 0, &size, 0);
2032 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2033 ok(size == 32, "got %u\n", size);
2034
2035 size = 0;
2036 memset(plaintext, 0, sizeof(plaintext));
2037 ret = pBCryptDecrypt(key, ciphertext5, 32, NULL, NULL, 16, plaintext, 32, &size, 0);
2038 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2039 ok(size == 32, "got %u\n", size);
2040 ok(!memcmp(plaintext, expected, sizeof(expected)), "wrong data\n");
2041
2042 /* test with padding smaller than block size */
2043 size = 0;
2044 ret = pBCryptDecrypt(key, ciphertext5, 32, NULL, NULL, 16, NULL, 0, &size, 0);
2045 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2046 ok(size == 32, "got %u\n", size);
2047
2048 size = 0;
2049 memset(plaintext, 0, sizeof(plaintext));
2050 ret = pBCryptDecrypt(key, ciphertext5, 32, NULL, NULL, 16, plaintext, 17, &size, BCRYPT_BLOCK_PADDING);
2051 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2052 ok(size == 17, "got %u\n", size);
2053 ok(!memcmp(plaintext, expected2, sizeof(expected2)), "wrong data\n");
2054
2055 /* test with padding of block size */
2056 size = 0;
2057 ret = pBCryptDecrypt(key, ciphertext6, 48, NULL, NULL, 16, NULL, 0, &size, 0);
2058 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2059 ok(size == 48, "got %u\n", size);
2060
2061 size = 0;
2062 memset(plaintext, 0, sizeof(plaintext));
2063 ret = pBCryptDecrypt(key, ciphertext6, 48, NULL, NULL, 16, plaintext, 32, &size, BCRYPT_BLOCK_PADDING);
2064 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2065 ok(size == 32, "got %u\n", size);
2066 ok(!memcmp(plaintext, expected3, sizeof(expected3)), "wrong data\n");
2067
2068 /* output size too small */
2069 size = 0;
2070 ret = pBCryptDecrypt(key, ciphertext4, 32, NULL, NULL, 16, plaintext, 31, &size, 0);
2071 ok(ret == STATUS_BUFFER_TOO_SMALL, "got 0x%x\n", ret);
2072 ok(size == 32, "got %u\n", size);
2073
2074 size = 0;
2075 ret = pBCryptDecrypt(key, ciphertext5, 32, NULL, NULL, 16, plaintext, 15, &size, BCRYPT_BLOCK_PADDING);
2076 ok(ret == STATUS_BUFFER_TOO_SMALL, "got 0x%x\n", ret);
2077 ok(size == 32, "got %u\n", size);
2078
2079 size = 0;
2080 ret = pBCryptDecrypt(key, ciphertext5, 32, NULL, NULL, 16, plaintext, 16, &size, BCRYPT_BLOCK_PADDING);
2081 ok(ret == STATUS_BUFFER_TOO_SMALL, "got 0x%x\n", ret);
2082 ok(size == 17, "got %u\n", size);
2083
2084 size = 0;
2085 ret = pBCryptDecrypt(key, ciphertext6, 48, NULL, NULL, 16, plaintext, 31, &size, BCRYPT_BLOCK_PADDING);
2086 ok(ret == STATUS_BUFFER_TOO_SMALL, "got 0x%x\n", ret);
2087 ok(size == 48, "got %u\n", size);
2088
2089 /* input size is not a multiple of block size */
2090 size = 0;
2091 ret = pBCryptDecrypt(key, ciphertext4, 17, NULL, NULL, 16, NULL, 0, &size, 0);
2092 ok(ret == STATUS_INVALID_BUFFER_SIZE, "got 0x%x\n", ret);
2093 ok(size == 17 || broken(size == 0 /* Win < 7 */), "got %u\n", size);
2094
2095 /* input size is not a multiple of block size, block padding set */
2096 size = 0;
2097 ret = pBCryptDecrypt(key, ciphertext4, 17, NULL, NULL, 16, NULL, 0, &size, BCRYPT_BLOCK_PADDING);
2098 ok(ret == STATUS_INVALID_BUFFER_SIZE, "got 0x%x\n", ret);
2099 ok(size == 17 || broken(size == 0 /* Win < 7 */), "got %u\n", size);
2100
2101 ret = pBCryptDestroyKey(key);
2102 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2103
2104 ret = pBCryptDestroyKey(key);
2105 ok(ret == STATUS_INVALID_HANDLE, "got 0x%x\n", ret);
2106 free(buf);
2107
2108 ret = pBCryptDestroyKey(NULL);
2109 ok(ret == STATUS_INVALID_HANDLE, "got 0x%x\n", ret);
2110
2111 ret = pBCryptCloseAlgorithmProvider(aes, 0);
2112 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2113
2114 ret = pBCryptCloseAlgorithmProvider(aes, 0);
2115 ok(ret == STATUS_INVALID_HANDLE, "got 0x%x\n", ret);
2116
2117 ret = pBCryptCloseAlgorithmProvider(NULL, 0);
2118 ok(ret == STATUS_INVALID_HANDLE, "got 0x%x\n", ret);
2119}
#define broken(x)
Definition: atltest.h:178
#define BCRYPT_AUTH_TAG_LENGTH
Definition: bcrypt.h:44
#define BCRYPT_BLOCK_PADDING
Definition: bcrypt.h:444
#define BCRYPT_CHAIN_MODE_ECB
Definition: bcrypt.h:112
#define free
Definition: debug_ros.c:5
BOOL expected
Definition: store.c:2000
#define STATUS_AUTH_TAG_MISMATCH
Definition: ntstatus.h:1399
#define STATUS_INVALID_BUFFER_SIZE
Definition: ntstatus.h:772
#define calloc
Definition: rosglue.h:14

Referenced by START_TEST().

◆ test_BcryptDeriveKeyCapi()

static void test_BcryptDeriveKeyCapi ( void  )
static

Definition at line 3741 of file bcrypt.c.

3742{
3743 static const UCHAR expect[] =
3744 {0xda,0x39,0xa3,0xee,0x5e,0x6b,0x4b,0x0d,0x32,0x55,0xbf,0xef,0x95,0x60,0x18,0x90,0xaf,0xd8,0x07,0x09};
3745 static const UCHAR expect2[] =
3746 {0x9b,0x03,0x17,0x41,0xf4,0x75,0x11,0xac,0xff,0x22,0xee,0x40,0xbb,0xe8,0xf9,0x74,0x17,0x26,0xb6,0xf2,
3747 0xf8,0xc7,0x88,0x02,0x9a,0xdc,0x0d,0xd7,0x83,0x58,0xea,0x65,0x2e,0x8b,0x85,0xc6,0xdb,0xb7,0xed,0x1c};
3750 UCHAR key[40];
3751 NTSTATUS ret;
3752
3753 ret = pBCryptOpenAlgorithmProvider(&alg, BCRYPT_SHA1_ALGORITHM, NULL, 0);
3754 ok(!ret, "got 0x%x\n", ret);
3755
3756 ret = pBCryptCreateHash(alg, &hash, NULL, 0, NULL, 0, 0);
3757 ok(!ret, "got 0x%x\n", ret);
3758
3759 ret = pBCryptDeriveKeyCapi(NULL, NULL, NULL, 0, 0);
3760 ok(ret == STATUS_INVALID_PARAMETER || ret == STATUS_INVALID_HANDLE /* win7 */, "got 0x%x\n", ret);
3761
3762 ret = pBCryptDeriveKeyCapi(hash, NULL, NULL, 0, 0);
3763 ok(ret == STATUS_INVALID_PARAMETER || !ret /* win7 */, "got 0x%x\n", ret);
3764
3765 ret = pBCryptDestroyHash(hash);
3766 ok(!ret, "got 0x%x\n", ret);
3767
3768 ret = pBCryptCreateHash(alg, &hash, NULL, 0, NULL, 0, 0);
3769 ok(!ret, "got 0x%x\n", ret);
3770
3771 ret = pBCryptDeriveKeyCapi(hash, NULL, key, 0, 0);
3772 ok(ret == STATUS_INVALID_PARAMETER || !ret /* win7 */, "got 0x%x\n", ret);
3773
3774 ret = pBCryptDestroyHash(hash);
3775 ok(!ret, "got 0x%x\n", ret);
3776
3777 ret = pBCryptCreateHash(alg, &hash, NULL, 0, NULL, 0, 0);
3778 ok(!ret, "got 0x%x\n", ret);
3779
3780 memset(key, 0, sizeof(key));
3781 ret = pBCryptDeriveKeyCapi(hash, NULL, key, 41, 0);
3782 ok(ret == STATUS_INVALID_PARAMETER || !ret /* win7 */, "got 0x%x\n", ret);
3783 if (!ret)
3784 ok(!memcmp(key, expect, sizeof(expect) - 1), "wrong key data\n");
3785
3786 ret = pBCryptDestroyHash(hash);
3787 ok(!ret, "got 0x%x\n", ret);
3788
3789 ret = pBCryptCreateHash(alg, &hash, NULL, 0, NULL, 0, 0);
3790 ok(!ret, "got 0x%x\n", ret);
3791
3792 memset(key, 0, sizeof(key));
3793 ret = pBCryptDeriveKeyCapi(hash, NULL, key, 20, 0);
3794 ok(!ret, "got 0x%x\n", ret);
3795 ok(!memcmp(key, expect, sizeof(expect) - 1), "wrong key data\n");
3796
3797 ret = pBCryptDeriveKeyCapi(hash, NULL, key, 20, 0);
3798 todo_wine ok(ret == STATUS_INVALID_HANDLE, "got 0x%x\n", ret);
3799
3800 ret = pBCryptHashData(hash, NULL, 0, 0);
3801 todo_wine ok(ret == STATUS_INVALID_HANDLE, "got 0x%x\n", ret);
3802
3803 ret = pBCryptDestroyHash(hash);
3804 ok(!ret, "got 0x%x\n", ret);
3805
3806 ret = pBCryptCreateHash(alg, &hash, NULL, 0, NULL, 0, 0);
3807 ok(!ret, "got 0x%x\n", ret);
3808
3809 ret = pBCryptHashData(hash, (UCHAR *)"test", 4, 0);
3810 ok(!ret, "got 0x%x\n", ret);
3811
3812 /* padding */
3813 memset(key, 0, sizeof(key));
3814 ret = pBCryptDeriveKeyCapi(hash, NULL, key, 40, 0);
3815 ok(!ret, "got 0x%x\n", ret);
3816 ok(!memcmp(key, expect2, sizeof(expect2) - 1), "wrong key data\n");
3817
3818 ret = pBCryptCloseAlgorithmProvider(alg, 0);
3819 ok(!ret, "got 0x%x\n", ret);
3820}
#define BCRYPT_SHA1_ALGORITHM
Definition: bcrypt.h:104
#define todo_wine
Definition: minitest.h:80

Referenced by START_TEST().

◆ test_BcryptDeriveKeyPBKDF2()

static void test_BcryptDeriveKeyPBKDF2 ( void  )
static

Definition at line 555 of file bcrypt.c.

556{
558 UCHAR buf[25];
559 char str[51];
561 ULONG i;
562
563 alg = NULL;
564 ret = pBCryptOpenAlgorithmProvider(&alg, BCRYPT_SHA1_ALGORITHM, MS_PRIMITIVE_PROVIDER,
566 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
567 ok(alg != NULL, "alg not set\n");
568
569 test_hash_length(alg, 20);
570 test_alg_name(alg, L"SHA1");
571
572 ret = pBCryptDeriveKeyPBKDF2(alg, rfc6070[0].pwd, rfc6070[0].pwd_len, rfc6070[0].salt, rfc6070[0].salt_len,
573 0, buf, rfc6070[0].dk_len, 0);
574 ok(ret == STATUS_INVALID_PARAMETER, "got 0x%x\n", ret);
575
576 for (i = 0; i < ARRAY_SIZE(rfc6070); i++)
577 {
578 memset(buf, 0, sizeof(buf));
579 ret = pBCryptDeriveKeyPBKDF2(alg, rfc6070[i].pwd, rfc6070[i].pwd_len, rfc6070[i].salt, rfc6070[i].salt_len,
581 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
583 ok(!memcmp(str, rfc6070[i].dk, rfc6070[i].dk_len), "got %s\n", str);
584 }
585
586 ret = pBCryptCloseAlgorithmProvider(alg, 0);
587 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
588
589 if (pBCryptHash)
590 {
591 ret = pBCryptDeriveKeyPBKDF2(BCRYPT_HMAC_SHA1_ALG_HANDLE, rfc6070[0].pwd, rfc6070[0].pwd_len, rfc6070[0].salt,
592 rfc6070[0].salt_len, 1, buf, rfc6070[0].dk_len, 0);
593 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
594 }
595}
#define ARRAY_SIZE(A)
Definition: main.h:20
ULONG pwd_len
Definition: bcrypt.c:537
ULONGLONG iterations
Definition: bcrypt.c:539
const UCHAR * dk
Definition: bcrypt.c:543
UCHAR * pwd
Definition: bcrypt.c:541
static const struct @1814 rfc6070[]
#define test_hash_length(a, b)
Definition: bcrypt.c:201
ULONG dk_len
Definition: bcrypt.c:540
static void format_hash(const UCHAR *bytes, ULONG size, char *buf)
Definition: bcrypt.c:154
ULONG salt_len
Definition: bcrypt.c:538
static UCHAR salt[]
Definition: bcrypt.c:521
#define BCRYPT_HMAC_SHA1_ALG_HANDLE
Definition: bcrypt.h:387
#define BCRYPT_ALG_HANDLE_HMAC_FLAG
Definition: bcrypt.h:441
const WCHAR * str

Referenced by START_TEST().

◆ test_BCryptEncrypt()

static void test_BCryptEncrypt ( void  )
static

Definition at line 1060 of file bcrypt.c.

1061{
1062 static UCHAR nonce[] =
1063 {0x10,0x20,0x30,0x40,0x50,0x60,0x10,0x20,0x30,0x40,0x50,0x60};
1064 static UCHAR auth_data[] =
1065 {0x60,0x50,0x40,0x30,0x20,0x10,0x60,0x50,0x40,0x30,0x20,0x10};
1066 static UCHAR secret[] =
1067 {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f};
1068 static UCHAR secret256[] =
1069 {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
1070 0x0f,0x0e,0x0d,0x0c,0x0b,0x0a,0x09,0x08,0x07,0x06,0x05,0x04,0x03,0x02,0x01,0x00};
1071 static UCHAR iv[] =
1072 {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f};
1073 static UCHAR data[] =
1074 {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10};
1075 static UCHAR data2[] =
1076 {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
1077 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10};
1078 static UCHAR expected[] =
1079 {0xc6,0xa1,0x3b,0x37,0x87,0x8f,0x5b,0x82,0x6f,0x4f,0x81,0x62,0xa1,0xc8,0xd8,0x79};
1080 static UCHAR expected2[] =
1081 {0xc6,0xa1,0x3b,0x37,0x87,0x8f,0x5b,0x82,0x6f,0x4f,0x81,0x62,0xa1,0xc8,0xd8,0x79,
1082 0x28,0x73,0x3d,0xef,0x84,0x8f,0xb0,0xa6,0x5d,0x1a,0x51,0xb7,0xec,0x8f,0xea,0xe9};
1083 static UCHAR expected3[] =
1084 {0xc6,0xa1,0x3b,0x37,0x87,0x8f,0x5b,0x82,0x6f,0x4f,0x81,0x62,0xa1,0xc8,0xd8,0x79,
1085 0xb1,0xa2,0x92,0x73,0xbe,0x2c,0x42,0x07,0xa5,0xac,0xe3,0x93,0x39,0x8c,0xb6,0xfb,
1086 0x87,0x5d,0xea,0xa3,0x7e,0x0f,0xde,0xfa,0xd9,0xec,0x6c,0x4e,0x3c,0x76,0x86,0xe4};
1087 static UCHAR expected4[] =
1088 {0xe1,0x82,0xc3,0xc0,0x24,0xfb,0x86,0x85,0xf3,0xf1,0x2b,0x7d,0x09,0xb4,0x73,0x67,
1089 0x86,0x64,0xc3,0xfe,0xa3,0x07,0x61,0xf8,0x16,0xc9,0x78,0x7f,0xe7,0xb1,0xc4,0x94};
1090 static UCHAR expected5[] =
1091 {0x0a,0x94,0x0b,0xb5,0x41,0x6e,0xf0,0x45,0xf1,0xc3,0x94,0x58,0xc6,0x53,0xea,0x5a};
1092 static UCHAR expected6[] =
1093 {0x0a,0x94,0x0b,0xb5,0x41,0x6e,0xf0,0x45,0xf1,0xc3,0x94,0x58,0xc6,0x53,0xea,0x5a,
1094 0x84,0x07,0x66,0xb7,0x49,0xc0,0x9b,0x49,0x74,0x28,0x8c,0x10,0xb9,0xc2,0x09,0x70};
1095 static UCHAR expected7[] =
1096 {0x0a,0x94,0x0b,0xb5,0x41,0x6e,0xf0,0x45,0xf1,0xc3,0x94,0x58,0xc6,0x53,0xea,0x5a,
1097 0x95,0x4f,0x64,0xf2,0xe4,0xe8,0x6e,0x9e,0xee,0x82,0xd2,0x02,0x16,0x68,0x48,0x99,
1098 0x95,0x4f,0x64,0xf2,0xe4,0xe8,0x6e,0x9e,0xee,0x82,0xd2,0x02,0x16,0x68,0x48,0x99};
1099 static UCHAR expected8[] =
1100 {0xb5,0x8a,0x10,0x64,0xd8,0xac,0xa9,0x9b,0xd9,0xb0,0x40,0x5b,0x85,0x45,0xf5,0xbb};
1101 static UCHAR expected9[] =
1102 {0x0a,0x94,0x0b,0xb5,0x41,0x6e,0xf0,0x45,0xf1,0xc3,0x94,0x58,0xc6,0x53,0xea,0x5a};
1103 static UCHAR expected10[] =
1104 {0x66,0xb8,0xbd,0xe5,0x90,0x6c,0xec,0xdf,0xfa,0x8a,0xb2,0xfd,0x92,0x84,0xeb,0xf0,
1105 0x95,0xc4,0xdf,0xa7,0x7a,0x62,0xe4,0xab,0xd4,0x0e,0x94,0x4e,0xd7,0x6e,0xa1,0x47,
1106 0x29,0x4b,0x37,0xfe,0x28,0x6d,0x5f,0x69,0x46,0x30,0x73,0xc0,0xaa,0x42,0xe4,0x46};
1107 static UCHAR expected11[] =
1108 {0x0a,0x22,0xf7,0x96,0xe1,0xb9,0x3e,0x90,0x32,0xcf,0xf8,0x04,0x83,0x8a,0xdf,0xc3};
1109 static UCHAR expected12[] =
1110 {0xb5,0x9d,0xe7,0x8e,0x0f,0x80,0x16,0xc3,0xf6,0x80,0xad,0xf8,0xac,0xef,0xf9,0x9f};
1111 static UCHAR expected13[] =
1112 {0xc6,0x41,0x37,0xd8,0x6f,0x65,0x64,0x1d,0x2b,0xa0,0xad,0xee,0x67,0xba,0x9b,0x5f};
1113 static UCHAR expected14[] =
1114 {0x0a,0x22,0xf7,0x96,0xe1,0xb9,0x3e,0x90,0x32,0xcf,0xf8,0x04,0x83,0x8a,0xdf,0xc3,
1115 0xa5,0xfa,0x54,0xd7,0x62,0x9d,0x8b,0x11,0x3d,0xd8,0xe2,0x95,0xc2,0x23,0x3f,0x29};
1116 static UCHAR expected15[] =
1117 {0x0a,0x22,0xf7,0x96,0xe1,0xb9,0x3e,0x90,0x32,0xcf,0xf8,0x04,0x83,0x8a,0xdf,0xc3,
1118 0xa5,0xe5,0xcd,0x29,0x48,0x37,0x3f,0x92,0x6f,0x09,0x84,0x5a,0xb8,0x88,0xda,0xfd,
1119 0x65,0x00,0x20,0x9a,0xc6,0xdb,0xfa,0x82,0xdb,0xbc,0xf4,0x70,0x7d,0x88,0x86,0xb5};
1120 static UCHAR expected16[] =
1121 {0x64,0xff,0xc6,0x97,0x14,0x5e,0x21,0xfa,0xe8,0x6e,0xba,0xc1,0x0c,0xb1,0x72,0x64,
1122 0x5d,0xf0,0x22,0x72,0xef,0x39,0xe3,0x2f,0x80,0x3e,0x53,0x00,0xc1,0xcf,0x3f,0xbb,
1123 0xea,0x30,0x01,0x78,0x3b,0xba,0x4d,0xca,0xa0,0x2e,0x83,0x5e,0x0e,0xe2,0x65,0xcb};
1124 static UCHAR expected_tag[] =
1125 {0x89,0xb3,0x92,0x00,0x39,0x20,0x09,0xb4,0x6a,0xd6,0xaf,0xca,0x4b,0x5b,0xfd,0xd0};
1126 static UCHAR expected_tag2[] =
1127 {0x9a,0x92,0x32,0x2c,0x61,0x2a,0xae,0xef,0x66,0x2a,0xfb,0x55,0xe9,0x48,0xdf,0xbd};
1128 static UCHAR expected_tag3[] =
1129 {0x17,0x9d,0xc0,0x7a,0xf0,0xcf,0xaa,0xd5,0x1c,0x11,0xc4,0x4b,0xd6,0xa3,0x3e,0x77};
1130 static UCHAR expected_tag4[] =
1131 {0x4c,0x42,0x83,0x9e,0x8d,0x40,0xf1,0x19,0xd6,0x2b,0x1c,0x66,0x03,0x2b,0x39,0x63};
1132
1134 UCHAR *buf, ciphertext[48], ivbuf[16], tag[16];
1136 ULONG size, len, i, test;
1139 HANDLE hthread;
1140 NTSTATUS ret;
1141
1142 ret = pBCryptOpenAlgorithmProvider(&aes, BCRYPT_AES_ALGORITHM, NULL, 0);
1143 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1144
1145 /******************
1146 * AES - CBC mode *
1147 ******************/
1148
1149 len = 0xdeadbeef;
1150 size = sizeof(len);
1151 ret = pBCryptGetProperty(aes, BCRYPT_OBJECT_LENGTH, (UCHAR *)&len, sizeof(len), &size, 0);
1152 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1153
1154 key = NULL;
1155 buf = calloc(1, len);
1156 ret = pBCryptGenerateSymmetricKey(aes, &key, buf, len, secret, sizeof(secret), 0);
1157 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1158 ok(key != NULL, "key not set\n");
1159
1160 /* input size is a multiple of block size */
1161 size = 0;
1162 memcpy(ivbuf, iv, sizeof(iv));
1163 ret = pBCryptEncrypt(key, data, 16, NULL, ivbuf, 16, NULL, 0, &size, 0);
1164 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1165 ok(size == 16, "got %u\n", size);
1166 ok(!memcmp(ivbuf, iv, sizeof(iv)), "wrong iv data.\n");
1167
1168 size = 0;
1169 memcpy(ivbuf, iv, sizeof(iv));
1170 memset(ciphertext, 0, sizeof(ciphertext));
1171 ret = pBCryptEncrypt(key, data, 16, NULL, ivbuf, 16, ciphertext, 16, &size, 0);
1172 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1173 ok(size == 16, "got %u\n", size);
1174 ok(!memcmp(ciphertext, expected, sizeof(expected)), "wrong data\n");
1175 for (i = 0; i < 16; i++)
1176 ok(ciphertext[i] == expected[i], "%u: %02x != %02x\n", i, ciphertext[i], expected[i]);
1177 ok(!memcmp(ivbuf, ciphertext, sizeof(iv)), "wrong iv data.\n");
1178
1179 /* NULL initialization vector */
1180 size = 0;
1181 memset(ciphertext, 0, sizeof(ciphertext));
1182 ret = pBCryptEncrypt(key, data, 16, NULL, NULL, 0, ciphertext, 16, &size, 0);
1183 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1184 ok(size == 16, "got %u\n", size);
1185 ok(!memcmp(ciphertext, expected8, sizeof(expected8)), "wrong data\n");
1186
1187 /* all zero initialization vector */
1188 size = 0;
1189 memset(ciphertext, 0, sizeof(ciphertext));
1190 memset(ivbuf, 0, sizeof(ivbuf));
1191 ret = pBCryptEncrypt(key, data, 16, NULL, ivbuf, 16, ciphertext, 16, &size, 0);
1192 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1193 ok(size == 16, "got %u\n", size);
1194 ok(!memcmp(ciphertext, expected9, sizeof(expected9)), "wrong data\n");
1195 for (i = 0; i < 16; i++)
1196 ok(ciphertext[i] == expected9[i], "%u: %02x != %02x\n", i, ciphertext[i], expected9[i]);
1197 ok(!memcmp(ivbuf, ciphertext, sizeof(iv)), "wrong iv data.\n");
1198
1199 /* input size is not a multiple of block size */
1200 size = 0;
1201 memcpy(ivbuf, iv, sizeof(iv));
1202 ret = pBCryptEncrypt(key, data, 17, NULL, ivbuf, 16, NULL, 0, &size, 0);
1203 ok(ret == STATUS_INVALID_BUFFER_SIZE, "got 0x%x\n", ret);
1204 ok(size == 17, "got %u\n", size);
1205
1206 /* input size is not a multiple of block size, block padding set */
1207 size = 0;
1208 memcpy(ivbuf, iv, sizeof(iv));
1209 ret = pBCryptEncrypt(key, data, 17, NULL, ivbuf, 16, NULL, 0, &size, BCRYPT_BLOCK_PADDING);
1210 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1211 ok(size == 32, "got %u\n", size);
1212 ok(!memcmp(ivbuf, iv, sizeof(iv)), "wrong iv data.\n");
1213
1214 size = 0;
1215 memcpy(ivbuf, iv, sizeof(iv));
1216 memset(ciphertext, 0, sizeof(ciphertext));
1217 ret = pBCryptEncrypt(key, data, 17, NULL, ivbuf, 16, ciphertext, 32, &size, BCRYPT_BLOCK_PADDING);
1218 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1219 ok(size == 32, "got %u\n", size);
1220 ok(!memcmp(ciphertext, expected2, sizeof(expected2)), "wrong data\n");
1221 for (i = 0; i < 32; i++)
1222 ok(ciphertext[i] == expected2[i], "%u: %02x != %02x\n", i, ciphertext[i], expected2[i]);
1223 ok(!memcmp(ivbuf, ciphertext + 32 - 16, sizeof(iv)), "wrong iv data.\n");
1224
1225 /* input size is a multiple of block size, block padding set */
1226 size = 0;
1227 memcpy(ivbuf, iv, sizeof(iv));
1228 ret = pBCryptEncrypt(key, data2, 32, NULL, ivbuf, 16, NULL, 0, &size, BCRYPT_BLOCK_PADDING);
1229 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1230 ok(size == 48, "got %u\n", size);
1231 ok(!memcmp(ivbuf, iv, sizeof(iv)), "wrong iv data.\n");
1232
1233 size = 0;
1234 memcpy(ivbuf, iv, sizeof(iv));
1235 memset(ciphertext, 0, sizeof(ciphertext));
1236 ret = pBCryptEncrypt(key, data2, 32, NULL, ivbuf, 16, ciphertext, 48, &size, BCRYPT_BLOCK_PADDING);
1237 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1238 ok(size == 48, "got %u\n", size);
1239 ok(!memcmp(ciphertext, expected3, sizeof(expected3)), "wrong data\n");
1240 for (i = 0; i < 48; i++)
1241 ok(ciphertext[i] == expected3[i], "%u: %02x != %02x\n", i, ciphertext[i], expected3[i]);
1242 ok(!memcmp(ivbuf, ciphertext + 48 - 16, sizeof(iv)), "wrong iv data.\n");
1243
1244 /* output size too small */
1245 size = 0;
1246 memcpy(ivbuf, iv, sizeof(iv));
1247 memset(ciphertext, 0, sizeof(ciphertext));
1248 ret = pBCryptEncrypt(key, data, 17, NULL, ivbuf, 16, ciphertext, 31, &size, BCRYPT_BLOCK_PADDING);
1249 ok(ret == STATUS_BUFFER_TOO_SMALL, "got 0x%x\n", ret);
1250 ok(size == 32, "got %u\n", size);
1251
1252 size = 0;
1253 memcpy(ivbuf, iv, sizeof(iv));
1254 memset(ciphertext, 0, sizeof(ciphertext));
1255 ret = pBCryptEncrypt(key, data2, 32, NULL, ivbuf, 16, ciphertext, 32, &size, BCRYPT_BLOCK_PADDING);
1256 ok(ret == STATUS_BUFFER_TOO_SMALL, "got 0x%x\n", ret);
1257 ok(size == 48, "got %u\n", size);
1258
1259 ret = pBCryptDestroyKey(key);
1260 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1261 free(buf);
1262
1263 /* 256 bit key */
1264 buf = calloc(1, len);
1265
1266 ret = pBCryptGenerateSymmetricKey(aes, &key, buf, len, secret256, sizeof(secret256), 0);
1267 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1268 ret = pBCryptDestroyKey(key);
1269 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1270
1271 /* Key generations succeeds if the key size exceeds maximum and uses maximum key length
1272 * from secret. */
1273 ret = pBCryptGenerateSymmetricKey(aes, &key, buf, len, secret256, sizeof(secret256) + 1, 0);
1274 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1275
1276 size = 0;
1277 memcpy(ivbuf, iv, sizeof(iv));
1278 ret = pBCryptEncrypt(key, data2, 32, NULL, ivbuf, 16, NULL, 0, &size, BCRYPT_BLOCK_PADDING);
1279 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1280 ok(size == 48, "got %u\n", size);
1281 ok(!memcmp(ivbuf, iv, sizeof(iv)), "wrong iv data.\n");
1282
1283 size = 0;
1284 memcpy(ivbuf, iv, sizeof(iv));
1285 memset(ciphertext, 0, sizeof(ciphertext));
1286 ret = pBCryptEncrypt(key, data2, 32, NULL, ivbuf, 16, ciphertext, 48, &size, BCRYPT_BLOCK_PADDING);
1287 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1288 ok(size == 48, "got %u\n", size);
1289 ok(!memcmp(ciphertext, expected10, sizeof(expected10)), "wrong data\n");
1290 for (i = 0; i < 48; i++)
1291 ok(ciphertext[i] == expected10[i], "%u: %02x != %02x\n", i, ciphertext[i], expected10[i]);
1292 ok(!memcmp(ivbuf, ciphertext + 48 - 16, sizeof(iv)), "wrong iv data.\n");
1293
1294 ret = pBCryptDestroyKey(key);
1295 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1296 free(buf);
1297
1298 /******************
1299 * AES - GCM mode *
1300 ******************/
1301
1302 size = 0;
1303 ret = pBCryptGetProperty(aes, BCRYPT_AUTH_TAG_LENGTH, NULL, 0, &size, 0);
1304 ok(ret == STATUS_NOT_SUPPORTED, "got 0x%x\n", ret);
1305
1306 ret = pBCryptSetProperty(aes, BCRYPT_CHAINING_MODE, (UCHAR*)BCRYPT_CHAIN_MODE_GCM, sizeof(BCRYPT_CHAIN_MODE_GCM), 0);
1307 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1308
1309 size = 0;
1310 ret = pBCryptGetProperty(aes, BCRYPT_AUTH_TAG_LENGTH, NULL, 0, &size, 0);
1311 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1312 ok(size == sizeof(tag_length), "got %u\n", size);
1313
1314 size = 0;
1315 memset(&tag_length, 0, sizeof(tag_length));
1316 ret = pBCryptGetProperty(aes, BCRYPT_AUTH_TAG_LENGTH, (UCHAR*)&tag_length, sizeof(tag_length), &size, 0);
1317 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1318 ok(size == sizeof(tag_length), "got %u\n", size);
1319 ok(tag_length.dwMinLength == 12, "Expected 12, got %u\n", tag_length.dwMinLength);
1320 ok(tag_length.dwMaxLength == 16, "Expected 16, got %u\n", tag_length.dwMaxLength);
1321 ok(tag_length.dwIncrement == 1, "Expected 1, got %u\n", tag_length.dwIncrement);
1322
1323 len = 0xdeadbeef;
1324 size = sizeof(len);
1325 ret = pBCryptGetProperty(aes, BCRYPT_OBJECT_LENGTH, (UCHAR *)&len, sizeof(len), &size, 0);
1326 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1327
1328 key = NULL;
1329 buf = calloc(1, len);
1330 ret = pBCryptGenerateSymmetricKey(aes, &key, buf, len, secret, sizeof(secret), 0);
1331 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1332 ok(key != NULL, "key not set\n");
1333
1334 ret = pBCryptGetProperty(key, BCRYPT_AUTH_TAG_LENGTH, (UCHAR*)&tag_length, sizeof(tag_length), &size, 0);
1335 ok(ret == STATUS_NOT_SUPPORTED, "got 0x%x\n", ret);
1336
1337 memset(&auth_info, 0, sizeof(auth_info));
1338 auth_info.cbSize = sizeof(auth_info);
1339 auth_info.dwInfoVersion = 1;
1340 auth_info.pbNonce = nonce;
1341 auth_info.cbNonce = sizeof(nonce);
1342 auth_info.pbTag = tag;
1343 auth_info.cbTag = sizeof(tag);
1344
1345 /* input size is a multiple of block size */
1346 size = 0;
1347 memcpy(ivbuf, iv, sizeof(iv));
1348 memset(ciphertext, 0xff, sizeof(ciphertext));
1349 memset(tag, 0xff, sizeof(tag));
1350 ret = pBCryptEncrypt(key, data2, 32, &auth_info, ivbuf, 16, ciphertext, 32, &size, 0);
1351 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1352 ok(size == 32, "got %u\n", size);
1353 ok(!memcmp(ciphertext, expected4, sizeof(expected4)), "wrong data\n");
1354 ok(!memcmp(tag, expected_tag, sizeof(expected_tag)), "wrong tag\n");
1355 for (i = 0; i < 32; i++)
1356 ok(ciphertext[i] == expected4[i], "%u: %02x != %02x\n", i, ciphertext[i], expected4[i]);
1357 for (i = 0; i < 16; i++)
1358 ok(tag[i] == expected_tag[i], "%u: %02x != %02x\n", i, tag[i], expected_tag[i]);
1359 ok(!memcmp(ivbuf, iv, sizeof(iv)), "wrong iv data.\n");
1360
1361 /* NULL initialization vector */
1362 size = 0;
1363 memset(ciphertext, 0xff, sizeof(ciphertext));
1364 memset(tag, 0xff, sizeof(tag));
1365 ret = pBCryptEncrypt(key, data2, 32, &auth_info, NULL, 0, ciphertext, 32, &size, 0);
1366 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1367 ok(size == 32, "got %u\n", size);
1368 ok(!memcmp(ciphertext, expected4, sizeof(expected4)), "wrong data\n");
1369 ok(!memcmp(tag, expected_tag, sizeof(expected_tag)), "wrong tag\n");
1370 for (i = 0; i < 32; i++)
1371 ok(ciphertext[i] == expected4[i], "%u: %02x != %02x\n", i, ciphertext[i], expected4[i]);
1372 for (i = 0; i < 16; i++)
1373 ok(tag[i] == expected_tag[i], "%u: %02x != %02x\n", i, tag[i], expected_tag[i]);
1374
1375 /* all zero initialization vector */
1376 size = 0;
1377 memset(ciphertext, 0xff, sizeof(ciphertext));
1378 memset(tag, 0xff, sizeof(tag));
1379 memset(ivbuf, 0, sizeof(ivbuf));
1380 ret = pBCryptEncrypt(key, data2, 32, &auth_info, ivbuf, 16, ciphertext, 32, &size, 0);
1381 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1382 ok(size == 32, "got %u\n", size);
1383 ok(!memcmp(ciphertext, expected4, sizeof(expected4)), "wrong data\n");
1384 ok(!memcmp(tag, expected_tag, sizeof(expected_tag)), "wrong tag\n");
1385 for (i = 0; i < 32; i++)
1386 ok(ciphertext[i] == expected4[i], "%u: %02x != %02x\n", i, ciphertext[i], expected4[i]);
1387 for (i = 0; i < 16; i++)
1388 ok(tag[i] == expected_tag[i], "%u: %02x != %02x\n", i, tag[i], expected_tag[i]);
1389 memset(ciphertext, 0, sizeof(iv));
1390 ok(!memcmp(ivbuf, ciphertext, sizeof(iv)), "wrong iv data.\n");
1391
1392 /* input size is not multiple of block size */
1393 size = 0;
1394 memcpy(ivbuf, iv, sizeof(iv));
1395 memset(ciphertext, 0xff, sizeof(ciphertext));
1396 memset(tag, 0xff, sizeof(tag));
1397 ret = pBCryptEncrypt(key, data2, 24, &auth_info, ivbuf, 16, ciphertext, 24, &size, 0);
1398 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1399 ok(size == 24, "got %u\n", size);
1400 ok(!memcmp(ciphertext, expected4, 24), "wrong data\n");
1401 ok(!memcmp(tag, expected_tag2, sizeof(expected_tag2)), "wrong tag\n");
1402 for (i = 0; i < 24; i++)
1403 ok(ciphertext[i] == expected4[i], "%u: %02x != %02x\n", i, ciphertext[i], expected4[i]);
1404 for (i = 0; i < 16; i++)
1405 ok(tag[i] == expected_tag2[i], "%u: %02x != %02x\n", i, tag[i], expected_tag2[i]);
1406 ok(!memcmp(ivbuf, iv, sizeof(iv)), "wrong iv data.\n");
1407
1408 /* test with auth data */
1409 auth_info.pbAuthData = auth_data;
1410 auth_info.cbAuthData = sizeof(auth_data);
1411
1412 size = 0;
1413 memcpy(ivbuf, iv, sizeof(iv));
1414 memset(ciphertext, 0xff, sizeof(ciphertext));
1415 memset(tag, 0xff, sizeof(tag));
1416 ret = pBCryptEncrypt(key, data2, 32, &auth_info, ivbuf, 16, ciphertext, 32, &size, 0);
1417 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1418 ok(size == 32, "got %u\n", size);
1419 ok(!memcmp(ciphertext, expected4, sizeof(expected4)), "wrong data\n");
1420 ok(!memcmp(tag, expected_tag3, sizeof(expected_tag3)), "wrong tag\n");
1421 for (i = 0; i < 32; i++)
1422 ok(ciphertext[i] == expected4[i], "%u: %02x != %02x\n", i, ciphertext[i], expected4[i]);
1423 for (i = 0; i < 16; i++)
1424 ok(tag[i] == expected_tag3[i], "%u: %02x != %02x\n", i, tag[i], expected_tag3[i]);
1425 ok(!memcmp(ivbuf, iv, sizeof(iv)), "wrong iv data.\n");
1426
1427 memset(tag, 0xff, sizeof(tag));
1428 ret = pBCryptEncrypt(key, data2, 0, &auth_info, ivbuf, 16, NULL, 0, &size, 0);
1429 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1430 ok(!size, "got %u\n", size);
1431 for (i = 0; i < 16; i++)
1432 ok(tag[i] == 0xff, "%u: %02x != %02x\n", i, tag[i], 0xff);
1433
1434 memset(tag, 0xff, sizeof(tag));
1435 ret = pBCryptEncrypt(key, NULL, 0, &auth_info, ivbuf, 16, NULL, 0, &size, 0);
1436 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1437 ok(!size, "got %u\n", size);
1438 ok(!memcmp(tag, expected_tag4, sizeof(expected_tag4)), "wrong tag\n");
1439 for (i = 0; i < 16; i++)
1440 ok(tag[i] == expected_tag4[i], "%u: %02x != %02x\n", i, tag[i], expected_tag4[i]);
1441
1442 /* test with padding */
1443 memcpy(ivbuf, iv, sizeof(iv));
1444 memset(ciphertext, 0, sizeof(ciphertext));
1445 ret = pBCryptEncrypt(key, data2, 32, &auth_info, ivbuf, 16, ciphertext, 32, &size, BCRYPT_BLOCK_PADDING);
1446 todo_wine ok(ret == STATUS_BUFFER_TOO_SMALL, "got 0x%x\n", ret);
1447
1448 memcpy(ivbuf, iv, sizeof(iv));
1449 memset(ciphertext, 0, sizeof(ciphertext));
1450 ret = pBCryptEncrypt(key, data2, 32, &auth_info, ivbuf, 16, ciphertext, 48, &size, BCRYPT_BLOCK_PADDING);
1451 ok(ret == STATUS_INVALID_PARAMETER, "got 0x%x\n", ret);
1452
1453 /* race test */
1454
1456 hthread = CreateThread(NULL, 0, encrypt_race_thread, key, 0, NULL);
1457
1459 ;
1460
1461 for (test = 0; test < RACE_TEST_COUNT; ++test)
1462 {
1463 size = 0;
1464 memset(ciphertext, 0xff, sizeof(ciphertext));
1465 memset(tag, 0xff, sizeof(tag));
1466 ret = pBCryptEncrypt(key, data2, 32, &auth_info, NULL, 0, ciphertext, 32, &size, 0);
1467 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1468 ok(size == 32, "got %u\n", size);
1469 ok(!memcmp(ciphertext, expected4, sizeof(expected4)), "wrong data\n");
1470 ok(!memcmp(tag, expected_tag3, sizeof(expected_tag2)), "wrong tag\n");
1471 for (i = 0; i < 32; i++)
1472 ok(ciphertext[i] == expected4[i], "%u: %02x != %02x\n", i, ciphertext[i], expected4[i]);
1473 for (i = 0; i < 16; i++)
1474 ok(tag[i] == expected_tag3[i], "%u: %02x != %02x\n", i, tag[i], expected_tag3[i]);
1475 }
1476
1477 WaitForSingleObject(hthread, INFINITE);
1478
1479 ret = pBCryptDestroyKey(key);
1480 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1481 free(buf);
1482
1483 /******************
1484 * AES - ECB mode *
1485 ******************/
1486
1487 ret = pBCryptSetProperty(aes, BCRYPT_CHAINING_MODE, (UCHAR*)BCRYPT_CHAIN_MODE_ECB, sizeof(BCRYPT_CHAIN_MODE_ECB), 0);
1488 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1489
1490 len = 0xdeadbeef;
1491 size = sizeof(len);
1492 ret = pBCryptGetProperty(aes, BCRYPT_OBJECT_LENGTH, (UCHAR *)&len, sizeof(len), &size, 0);
1493 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1494
1495 buf = calloc(1, len);
1496 ret = pBCryptGenerateSymmetricKey(aes, &key, buf, len, secret, sizeof(secret), 0);
1497 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1498
1499 /* initialization vector is not allowed */
1500 size = 0;
1501 memcpy(ivbuf, iv, sizeof(iv));
1502 ret = pBCryptEncrypt(key, data, 16, NULL, ivbuf, 16, ciphertext, 16, &size, 0);
1503 ok(ret == STATUS_INVALID_PARAMETER, "got 0x%x\n", ret);
1504 ok(size == 16, "got %u\n", size);
1505
1506 /* input size is a multiple of block size */
1507 size = 0;
1508 ret = pBCryptEncrypt(key, data, 16, NULL, NULL, 16, NULL, 0, &size, 0);
1509 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1510 ok(size == 16, "got %u\n", size);
1511
1512 size = 0;
1513 memset(ciphertext, 0, sizeof(ciphertext));
1514 ret = pBCryptEncrypt(key, data, 16, NULL, NULL, 16, ciphertext, 16, &size, 0);
1515 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1516 ok(size == 16, "got %u\n", size);
1517 ok(!memcmp(ciphertext, expected5, sizeof(expected5)), "wrong data\n");
1518 for (i = 0; i < 16; i++)
1519 ok(ciphertext[i] == expected5[i], "%u: %02x != %02x\n", i, ciphertext[i], expected5[i]);
1520
1521 /* input size is not a multiple of block size */
1522 size = 0;
1523 ret = pBCryptEncrypt(key, data, 17, NULL, NULL, 16, NULL, 0, &size, 0);
1524 ok(ret == STATUS_INVALID_BUFFER_SIZE, "got 0x%x\n", ret);
1525 ok(size == 17, "got %u\n", size);
1526
1527 /* input size is not a multiple of block size, block padding set */
1528 size = 0;
1529 ret = pBCryptEncrypt(key, data, 17, NULL, NULL, 16, NULL, 0, &size, BCRYPT_BLOCK_PADDING);
1530 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1531 ok(size == 32, "got %u\n", size);
1532
1533 size = 0;
1534 memset(ciphertext, 0, sizeof(ciphertext));
1535 ret = pBCryptEncrypt(key, data, 17, NULL, NULL, 16, ciphertext, 32, &size, BCRYPT_BLOCK_PADDING);
1536 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1537 ok(size == 32, "got %u\n", size);
1538 ok(!memcmp(ciphertext, expected6, sizeof(expected6)), "wrong data\n");
1539 for (i = 0; i < 32; i++)
1540 ok(ciphertext[i] == expected6[i], "%u: %02x != %02x\n", i, ciphertext[i], expected6[i]);
1541
1542 /* input size is a multiple of block size, block padding set */
1543 size = 0;
1544 ret = pBCryptEncrypt(key, data2, 32, NULL, NULL, 16, NULL, 0, &size, BCRYPT_BLOCK_PADDING);
1545 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1546 ok(size == 48, "got %u\n", size);
1547
1548 size = 0;
1549 memset(ciphertext, 0, sizeof(ciphertext));
1550 ret = pBCryptEncrypt(key, data2, 32, NULL, NULL, 16, ciphertext, 48, &size, BCRYPT_BLOCK_PADDING);
1551 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1552 ok(size == 48, "got %u\n", size);
1553 ok(!memcmp(ciphertext, expected7, sizeof(expected7)), "wrong data\n");
1554 for (i = 0; i < 48; i++)
1555 ok(ciphertext[i] == expected7[i], "%u: %02x != %02x\n", i, ciphertext[i], expected7[i]);
1556
1557 /* output size too small */
1558 size = 0;
1559 memset(ciphertext, 0, sizeof(ciphertext));
1560 ret = pBCryptEncrypt(key, data, 17, NULL, NULL, 16, ciphertext, 31, &size, BCRYPT_BLOCK_PADDING);
1561 ok(ret == STATUS_BUFFER_TOO_SMALL, "got 0x%x\n", ret);
1562 ok(size == 32, "got %u\n", size);
1563
1564 size = 0;
1565 memset(ciphertext, 0, sizeof(ciphertext));
1566 ret = pBCryptEncrypt(key, data2, 32, NULL, NULL, 16, ciphertext, 32, &size, BCRYPT_BLOCK_PADDING);
1567 ok(ret == STATUS_BUFFER_TOO_SMALL, "got 0x%x\n", ret);
1568 ok(size == 48, "got %u\n", size);
1569
1570 ret = pBCryptDestroyKey(key);
1571 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1572 free(buf);
1573
1574 /******************
1575 * AES - CFB mode *
1576 ******************/
1577
1578 ret = pBCryptSetProperty(aes, BCRYPT_CHAINING_MODE, (UCHAR *)BCRYPT_CHAIN_MODE_CFB, sizeof(BCRYPT_CHAIN_MODE_CFB), 0);
1579 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1580
1581 key = NULL;
1582 buf = calloc(1, len);
1583 ret = pBCryptGenerateSymmetricKey(aes, &key, buf, len, secret, sizeof(secret), 0);
1584 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1585 ok(key != NULL, "key not set\n");
1586
1587 /* input size is a multiple of block size */
1588 size = 0;
1589 memcpy(ivbuf, iv, sizeof(iv));
1590 ret = pBCryptEncrypt(key, data, 16, NULL, ivbuf, 16, NULL, 0, &size, 0);
1591 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1592 ok(size == 16, "got %u\n", size);
1593 ok(!memcmp(ivbuf, iv, sizeof(iv)), "wrong iv data.\n");
1594
1595 size = 0;
1596 memcpy(ivbuf, iv, sizeof(iv));
1597 memset(ciphertext, 0, sizeof(ciphertext));
1598 ret = pBCryptEncrypt(key, data, 16, NULL, ivbuf, 16, ciphertext, 16, &size, 0);
1599 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1600 ok(size == 16, "got %u\n", size);
1601 ok(!memcmp(ciphertext, expected11, sizeof(expected11)), "wrong data\n");
1602 for (i = 0; i < 16; i++)
1603 ok(ciphertext[i] == expected11[i], "%u: %02x != %02x\n", i, ciphertext[i], expected11[i]);
1604 ok(!memcmp(ivbuf, ciphertext, sizeof(iv)), "wrong iv data.\n");
1605
1606 /* NULL initialization vector */
1607 size = 0;
1608 memset(ciphertext, 0, sizeof(ciphertext));
1609 ret = pBCryptEncrypt(key, data, 16, NULL, NULL, 0, ciphertext, 16, &size, 0);
1610 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1611 ok(size == 16, "got %u\n", size);
1612 ok(!memcmp(ciphertext, expected12, sizeof(expected12)), "wrong data\n");
1613
1614 /* all zero initialization vector */
1615 size = 0;
1616 memset(ciphertext, 0, sizeof(ciphertext));
1617 memset(ivbuf, 0, sizeof(ivbuf));
1618 ret = pBCryptEncrypt(key, data, 16, NULL, ivbuf, 16, ciphertext, 16, &size, 0);
1619 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1620 ok(size == 16, "got %u\n", size);
1621 ok(!memcmp(ciphertext, expected13, sizeof(expected13)), "wrong data\n");
1622 for (i = 0; i < 16; i++)
1623 ok(ciphertext[i] == expected13[i], "%u: %02x != %02x\n", i, ciphertext[i], expected13[i]);
1624 ok(!memcmp(ivbuf, ciphertext, sizeof(iv)), "wrong iv data.\n");
1625
1626 /* input size is not a multiple of block size */
1627 size = 0;
1628 memcpy(ivbuf, iv, sizeof(iv));
1629 ret = pBCryptEncrypt(key, data, 17, NULL, ivbuf, 16, NULL, 0, &size, 0);
1630 todo_wine ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1631 ok(size == 17, "got %u\n", size);
1632
1633 /* input size is not a multiple of block size, block padding set */
1634 size = 0;
1635 memcpy(ivbuf, iv, sizeof(iv));
1636 ret = pBCryptEncrypt(key, data, 17, NULL, ivbuf, 16, NULL, 0, &size, BCRYPT_BLOCK_PADDING);
1637 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1638 ok(size == 32, "got %u\n", size);
1639 ok(!memcmp(ivbuf, iv, sizeof(iv)), "wrong iv data.\n");
1640
1641 size = 0;
1642 memcpy(ivbuf, iv, sizeof(iv));
1643 memset(ciphertext, 0, sizeof(ciphertext));
1644 ret = pBCryptEncrypt(key, data, 17, NULL, ivbuf, 16, ciphertext, 32, &size, BCRYPT_BLOCK_PADDING);
1645 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1646 ok(size == 32, "got %u\n", size);
1647 ok(!memcmp(ciphertext, expected14, sizeof(expected14)), "wrong data\n");
1648 for (i = 0; i < 32; i++)
1649 ok(ciphertext[i] == expected14[i], "%u: %02x != %02x\n", i, ciphertext[i], expected14[i]);
1650 ok(!memcmp(ivbuf, ciphertext + 32 - 16, sizeof(iv)), "wrong iv data.\n");
1651
1652 /* input size is a multiple of block size, block padding set */
1653 size = 0;
1654 memcpy(ivbuf, iv, sizeof(iv));
1655 ret = pBCryptEncrypt(key, data2, 32, NULL, ivbuf, 16, NULL, 0, &size, BCRYPT_BLOCK_PADDING);
1656 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1657 ok(size == 48, "got %u\n", size);
1658
1659 size = 0;
1660 memcpy(ivbuf, iv, sizeof(iv));
1661 memset(ciphertext, 0, sizeof(ciphertext));
1662 ret = pBCryptEncrypt(key, data2, 32, NULL, ivbuf, 16, ciphertext, 48, &size, BCRYPT_BLOCK_PADDING);
1663 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1664 ok(size == 48, "got %u\n", size);
1665 ok(!memcmp(ciphertext, expected15, sizeof(expected15)), "wrong data\n");
1666 for (i = 0; i < 48; i++)
1667 ok(ciphertext[i] == expected15[i], "%u: %02x != %02x\n", i, ciphertext[i], expected15[i]);
1668 ok(!memcmp(ivbuf, ciphertext + 48 - 16, sizeof(iv)), "wrong iv data.\n");
1669
1670 /* output size too small */
1671 size = 0;
1672 memcpy(ivbuf, iv, sizeof(iv));
1673 memset(ciphertext, 0, sizeof(ciphertext));
1674 ret = pBCryptEncrypt(key, data, 17, NULL, ivbuf, 16, ciphertext, 31, &size, BCRYPT_BLOCK_PADDING);
1675 ok(ret == STATUS_BUFFER_TOO_SMALL, "got 0x%x\n", ret);
1676 ok(size == 32, "got %u\n", size);
1677 ok(!memcmp(ivbuf, iv, sizeof(iv)), "wrong iv data.\n");
1678
1679 size = 0;
1680 memcpy(ivbuf, iv, sizeof(iv));
1681 memset(ciphertext, 0, sizeof(ciphertext));
1682 ret = pBCryptEncrypt(key, data2, 32, NULL, ivbuf, 16, ciphertext, 32, &size, BCRYPT_BLOCK_PADDING);
1683 ok(ret == STATUS_BUFFER_TOO_SMALL, "got 0x%x\n", ret);
1684 ok(size == 48, "got %u\n", size);
1685 ok(!memcmp(ivbuf, iv, sizeof(iv)), "wrong iv data.\n");
1686
1687 ret = pBCryptDestroyKey(key);
1688 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1689 free(buf);
1690
1691 /* 256 bit key */
1692 buf = calloc(1, len);
1693
1694 ret = pBCryptGenerateSymmetricKey(aes, &key, buf, len, secret256, sizeof(secret256), 0);
1695 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1696 ret = pBCryptDestroyKey(key);
1697 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1698
1699 /* Key generations succeeds if the key size exceeds maximum and uses maximum key length
1700 * from secret. */
1701 ret = pBCryptGenerateSymmetricKey(aes, &key, buf, len, secret256, sizeof(secret256) + 1, 0);
1702 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1703
1704 size = 0;
1705 memcpy(ivbuf, iv, sizeof(iv));
1706 ret = pBCryptEncrypt(key, data2, 32, NULL, ivbuf, 16, NULL, 0, &size, BCRYPT_BLOCK_PADDING);
1707 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1708 ok(size == 48, "got %u\n", size);
1709 ok(!memcmp(ivbuf, iv, sizeof(iv)), "wrong iv data.\n");
1710
1711 size = 0;
1712 memcpy(ivbuf, iv, sizeof(iv));
1713 memset(ciphertext, 0, sizeof(ciphertext));
1714 ret = pBCryptEncrypt(key, data2, 32, NULL, ivbuf, 16, ciphertext, 48, &size, BCRYPT_BLOCK_PADDING);
1715 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1716 ok(size == 48, "got %u\n", size);
1717 ok(!memcmp(ciphertext, expected16, sizeof(expected16)), "wrong data\n");
1718 for (i = 0; i < 48; i++)
1719 ok(ciphertext[i] == expected16[i], "%u: %02x != %02x\n", i, ciphertext[i], expected16[i]);
1720 ok(!memcmp(ivbuf, ciphertext + 48 - 16, sizeof(iv)), "wrong iv data.\n");
1721
1722 ret = pBCryptCloseAlgorithmProvider(aes, 0);
1723 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1724}
static DWORD WINAPI encrypt_race_thread(void *parameter)
Definition: bcrypt.c:1005
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:137
#define INFINITE
Definition: serial.h:102
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82

Referenced by START_TEST().

◆ test_BCryptEnumAlgorithms()

static void test_BCryptEnumAlgorithms ( void  )
static

Definition at line 3642 of file bcrypt.c.

3643{
3645 NTSTATUS ret;
3646 ULONG count, op;
3647
3648 ret = pBCryptEnumAlgorithms(0, NULL, NULL, 0);
3649 ok(ret == STATUS_INVALID_PARAMETER, "got 0x%x\n", ret);
3650
3651 ret = pBCryptEnumAlgorithms(0, &count, NULL, 0);
3652 ok(ret == STATUS_INVALID_PARAMETER, "got 0x%x\n", ret);
3653
3654 ret = pBCryptEnumAlgorithms(0, NULL, &list, 0);
3655 ok(ret == STATUS_INVALID_PARAMETER, "got 0x%x\n", ret);
3656
3657 ret = pBCryptEnumAlgorithms(~0u, &count, &list, 0);
3658 ok(ret == STATUS_INVALID_PARAMETER, "got 0x%x\n", ret);
3659
3660 count = 0;
3661 list = NULL;
3662 ret = pBCryptEnumAlgorithms(0, &count, &list, 0);
3663 ok(!ret, "got 0x%x\n", ret);
3664 ok(list != NULL, "NULL list\n");
3665 ok(count, "got %u\n", count);
3666 pBCryptFreeBuffer( list );
3667
3670 count = 0;
3671 list = NULL;
3672 ret = pBCryptEnumAlgorithms(op, &count, &list, 0);
3673 ok(!ret, "got 0x%x\n", ret);
3674 ok(list != NULL, "NULL list\n");
3675 ok(count, "got %u\n", count);
3676 pBCryptFreeBuffer( list );
3677}
#define BCRYPT_SECRET_AGREEMENT_OPERATION
Definition: bcrypt.h:142
#define BCRYPT_SIGNATURE_OPERATION
Definition: bcrypt.h:143
#define BCRYPT_CIPHER_OPERATION
Definition: bcrypt.h:139
#define BCRYPT_ASYMMETRIC_ENCRYPTION_OPERATION
Definition: bcrypt.h:141
Definition: list.h:37
UINT op
Definition: effect.c:236
GLuint GLuint GLsizei count
Definition: gl.h:1545
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
Definition: glfuncs.h:240
#define list
Definition: rosglue.h:35

Referenced by START_TEST().

◆ test_BCryptEnumContextFunctions()

static void test_BCryptEnumContextFunctions ( void  )
static

Definition at line 3507 of file bcrypt.c.

3508{
3511 ULONG buflen;
3512
3513 buffer = NULL;
3514 status = pBCryptEnumContextFunctions( CRYPT_LOCAL, L"SSL", NCRYPT_SCHANNEL_INTERFACE, &buflen, &buffer );
3515 todo_wine ok( status == STATUS_SUCCESS, "got 0x%08x\n", status);
3516 if (status == STATUS_SUCCESS) pBCryptFreeBuffer( buffer );
3517}
#define NCRYPT_SCHANNEL_INTERFACE
Definition: bcrypt.c:3505
#define CRYPT_LOCAL
Definition: bcrypt.h:449
GLuint buffer
Definition: glext.h:5915

Referenced by START_TEST().

◆ test_BCryptGenerateSymmetricKey()

static void test_BCryptGenerateSymmetricKey ( void  )
static

Definition at line 779 of file bcrypt.c.

780{
781 static UCHAR secret[] =
782 {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f};
783 static UCHAR iv[] =
784 {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f};
785 static UCHAR data[] =
786 {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f};
787 static UCHAR expected[] =
788 {0xc6,0xa1,0x3b,0x37,0x87,0x8f,0x5b,0x82,0x6f,0x4f,0x81,0x62,0xa1,0xc8,0xd8,0x79};
789 static UCHAR expected2[] =
790 {0xb5,0x8a,0x10,0x64,0xd8,0xac,0xa9,0x9b,0xd9,0xb0,0x40,0x5b,0x85,0x45,0xf5,0xbb};
791 static UCHAR expected3[] =
792 {0xe3,0x7c,0xd3,0x63,0xdd,0x7c,0x87,0xa0,0x9a,0xff,0x0e,0x3e,0x60,0xe0,0x9c,0x82};
795 UCHAR *buf, ciphertext[16], plaintext[16], ivbuf[16], mode[64];
796 BCRYPT_KEY_LENGTHS_STRUCT key_lengths;
797 ULONG size, len, len2, i;
799 DWORD keylen;
800
801 ret = pBCryptOpenAlgorithmProvider(&aes, BCRYPT_AES_ALGORITHM, NULL, 0);
802 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
803
804 len = size = 0xdeadbeef;
805 ret = pBCryptGetProperty(aes, BCRYPT_OBJECT_LENGTH, (UCHAR *)&len, sizeof(len), &size, 0);
806 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
807 len2 = len;
808
809 key = (void *)0xdeadbeef;
810 ret = pBCryptGenerateSymmetricKey(NULL, &key, NULL, 0, secret, sizeof(secret), 0);
811 ok(ret == STATUS_INVALID_HANDLE, "got 0x%x\n", ret);
812 ok(key == (void *)0xdeadbeef, "got %p\n", key);
813
814 key = NULL;
815 buf = calloc(1, len);
816
817 key = (BCRYPT_KEY_HANDLE)0xdeadbeef;
818 ret = pBCryptGenerateSymmetricKey(aes, &key, buf, len, secret, 1, 0);
819 ok(ret == STATUS_INVALID_PARAMETER, "got 0x%x\n", ret);
820 ok(key == (HANDLE)0xdeadbeef, "got unexpected key %p.\n", key);
821
822 key = (BCRYPT_KEY_HANDLE)0xdeadbeef;
823 ret = pBCryptGenerateSymmetricKey(aes, &key, buf, len, secret, sizeof(secret) + 1, 0);
824 ok(ret == STATUS_INVALID_PARAMETER, "got 0x%x\n", ret);
825 ok(key == (HANDLE)0xdeadbeef, "got unexpected key %p.\n", key);
826
827 ret = pBCryptGenerateSymmetricKey(aes, &key, buf, len, secret, sizeof(secret), 0);
828 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
829 ok(key != NULL, "key not set\n");
830
831 keylen = 0;
832 ret = pBCryptGetProperty(key, BCRYPT_KEY_STRENGTH, (UCHAR *)&keylen, sizeof(keylen), &size, 0);
833 ok(!ret, "got 0x%x\n", ret);
834 ok(size == sizeof(keylen), "got %u\n", size);
835 ok(keylen == 128, "got %u\n", keylen);
836
837 ret = pBCryptSetProperty(aes, BCRYPT_CHAINING_MODE, (UCHAR *)BCRYPT_CHAIN_MODE_CBC,
838 sizeof(BCRYPT_CHAIN_MODE_CBC), 0);
839 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
840
842 {
843 keylen = 512;
844 ret = pBCryptSetProperty(aes, BCRYPT_KEY_LENGTH, (UCHAR *)&keylen, sizeof(keylen), 0);
845 ok(ret == STATUS_NOT_SUPPORTED, "got 0x%x\n", ret);
846 }
847
848 size = 0;
849 memset(mode, 0, sizeof(mode));
850 ret = pBCryptGetProperty(key, BCRYPT_CHAINING_MODE, mode, sizeof(mode), &size, 0);
851 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
852 ok(!lstrcmpW((const WCHAR *)mode, BCRYPT_CHAIN_MODE_CBC), "got %s\n", wine_dbgstr_w((const WCHAR *)mode));
853 ok(size == 64, "got %u\n", size);
854
855 ret = pBCryptSetProperty(key, BCRYPT_CHAINING_MODE, (UCHAR *)BCRYPT_CHAIN_MODE_ECB, 0, 0);
856 ok(ret == STATUS_SUCCESS || broken(ret == STATUS_NOT_SUPPORTED) /* < Win 8 */, "got 0x%x\n", ret);
857 if (ret == STATUS_SUCCESS)
858 {
859 size = 0;
860 memset(mode, 0, sizeof(mode));
861 ret = pBCryptGetProperty(key, BCRYPT_CHAINING_MODE, mode, sizeof(mode), &size, 0);
862 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
863 ok(!lstrcmpW((const WCHAR *)mode, BCRYPT_CHAIN_MODE_ECB), "got %s\n", wine_dbgstr_w((const WCHAR *)mode));
864 ok(size == 64, "got %u\n", size);
865 }
866
867 ret = pBCryptSetProperty(key, BCRYPT_CHAINING_MODE, (UCHAR *)BCRYPT_CHAIN_MODE_CBC,
868 sizeof(BCRYPT_CHAIN_MODE_CBC), 0);
869 ok(ret == STATUS_SUCCESS || broken(ret == STATUS_NOT_SUPPORTED) /* < Win 8 */, "got 0x%x\n", ret);
870
871 size = 0xdeadbeef;
872 ret = pBCryptEncrypt(key, NULL, 0, NULL, NULL, 0, NULL, 0, &size, 0);
873 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
874 ok(!size, "got %u\n", size);
875
876 size = 0;
877 memcpy(ivbuf, iv, sizeof(iv));
878 ret = pBCryptEncrypt(key, data, 16, NULL, ivbuf, 16, NULL, 0, &size, 0);
879 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
880 ok(size == 16, "got %u\n", size);
881 ok(!memcmp(ivbuf, iv, sizeof(iv)), "wrong iv data.\n");
882
883 size = 0;
884 memcpy(ivbuf, iv, sizeof(iv));
885 memset(ciphertext, 0, sizeof(ciphertext));
886 ret = pBCryptEncrypt(key, data, 16, NULL, ivbuf, 16, ciphertext, 16, &size, 0);
887 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
888 ok(size == 16, "got %u\n", size);
889 ok(!memcmp(ciphertext, expected, sizeof(expected)), "wrong data\n");
890 for (i = 0; i < 16; i++)
891 ok(ciphertext[i] == expected[i], "%u: %02x != %02x\n", i, ciphertext[i], expected[i]);
892 ok(!memcmp(ivbuf, ciphertext, sizeof(iv)), "wrong iv data.\n");
893
894 size = 0;
895 memset(ciphertext, 0, sizeof(ciphertext));
896 ret = pBCryptEncrypt(key, data, 16, NULL, NULL, 0, ciphertext, 16, &size, 0);
897 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
898 ok(size == 16, "got %u\n", size);
899 ok(!memcmp(ciphertext, expected2, sizeof(expected2)), "wrong data\n");
900
901 size = 0;
902 memcpy(ivbuf, iv, sizeof(iv));
903 ++ivbuf[0];
904 memset(ciphertext, 0, sizeof(ciphertext));
905 ret = pBCryptEncrypt(key, data, 16, NULL, ivbuf, 16, ciphertext, 16, &size, 0);
906 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
907 ok(size == 16, "got %u\n", size);
908 ok(!memcmp(ciphertext, expected3, sizeof(expected3)), "wrong data\n");
909 for (i = 0; i < 16; i++)
910 ok(ciphertext[i] == expected3[i], "%u: %02x != %02x\n", i, ciphertext[i], expected3[i]);
911 ok(!memcmp(ivbuf, ciphertext, sizeof(iv)), "wrong iv data.\n");
912
913 key2 = (void *)0xdeadbeef;
914 ret = pBCryptDuplicateKey(NULL, &key2, NULL, 0, 0);
915 ok(ret == STATUS_INVALID_HANDLE, "got 0x%x\n", ret);
916 ok(key2 == (void *)0xdeadbeef, "got %p\n", key2);
917
918 if (0) /* crashes on some Windows versions */
919 {
920 ret = pBCryptDuplicateKey(key, NULL, NULL, 0, 0);
921 ok(ret == STATUS_INVALID_PARAMETER, "got 0x%x\n", ret);
922 }
923
924 key2 = (void *)0xdeadbeef;
925 ret = pBCryptDuplicateKey(key, &key2, NULL, 0, 0);
926 ok(ret == STATUS_SUCCESS || broken(ret == STATUS_INVALID_PARAMETER), "got 0x%x\n", ret);
927
928 if (ret == STATUS_SUCCESS)
929 {
930 size = 0;
931 memcpy(ivbuf, iv, sizeof(iv));
932 memset(ciphertext, 0, sizeof(ciphertext));
933 ret = pBCryptEncrypt(key2, data, 16, NULL, ivbuf, 16, ciphertext, 16, &size, 0);
934 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
935 ok(size == 16, "got %u\n", size);
936 ok(!memcmp(ciphertext, expected, sizeof(expected)), "wrong data\n");
937 for (i = 0; i < 16; i++)
938 ok(ciphertext[i] == expected[i], "%u: %02x != %02x\n", i, ciphertext[i], expected[i]);
939 ok(!memcmp(ivbuf, ciphertext, sizeof(iv)), "wrong iv data.\n");
940
941 ret = pBCryptDestroyKey(key2);
942 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
943 }
944
945 size = 0xdeadbeef;
946 ret = pBCryptDecrypt(key, NULL, 0, NULL, NULL, 0, NULL, 0, &size, 0);
947 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
948 ok(!size, "got %u\n", size);
949
950 size = 0;
951 memcpy(ivbuf, iv, sizeof(iv));
952 ret = pBCryptDecrypt(key, ciphertext, 16, NULL, ivbuf, 16, NULL, 0, &size, 0);
953 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
954 ok(size == 16, "got %u\n", size);
955
956 size = 0;
957 memcpy(ivbuf, iv, sizeof(iv));
958 memset(plaintext, 0, sizeof(plaintext));
959 ret = pBCryptDecrypt(key, ciphertext, 16, NULL, ivbuf, 16, plaintext, 16, &size, 0);
960 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
961 ok(size == 16, "got %u\n", size);
962 ok(!memcmp(plaintext, data, sizeof(data)), "wrong data\n");
963 ok(!memcmp(ivbuf, ciphertext, sizeof(iv)), "wrong iv data.\n");
964
965 memset(mode, 0, sizeof(mode));
966 ret = pBCryptGetProperty(key, BCRYPT_CHAINING_MODE, mode, sizeof(mode), &size, 0);
967 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
968 ok(!lstrcmpW((const WCHAR *)mode, BCRYPT_CHAIN_MODE_CBC), "wrong mode\n");
969
970 len = 0;
971 size = 0;
972 ret = pBCryptGetProperty(key, BCRYPT_BLOCK_LENGTH, (UCHAR *)&len, sizeof(len), &size, 0);
973 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
974 ok(len == 16, "got %u\n", len);
975 ok(size == sizeof(len), "got %u\n", size);
976
977 size = 0;
978 memset(&key_lengths, 0, sizeof(key_lengths));
979 ret = pBCryptGetProperty(aes, BCRYPT_KEY_LENGTHS, (UCHAR*)&key_lengths, sizeof(key_lengths), &size, 0);
980 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
981 ok(size == sizeof(key_lengths), "got %u\n", size);
982 ok(key_lengths.dwMinLength == 128, "Expected 128, got %u\n", key_lengths.dwMinLength);
983 ok(key_lengths.dwMaxLength == 256, "Expected 256, got %u\n", key_lengths.dwMaxLength);
984 ok(key_lengths.dwIncrement == 64, "Expected 64, got %u\n", key_lengths.dwIncrement);
985
986 ret = pBCryptDestroyKey(key);
987 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
988
989 if (pBCryptHash)
990 {
991 ret = pBCryptGenerateSymmetricKey(BCRYPT_AES_CBC_ALG_HANDLE, &key, buf, len2, secret, sizeof(secret), 0);
992 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
993 ret = pBCryptDestroyKey(key);
994 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
995 }
996
997 free(buf);
998 ret = pBCryptCloseAlgorithmProvider(aes, 0);
999 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
1000}
static BCRYPT_KEY_HANDLE
Definition: bcrypt.c:49
#define BCRYPT_KEY_LENGTH
Definition: bcrypt.h:52
#define BCRYPT_KEY_STRENGTH
Definition: bcrypt.h:55
unsigned long DWORD
Definition: ntddk_ex.h:95

Referenced by START_TEST().

◆ test_BCryptGenRandom()

static const WCHAR ULONG CRYPT_CONTEXT_FUNCTIONS **static void test_BCryptGenRandom ( void  )
static

Definition at line 64 of file bcrypt.c.

65{
67 UCHAR buffer[256];
68
69 ret = pBCryptGenRandom(NULL, NULL, 0, 0);
70 ok(ret == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got 0x%x\n", ret);
71 ret = pBCryptGenRandom(NULL, buffer, 0, 0);
72 ok(ret == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got 0x%x\n", ret);
73 ret = pBCryptGenRandom(NULL, buffer, sizeof(buffer), 0);
74 ok(ret == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got 0x%x\n", ret);
75 ret = pBCryptGenRandom(NULL, buffer, sizeof(buffer), BCRYPT_USE_SYSTEM_PREFERRED_RNG);
76 ok(ret == STATUS_SUCCESS, "Expected success, got 0x%x\n", ret);
77 ret = pBCryptGenRandom(NULL, buffer, sizeof(buffer),
79 ok(ret == STATUS_SUCCESS, "Expected success, got 0x%x\n", ret);
80 ret = pBCryptGenRandom(NULL, NULL, sizeof(buffer), BCRYPT_USE_SYSTEM_PREFERRED_RNG);
81 ok(ret == STATUS_INVALID_PARAMETER, "Expected STATUS_INVALID_PARAMETER, got 0x%x\n", ret);
82
83 /* Zero sized buffer should work too */
84 ret = pBCryptGenRandom(NULL, buffer, 0, BCRYPT_USE_SYSTEM_PREFERRED_RNG);
85 ok(ret == STATUS_SUCCESS, "Expected success, got 0x%x\n", ret);
86
87 /* Test random number generation - It's impossible for a sane RNG to return 8 zeros */
88 memset(buffer, 0, 16);
89 ret = pBCryptGenRandom(NULL, buffer, 8, BCRYPT_USE_SYSTEM_PREFERRED_RNG);
90 ok(ret == STATUS_SUCCESS, "Expected success, got 0x%x\n", ret);
91 ok(memcmp(buffer, buffer + 8, 8), "Expected a random number, got 0\n");
92
93 /* Test pseudo handle, which was introduced at the same time as BCryptHash */
94 if (pBCryptHash)
95 {
96 ret = pBCryptGenRandom(BCRYPT_RNG_ALG_HANDLE, buffer, sizeof(buffer), 0);
97 ok(ret == STATUS_SUCCESS, "Expected success, got 0x%x\n", ret);
98
99 ret = pBCryptCloseAlgorithmProvider(BCRYPT_RNG_ALG_HANDLE, 0);
100 ok(ret == STATUS_INVALID_HANDLE, "got 0x%x\n", ret);
101 }
102 else win_skip("BCryptGenRandom pseudo handles are not available\n");
103
104}
#define BCRYPT_RNG_ALG_HANDLE
Definition: bcrypt.h:385
#define BCRYPT_RNG_USE_ENTROPY_IN_BUFFER
Definition: bcrypt.h:437
#define BCRYPT_USE_SYSTEM_PREFERRED_RNG
Definition: bcrypt.h:438

Referenced by START_TEST().

◆ test_BCryptGetFipsAlgorithmMode()

static void test_BCryptGetFipsAlgorithmMode ( void  )
static

Definition at line 106 of file bcrypt.c.

107{
108 static const WCHAR policyKeyVistaW[] = {
109 'S','y','s','t','e','m','\\',
110 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
111 'C','o','n','t','r','o','l','\\',
112 'L','s','a','\\',
113 'F','I','P','S','A','l','g','o','r','i','t','h','m','P','o','l','i','c','y',0};
114 static const WCHAR policyValueVistaW[] = {'E','n','a','b','l','e','d',0};
115 static const WCHAR policyKeyXPW[] = {
116 'S','y','s','t','e','m','\\',
117 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
118 'C','o','n','t','r','o','l','\\',
119 'L','s','a',0};
120 static const WCHAR policyValueXPW[] = {
121 'F','I','P','S','A','l','g','o','r','i','t','h','m','P','o','l','i','c','y',0};
122 HKEY hkey = NULL;
125 DWORD value, count[2] = {sizeof(value), sizeof(value)};
127
128 if (RegOpenKeyW(HKEY_LOCAL_MACHINE, policyKeyVistaW, &hkey) == ERROR_SUCCESS &&
129 RegQueryValueExW(hkey, policyValueVistaW, NULL, NULL, (void *)&value, &count[0]) == ERROR_SUCCESS)
130 {
131 expected = !!value;
132 }
133 else if (RegOpenKeyW(HKEY_LOCAL_MACHINE, policyKeyXPW, &hkey) == ERROR_SUCCESS &&
134 RegQueryValueExW(hkey, policyValueXPW, NULL, NULL, (void *)&value, &count[0]) == ERROR_SUCCESS)
135 {
136 expected = !!value;
137 }
138 else
139 {
140 expected = FALSE;
142 ok(0, "Neither XP or Vista key is present\n");
143 }
144 RegCloseKey(hkey);
145
146 ret = pBCryptGetFipsAlgorithmMode(&enabled);
147 ok(ret == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got 0x%x\n", ret);
148 ok(enabled == expected, "expected result %d, got %d\n", expected, enabled);
149
150 ret = pBCryptGetFipsAlgorithmMode(NULL);
151 ok(ret == STATUS_INVALID_PARAMETER, "Expected STATUS_INVALID_PARAMETER, got 0x%x\n", ret);
152}
unsigned char BOOLEAN
Definition: actypes.h:127
#define RegCloseKey(hKey)
Definition: registry.h:49
#define ERROR_SUCCESS
Definition: deptool.c:10
#define FALSE
Definition: types.h:117
LONG WINAPI RegOpenKeyW(HKEY hKey, LPCWSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:3268
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
GLenum GLenum GLsizei const GLuint GLboolean enabled
Definition: glext.h:7750
Definition: pdh_main.c:96
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12

Referenced by START_TEST().

◆ test_BcryptHash()

static void test_BcryptHash ( void  )
static

Definition at line 461 of file bcrypt.c.

462{
463 static const char expected[] =
464 "e2a3e68d23ce348b8f68b3079de3d4c9";
465 static const char expected_hmac[] =
466 "7bda029b93fa8d817fcc9e13d6bdf092";
468 UCHAR md5[16], md5_hmac[16];
469 char str[65];
471
472 if (!pBCryptHash) /* < Win10 */
473 {
474 win_skip("BCryptHash is not available\n");
475 return;
476 }
477
478 alg = NULL;
479 ret = pBCryptOpenAlgorithmProvider(&alg, BCRYPT_MD5_ALGORITHM, MS_PRIMITIVE_PROVIDER, 0);
480 ok(ret == STATUS_SUCCESS, "got 0x%08x\n", ret);
481 ok(alg != NULL, "alg not set\n");
482
483 test_hash_length(alg, 16);
484 test_alg_name(alg, L"MD5");
485
486 memset(md5, 0, sizeof(md5));
487 ret = pBCryptHash(alg, NULL, 0, (UCHAR *)"test", sizeof("test"), md5, sizeof(md5));
488 ok(ret == STATUS_SUCCESS, "got 0x%08x\n", ret);
489 format_hash( md5, sizeof(md5), str );
490 ok(!strcmp(str, expected), "got %s\n", str);
491
492 ret = pBCryptCloseAlgorithmProvider(alg, 0);
493 ok(ret == STATUS_SUCCESS, "got 0x%08x\n", ret);
494
495 alg = NULL;
496 memset(md5_hmac, 0, sizeof(md5_hmac));
497 ret = pBCryptOpenAlgorithmProvider(&alg, BCRYPT_MD5_ALGORITHM, MS_PRIMITIVE_PROVIDER, BCRYPT_ALG_HANDLE_HMAC_FLAG);
498 ok(ret == STATUS_SUCCESS, "got 0x%08x\n", ret);
499 ok(alg != NULL, "alg not set\n");
500
501 ret = pBCryptHash(alg, (UCHAR *)"key", sizeof("key"), (UCHAR *)"test", sizeof("test"), md5_hmac, sizeof(md5_hmac));
502 ok(ret == STATUS_SUCCESS, "got 0x%08x\n", ret);
503 format_hash( md5_hmac, sizeof(md5_hmac), str );
504 ok(!strcmp(str, expected_hmac), "got %s\n", str);
505
506 ret = pBCryptCloseAlgorithmProvider(alg, 0);
507 ok(ret == STATUS_SUCCESS, "got 0x%08x\n", ret);
508
509 if (pBCryptHash)
510 {
511 memset(md5, 0, sizeof(md5));
512 ret = pBCryptHash(BCRYPT_MD5_ALG_HANDLE, NULL, 0, (UCHAR *)"test", sizeof("test"), md5, sizeof(md5));
513 ok(ret == STATUS_SUCCESS, "got 0x%08x\n", ret);
514 format_hash( md5, sizeof(md5), str );
515 ok(!strcmp(str, expected), "got %s\n", str);
516 }
517}
#define BCRYPT_MD5_ALG_HANDLE
Definition: bcrypt.h:379
#define BCRYPT_MD5_ALGORITHM
Definition: bcrypt.h:98
#define md5
Definition: compat-1.3.h:2034
_ACRTIMP int __cdecl strcmp(const char *, const char *)
Definition: string.c:3324

Referenced by START_TEST().

◆ test_BCryptSignHash()

static void test_BCryptSignHash ( void  )
static

Definition at line 3539 of file bcrypt.c.

3540{
3541 static UCHAR hash[] =
3542 {0x7e,0xe3,0x74,0xe7,0xc5,0x0b,0x6b,0x70,0xdb,0xab,0x32,0x6d,0x1d,0x51,0xd6,0x74,0x79,0x8e,0x5b,0x4b};
3543 static UCHAR hash_sha256[] =
3544 {0x25,0x2f,0x10,0xc8,0x36,0x10,0xeb,0xca,0x1a,0x05,0x9c,0x0b,0xae,0x82,0x55,0xeb,0xa2,0xf9,0x5b,0xe4,
3545 0xd1,0xd7,0xbC,0xfA,0x89,0xd7,0x24,0x8a,0x82,0xd9,0xf1,0x11};
3549 UCHAR sig[256];
3550 NTSTATUS ret;
3551 ULONG len;
3552
3553 /* RSA */
3554 ret = pBCryptOpenAlgorithmProvider(&alg, BCRYPT_RSA_ALGORITHM, NULL, 0);
3555 ok(!ret, "got 0x%x\n", ret);
3556
3557 /* public key */
3558 ret = pBCryptImportKeyPair(alg, NULL, BCRYPT_RSAPUBLIC_BLOB, &key, rsapublic, sizeof(rsapublic), 0);
3559 ok(!ret, "got 0x%x\n", ret);
3560
3561 len = 0;
3563 ret = pBCryptSignHash(key, &pad, NULL, 0, NULL, 0, &len, BCRYPT_PAD_PKCS1);
3564 ok(!ret, "got 0x%x\n", ret);
3565 ok(len == 256, "got %u\n", len);
3566
3567 /* test len return when only output is NULL, as described in BCryptSignHash doc */
3568 ret = pBCryptSignHash(key, &pad, hash, sizeof(hash), NULL, 0, &len, BCRYPT_PAD_PKCS1);
3569 ok(!ret, "got 0x%x\n", ret);
3570 ok(len == 256, "got %u\n", len);
3571
3572 len = 0;
3573 ret = pBCryptSignHash(key, &pad, hash, sizeof(hash), sig, sizeof(sig), &len, BCRYPT_PAD_PKCS1);
3574 ok(ret == STATUS_INVALID_PARAMETER || broken(ret == STATUS_INTERNAL_ERROR) /* < win7 */, "got 0x%x\n", ret);
3575 ret = pBCryptDestroyKey(key);
3576 ok(!ret, "got 0x%x\n", ret);
3577
3578 ret = pBCryptGenerateKeyPair(alg, &key, 512, 0);
3579 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
3580
3581 ret = pBCryptFinalizeKeyPair(key, 0);
3582 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
3583
3584 ret = pBCryptFinalizeKeyPair(key, 0);
3585 ok(ret == STATUS_INVALID_HANDLE, "got 0x%x\n", ret);
3586
3587 len = 0;
3588 memset(sig, 0, sizeof(sig));
3589
3590 /* inference of padding info on RSA not supported */
3591 ret = pBCryptSignHash(key, NULL, hash, sizeof(hash), sig, sizeof(sig), &len, 0);
3592 ok(ret == STATUS_INVALID_PARAMETER, "got 0x%x\n", ret);
3593
3594 ret = pBCryptSignHash(key, &pad, hash, sizeof(hash), sig, 0, &len, BCRYPT_PAD_PKCS1);
3595 ok(ret == STATUS_BUFFER_TOO_SMALL, "got 0x%x\n", ret);
3596
3597 ret = pBCryptSignHash(key, &pad, hash, sizeof(hash), sig, sizeof(sig), &len, BCRYPT_PAD_PKCS1);
3598 ok(!ret, "got 0x%x\n", ret);
3599 ok(len == 64, "got %u\n", len);
3600
3601 ret = pBCryptVerifySignature(key, &pad, hash, sizeof(hash), sig, len, BCRYPT_PAD_PKCS1);
3602 ok(!ret, "got 0x%x\n", ret);
3603
3604 ret = pBCryptDestroyKey(key);
3605 ok(!ret, "got 0x%x\n", ret);
3606
3607 ret = pBCryptCloseAlgorithmProvider(alg, 0);
3608 ok(!ret, "got 0x%x\n", ret);
3609
3610 /* ECDSA */
3611 ret = pBCryptOpenAlgorithmProvider(&alg, BCRYPT_ECDSA_P256_ALGORITHM, NULL, 0);
3612 ok(!ret, "got 0x%x\n", ret);
3613
3614 ret = pBCryptGenerateKeyPair(alg, &key, 256, 0);
3615 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
3616
3617 ret = pBCryptFinalizeKeyPair(key, 0);
3618 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
3619
3620 memset(sig, 0, sizeof(sig));
3621 len = 0;
3622
3623 /* automatically detects padding info */
3624 ret = pBCryptSignHash(key, NULL, hash, sizeof(hash), sig, sizeof(sig), &len, 0);
3625 ok (!ret, "got 0x%x\n", ret);
3626 ok (len == 64, "got %u\n", len);
3627
3628 ret = pBCryptVerifySignature(key, NULL, hash, sizeof(hash), sig, len, 0);
3629 ok(!ret, "got 0x%x\n", ret);
3630
3631 /* mismatch info (SHA-1 != SHA-256) */
3632 ret = pBCryptSignHash(key, &pad, hash_sha256, sizeof(hash_sha256), sig, sizeof(sig), &len, BCRYPT_PAD_PKCS1);
3633 ok (ret == STATUS_INVALID_PARAMETER, "got 0x%x\n", ret);
3634
3635 ret = pBCryptDestroyKey(key);
3636 ok(!ret, "got 0x%x\n", ret);
3637
3638 ret = pBCryptCloseAlgorithmProvider(alg, 0);
3639 ok(!ret, "got 0x%x\n", ret);
3640}
static BYTE rsapublic[]
Definition: bcrypt.c:3519
#define BCRYPT_RSAPUBLIC_BLOB
Definition: bcrypt.h:67
#define BCRYPT_RSA_ALGORITHM
Definition: bcrypt.h:102
#define BCRYPT_PAD_PKCS1
Definition: bcrypt.h:236
#define BCRYPT_ECDSA_P256_ALGORITHM
Definition: bcrypt.h:93
#define STATUS_INTERNAL_ERROR
Definition: ntstatus.h:559

Referenced by START_TEST().

◆ test_DH()

static void test_DH ( void  )
static

Definition at line 3349 of file bcrypt.c.

3350{
3351 UCHAR hash[20];
3352 BCRYPT_KEY_HANDLE key, pubkey, privkey;
3354 BCRYPT_DH_KEY_BLOB *dhkey;
3356 UCHAR *buf;
3357 ULONG size;
3358
3359 if (!pBCryptHash) /* < Win10 */
3360 {
3361 win_skip("broken DH detected\n");
3362 return;
3363 }
3364
3365 key = NULL;
3366 status = pBCryptGenerateKeyPair(BCRYPT_DH_ALG_HANDLE, &key, 512, 0);
3367 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
3368 ok(key != NULL, "key not set\n");
3369
3370 status = pBCryptFinalizeKeyPair(key, 0);
3371 todo_wine ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
3372 if (status != STATUS_SUCCESS)
3373 {
3374 pBCryptDestroyKey(key);
3375 return;
3376 }
3377
3378 size = 0;
3379 status = pBCryptExportKey(key, NULL, BCRYPT_DH_PUBLIC_BLOB, NULL, 0, &size, 0);
3380 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
3381 ok(size, "size not set\n");
3382
3383 buf = malloc(size);
3384 status = pBCryptExportKey(key, NULL, BCRYPT_DH_PUBLIC_BLOB, buf, size, &size, 0);
3385 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
3386 dhkey = (BCRYPT_DH_KEY_BLOB *)buf;
3387 ok(dhkey->dwMagic == BCRYPT_DH_PUBLIC_MAGIC, "got 0x%x\n", dhkey->dwMagic);
3388 ok(dhkey->cbKey == 64, "got %u\n", dhkey->cbKey);
3389 ok(size == sizeof(*dhkey) + dhkey->cbKey * 3, "got %u\n", size);
3390
3391 status = pBCryptImportKeyPair(BCRYPT_DH_ALG_HANDLE, NULL, BCRYPT_DH_PUBLIC_BLOB, &pubkey, buf, size, 0);
3392 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
3393 free(buf);
3394 pBCryptDestroyKey(pubkey);
3395
3396 size = 0;
3397 status = pBCryptExportKey(key, NULL, BCRYPT_DH_PRIVATE_BLOB, NULL, 0, &size, 0);
3398 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
3399 ok(size == sizeof(*dhkey) + 64 * 4, "size not set\n");
3400
3401 buf = calloc(1, size);
3402 status = pBCryptExportKey(key, NULL, BCRYPT_DH_PRIVATE_BLOB, buf, size, &size, 0);
3403 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
3404 dhkey = (BCRYPT_DH_KEY_BLOB *)buf;
3405 ok(dhkey->dwMagic == BCRYPT_DH_PRIVATE_MAGIC, "got 0x%x\n", dhkey->dwMagic);
3406 ok(dhkey->cbKey == 64, "got %u\n", dhkey->cbKey);
3407 ok(size == sizeof(*dhkey) + dhkey->cbKey * 4, "got %u\n", size);
3408 pBCryptDestroyKey(key);
3409
3410 status = pBCryptImportKeyPair(BCRYPT_DH_ALG_HANDLE, NULL, BCRYPT_DH_PRIVATE_BLOB, &privkey, buf, size, 0);
3411 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
3412 free(buf);
3413 pBCryptDestroyKey(privkey);
3414
3415 status = pBCryptImportKeyPair(BCRYPT_DH_ALG_HANDLE, NULL, BCRYPT_DH_PRIVATE_BLOB, &privkey, dh_privkey,
3416 sizeof(dh_privkey), 0);
3417 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
3418
3419 size = 0;
3420 status = pBCryptExportKey(privkey, NULL, BCRYPT_DH_PRIVATE_BLOB, NULL, 0, &size, 0);
3421 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
3422 ok(size, "size not set\n");
3423
3424 buf = malloc(size);
3425 status = pBCryptExportKey(privkey, NULL, BCRYPT_DH_PRIVATE_BLOB, buf, size, &size, 0);
3426 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
3427 ok(size == sizeof(dh_privkey), "got %u\n", size);
3428 ok(!memcmp(buf, dh_privkey, size), "wrong data\n");
3429 free(buf);
3430
3432 sizeof(dh_pubkey), 0);
3433 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
3434
3435 size = 0;
3436 status = pBCryptExportKey(privkey, NULL, BCRYPT_DH_PUBLIC_BLOB, NULL, 0, &size, 0);
3437 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
3438 ok(size, "size not set\n");
3439
3440 buf = malloc(size);
3441 status = pBCryptExportKey(privkey, NULL, BCRYPT_DH_PUBLIC_BLOB, buf, size, &size, 0);
3442 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
3443 ok(size == sizeof(dh_pubkey), "got %u\n", size);
3444 ok(!memcmp(buf, dh_pubkey, size), "wrong data\n");
3445 free(buf);
3446
3447 status = pBCryptSignHash(privkey, NULL, hash, sizeof(hash), NULL, 0, &size, 0);
3448 ok(status == STATUS_NOT_SUPPORTED, "got 0x%x\n", status);
3449
3450 status = pBCryptEncrypt(privkey, NULL, 0, NULL, NULL, 0, NULL, 0, &size, 0);
3451 ok(status == STATUS_NOT_SUPPORTED, "got 0x%x\n", status);
3452
3453 status = pBCryptSecretAgreement(privkey, pubkey, &secret, 0);
3454 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
3455 pBCryptDestroyKey(pubkey);
3456 pBCryptDestroyKey(privkey);
3457
3458 size = 0;
3459 status = pBCryptDeriveKey(secret, BCRYPT_KDF_RAW_SECRET, NULL, NULL, 0, &size, 0);
3461 {
3462 win_skip("BCRYPT_KDF_RAW_SECRET not supported\n"); /* < win10 */
3463 pBCryptDestroySecret(secret);
3464 return;
3465 }
3466 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
3467 ok(size == 64, "got %u\n", size);
3468
3469 buf = calloc(1, size);
3470 status = pBCryptDeriveKey(secret, BCRYPT_KDF_RAW_SECRET, NULL, buf, size, &size, 0);
3471 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
3472 ok(!memcmp(dh_secret, buf, size), "wrong data\n");
3473 free(buf);
3474
3475 size = 0;
3476 status = pBCryptDeriveKey(secret, BCRYPT_KDF_HASH, NULL, NULL, 0, &size, 0);
3477 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
3478 ok(size == 20, "got %u\n", size);
3479
3480 size = 0;
3481 status = pBCryptDeriveKey(secret, BCRYPT_KDF_HASH, &dh_hash_params, NULL, 0, &size, 0);
3482 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
3483 ok(size == 20, "got %u\n", size);
3484
3485 buf = calloc(1, size);
3486 status = pBCryptDeriveKey(secret, BCRYPT_KDF_HASH, &dh_hash_params, buf, size, NULL, 0);
3487 ok(status == STATUS_INVALID_PARAMETER, "got 0x%x\n", status);
3488
3489 status = pBCryptDeriveKey(secret, BCRYPT_KDF_HASH, &dh_hash_params, buf, size, &size, 0);
3490 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
3491 ok(!memcmp(dh_hashed_secret, buf, size), "wrong data\n");
3492 ok(size == 20, "got %u\n", size);
3493
3494 memset(buf, 0, 20);
3495 status = pBCryptDeriveKey(secret, BCRYPT_KDF_HASH, &dh_hash_params, buf, 10, &size, 0);
3496 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
3497 ok(!memcmp(dh_hashed_secret, buf, size), "wrong data\n");
3498 ok(size == 10, "got %u\n", size);
3499 free(buf);
3500
3501 pBCryptDestroySecret(secret);
3502}
BCryptBufferDesc dh_hash_params
Definition: bcrypt.c:3342
static BYTE dh_privkey[]
Definition: bcrypt.c:3293
static BYTE dh_secret[]
Definition: bcrypt.c:3319
static BYTE dh_hashed_secret[]
Definition: bcrypt.c:3327
static BYTE dh_pubkey[]
Definition: bcrypt.c:3272
#define BCRYPT_KDF_HASH
Definition: bcrypt.h:117
#define BCRYPT_DH_PUBLIC_MAGIC
Definition: bcrypt.h:280
#define BCRYPT_DH_ALG_HANDLE
Definition: bcrypt.h:417
#define BCRYPT_KDF_RAW_SECRET
Definition: bcrypt.h:121
#define BCRYPT_DH_PRIVATE_BLOB
Definition: bcrypt.h:75
#define BCRYPT_DH_PUBLIC_BLOB
Definition: bcrypt.h:74
#define BCRYPT_DH_PRIVATE_MAGIC
Definition: bcrypt.h:281
#define malloc
Definition: debug_ros.c:4
static const WCHAR pubkey[]
Definition: asmname.c:68

Referenced by START_TEST().

◆ test_DSA()

static void test_DSA ( void  )
static

Definition at line 3871 of file bcrypt.c.

3872{
3875 BCRYPT_DSA_KEY_BLOB *dsablob;
3876 UCHAR sig[40], schemes;
3877 ULONG len, size;
3878 NTSTATUS ret;
3879 BYTE *buf, buf2[sizeof(BCRYPT_DSA_KEY_BLOB) + sizeof(dsaPublicBlob)];
3880
3881 ret = pBCryptOpenAlgorithmProvider(&alg, BCRYPT_DSA_ALGORITHM, NULL, 0);
3882 ok(!ret, "got 0x%x\n", ret);
3883
3884 ret = pBCryptGetProperty(alg, L"PaddingSchemes", (UCHAR *)&schemes, sizeof(schemes), &size, 0);
3885 ok(ret == STATUS_NOT_SUPPORTED, "got 0x%x\n", ret);
3886
3887 ret = pBCryptImportKeyPair(alg, NULL, BCRYPT_PUBLIC_KEY_BLOB, &key, dsaPublicBlob, sizeof(dsaPublicBlob), 0);
3888 ok(!ret, "got 0x%x\n", ret);
3889 if(ret)
3890 {
3891 win_skip("BCRYPT_DSA_ALGORITHM not supported\n");
3892 goto dsa_end;
3893 }
3894 pBCryptDestroyKey(key);
3895
3896 ret = pBCryptImportKeyPair(alg, NULL, BCRYPT_DSA_PUBLIC_BLOB, &key, dsaPublicBlob, sizeof(dsaPublicBlob), 0);
3897 ok(!ret, "got 0x%x\n", ret);
3898
3899 memset(buf2, 0xcc, sizeof(buf2));
3900 ret = pBCryptExportKey(key, NULL, BCRYPT_DSA_PUBLIC_BLOB, buf2, sizeof(buf2), &size, 0);
3901 ok(!ret, "got 0x%x\n", ret);
3902 dsablob = (BCRYPT_DSA_KEY_BLOB *)buf2;
3903 ok(dsablob->dwMagic == BCRYPT_DSA_PUBLIC_MAGIC, "got 0x%x\n", dsablob->dwMagic);
3904 ok(dsablob->cbKey == 64, "got %u\n", dsablob->cbKey);
3905 ok(size == sizeof(*dsablob) + dsablob->cbKey * 3, "got %u\n", size);
3906
3907 ret = pBCryptExportKey(key, NULL, BCRYPT_DSA_PRIVATE_BLOB, buf2, sizeof(buf2), &size, 0);
3908 todo_wine ok(ret == STATUS_INVALID_PARAMETER, "got 0x%x\n", ret);
3909
3910 ret = pBCryptVerifySignature(key, NULL, dsaHash, sizeof(dsaHash), dsaSignature, sizeof(dsaSignature), 0);
3911 ok(!ret, "got 0x%x\n", ret);
3912
3913 ret = pBCryptDestroyKey(key);
3914 ok(!ret, "got 0x%x\n", ret);
3915
3916 /* sign/verify with export/import round-trip */
3917 ret = pBCryptGenerateKeyPair(alg, &key, 512, 0);
3918 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
3919
3920 ret = pBCryptFinalizeKeyPair(key, 0);
3921 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
3922
3923 len = 0;
3924 memset(sig, 0, sizeof(sig));
3925 ret = pBCryptSignHash(key, NULL, dsaHash, sizeof(dsaHash), sig, sizeof(sig), &len, 0);
3926 ok(!ret, "got 0x%x\n", ret);
3927 ok(len == 40, "got %u\n", len);
3928
3929 size = 0;
3930 ret = pBCryptExportKey(key, NULL, BCRYPT_DSA_PUBLIC_BLOB, NULL, 0, &size, 0);
3931 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
3932 ok(size, "size not set\n");
3933
3934 buf = calloc(1, size);
3935 ret = pBCryptExportKey(key, NULL, BCRYPT_DSA_PUBLIC_BLOB, buf, size, &size, 0);
3936 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
3937 dsablob = (BCRYPT_DSA_KEY_BLOB *)buf;
3938 ok(dsablob->dwMagic == BCRYPT_DSA_PUBLIC_MAGIC, "got 0x%x\n", dsablob->dwMagic);
3939 ok(dsablob->cbKey == 64, "got %u\n", dsablob->cbKey);
3940 ok(size == sizeof(*dsablob) + dsablob->cbKey * 3, "got %u\n", size);
3941
3942 ret = pBCryptDestroyKey(key);
3943 ok(!ret, "got 0x%x\n", ret);
3944
3945 ret = pBCryptImportKeyPair(alg, NULL, BCRYPT_DSA_PUBLIC_BLOB, &key, buf, size, 0);
3946 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
3947 free(buf);
3948
3949 ret = pBCryptVerifySignature(key, NULL, dsaHash, sizeof(dsaHash), sig, len, 0);
3950 ok(!ret, "got 0x%x\n", ret);
3951 ret = pBCryptDestroyKey(key);
3952 ok(!ret, "got 0x%x\n", ret);
3953
3954 ret = pBCryptImportKeyPair(alg, NULL, LEGACY_DSA_V2_PRIVATE_BLOB, &key, dssKey, sizeof(dssKey), 0);
3955 ok(!ret, "got 0x%x\n", ret);
3956
3957 size = 0;
3958 ret = pBCryptExportKey(key, NULL, LEGACY_DSA_V2_PRIVATE_BLOB, NULL, 0, &size, 0);
3959 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
3960 ok(size, "size not set\n");
3961
3962 buf = calloc(1, size);
3963 ret = pBCryptExportKey(key, NULL, LEGACY_DSA_V2_PRIVATE_BLOB, buf, size, &size, 0);
3964 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
3965 ok(size == sizeof(dssKey), "got %u expected %Iu\n", size, sizeof(dssKey));
3966 ok(!memcmp(dssKey, buf, size), "wrong data\n");
3967 free(buf);
3968
3969 ret = pBCryptDestroyKey(key);
3970 ok(!ret, "got 0x%x\n", ret);
3971dsa_end:
3972 ret = pBCryptCloseAlgorithmProvider(alg, 0);
3973 ok(!ret, "got 0x%x\n", ret);
3974}
static UCHAR dsaSignature[]
Definition: bcrypt.c:3827
static UCHAR dssKey[]
Definition: bcrypt.c:3850
static UCHAR dsaPublicBlob[]
Definition: bcrypt.c:3833
static UCHAR dsaHash[]
Definition: bcrypt.c:3822
#define LEGACY_DSA_V2_PRIVATE_BLOB
Definition: bcrypt.h:79
struct _BCRYPT_DSA_KEY_BLOB BCRYPT_DSA_KEY_BLOB
#define BCRYPT_DSA_ALGORITHM
Definition: bcrypt.h:90
#define BCRYPT_PUBLIC_KEY_BLOB
Definition: bcrypt.h:72
#define BCRYPT_DSA_PUBLIC_BLOB
Definition: bcrypt.h:70
#define BCRYPT_DSA_PRIVATE_BLOB
Definition: bcrypt.h:71
#define BCRYPT_DSA_PUBLIC_MAGIC
Definition: bcrypt.h:241
unsigned char BYTE
Definition: xxhash.c:193

Referenced by START_TEST().

◆ test_ECDH()

static void test_ECDH ( void  )
static

Definition at line 3102 of file bcrypt.c.

3103{
3104 BYTE *buf;
3105 BCRYPT_ECCKEY_BLOB *ecckey;
3107 BCRYPT_KEY_HANDLE key, privkey, pubkey;
3110 ULONG size;
3111
3112 status = pBCryptOpenAlgorithmProvider(&alg, BCRYPT_ECDH_P256_ALGORITHM, NULL, 0);
3113 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
3114
3115 key = NULL;
3116 status = pBCryptGenerateKeyPair(alg, &key, 256, 0);
3117 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
3118 ok(key != NULL, "key not set\n");
3119
3120 status = pBCryptFinalizeKeyPair(key, 0);
3121 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
3122
3123 size = 0;
3124 status = pBCryptExportKey(key, NULL, BCRYPT_ECCPUBLIC_BLOB, NULL, 0, &size, 0);
3125 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
3126 ok(size, "size not set\n");
3127
3128 buf = malloc(size);
3129 status = pBCryptExportKey(key, NULL, BCRYPT_ECCPUBLIC_BLOB, buf, size, &size, 0);
3130 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
3131 ecckey = (BCRYPT_ECCKEY_BLOB *)buf;
3132 ok(ecckey->dwMagic == BCRYPT_ECDH_PUBLIC_P256_MAGIC, "got 0x%x\n", ecckey->dwMagic);
3133 ok(ecckey->cbKey == 32, "got %u\n", ecckey->cbKey);
3134 ok(size == sizeof(*ecckey) + ecckey->cbKey * 2, "got %u\n", size);
3135
3136 status = pBCryptImportKeyPair(alg, NULL, BCRYPT_PUBLIC_KEY_BLOB, &pubkey, buf, size, 0);
3137 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
3138 pBCryptDestroyKey(pubkey);
3139
3140 status = pBCryptImportKeyPair(alg, NULL, BCRYPT_ECCPUBLIC_BLOB, &pubkey, buf, size, 0);
3141 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
3142 free(buf);
3143
3144 size = 0;
3145 status = pBCryptExportKey(key, NULL, BCRYPT_ECCPRIVATE_BLOB, NULL, 0, &size, 0);
3146 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
3147 ok(size, "size not set\n");
3148
3149 buf = malloc(size);
3150 status = pBCryptExportKey(key, NULL, BCRYPT_ECCPRIVATE_BLOB, buf, size, &size, 0);
3151 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
3152 ecckey = (BCRYPT_ECCKEY_BLOB *)buf;
3153 ok(ecckey->dwMagic == BCRYPT_ECDH_PRIVATE_P256_MAGIC, "got 0x%x\n", ecckey->dwMagic);
3154 ok(ecckey->cbKey == 32, "got %u\n", ecckey->cbKey);
3155 ok(size == sizeof(*ecckey) + ecckey->cbKey * 3, "got %u\n", size);
3156
3157 status = pBCryptImportKeyPair(alg, NULL, BCRYPT_ECCPRIVATE_BLOB, &privkey, buf, size, 0);
3158 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
3159 free(buf);
3160 pBCryptDestroyKey(pubkey);
3161 pBCryptDestroyKey(privkey);
3162 pBCryptDestroyKey(key);
3163
3164 status = pBCryptImportKeyPair(alg, NULL, BCRYPT_ECCPRIVATE_BLOB, &privkey, eccprivkey, sizeof(eccprivkey), 0);
3165 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
3166
3167 size = 0;
3168 status = pBCryptExportKey(privkey, NULL, BCRYPT_ECCPRIVATE_BLOB, NULL, 0, &size, 0);
3169 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
3170 ok(size, "size not set\n");
3171
3172 buf = malloc(size);
3173 status = pBCryptExportKey(privkey, NULL, BCRYPT_ECCPRIVATE_BLOB, buf, size, &size, 0);
3174 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
3175 ok(size == sizeof(eccprivkey), "got %u\n", size);
3176 ok(!memcmp(buf, eccprivkey, size), "wrong data\n");
3177 free(buf);
3178
3179 status = pBCryptImportKeyPair(alg, NULL, BCRYPT_ECCPUBLIC_BLOB, &pubkey, ecdh_pubkey, sizeof(ecdh_pubkey), 0);
3180 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
3181
3182 status = pBCryptSecretAgreement(privkey, pubkey, &secret, 0);
3183 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
3184 if (status != STATUS_SUCCESS) goto derive_end;
3185
3186 status = pBCryptDeriveKey(secret, BCRYPT_KDF_RAW_SECRET, NULL, NULL, 0, &size, 0);
3187 if (status == STATUS_NOT_SUPPORTED) /* < win10 */
3188 {
3189 win_skip("BCRYPT_KDF_RAW_SECRET not supported\n");
3190 goto raw_secret_end;
3191 }
3192 todo_wine ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
3193 if (status != STATUS_SUCCESS) goto raw_secret_end;
3194
3195 ok(size == 32, "size of secret key incorrect, got %u, expected 32\n", size);
3196 buf = malloc(size);
3197 status = pBCryptDeriveKey(secret, BCRYPT_KDF_RAW_SECRET, NULL, buf, size, &size, 0);
3198 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
3199 ok(!(memcmp(ecdh_secret, buf, size)), "wrong data\n");
3200 free(buf);
3201
3202raw_secret_end:
3203 status = pBCryptDeriveKey(secret, BCRYPT_KDF_HASH, &hash_params, NULL, 0, &size, 0);
3204 todo_wine ok (status == STATUS_SUCCESS, "got 0x%x\n", status);
3205 if (status != STATUS_SUCCESS) goto derive_end;
3206
3207 ok (size == 20, "got %u\n", size);
3208 buf = malloc(size);
3209 status = pBCryptDeriveKey(secret, BCRYPT_KDF_HASH, &hash_params, buf, size, &size, 0);
3210 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
3211 ok(!(memcmp(hashed_secret, buf, size)), "wrong data\n");
3212 free(buf);
3213
3214 /* ulVersion is not verified */
3215 hash_params.ulVersion = 0xdeadbeef;
3216 status = pBCryptDeriveKey(secret, BCRYPT_KDF_HASH, &hash_params, NULL, 0, &size, 0);
3217 ok (status == STATUS_SUCCESS, "got 0x%x\n", status);
3218
3220 hash_param_buffers[0].pvBuffer = (void*) L"INVALID";
3221 hash_param_buffers[0].cbBuffer = sizeof(L"INVALID");
3222
3223 status = pBCryptDeriveKey(secret, BCRYPT_KDF_HASH, &hash_params, NULL, 0, &size, 0);
3224 ok (status == STATUS_NOT_SUPPORTED || broken (status == STATUS_NOT_FOUND) /* < win8 */, "got 0x%x\n", status);
3225
3228 status = pBCryptDeriveKey(secret, BCRYPT_KDF_HASH, &hash_params, NULL, 0, &size, 0);
3229 ok (status == STATUS_NOT_SUPPORTED, "got 0x%x\n", status);
3230
3231derive_end:
3232 pBCryptDestroySecret(secret);
3233 pBCryptDestroyKey(pubkey);
3234 pBCryptDestroyKey(privkey);
3235 pBCryptCloseAlgorithmProvider(alg, 0);
3236
3237 status = pBCryptOpenAlgorithmProvider(&alg, BCRYPT_ECDH_P384_ALGORITHM, NULL, 0);
3238 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
3239
3240 key = NULL;
3241 status = pBCryptGenerateKeyPair(alg, &key, 384, 0);
3242 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
3243 ok(key != NULL, "key not set\n");
3244
3245 status = pBCryptFinalizeKeyPair(key, 0);
3246 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
3247
3248 size = 0;
3249 status = pBCryptExportKey(key, NULL, BCRYPT_ECCPUBLIC_BLOB, NULL, 0, &size, 0);
3250 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
3251 ok(size, "size not set\n");
3252
3253 buf = malloc(size);
3254 status = pBCryptExportKey(key, NULL, BCRYPT_ECCPUBLIC_BLOB, buf, size, &size, 0);
3255 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
3256 ecckey = (BCRYPT_ECCKEY_BLOB *)buf;
3257 ok(ecckey->dwMagic == BCRYPT_ECDH_PUBLIC_P384_MAGIC, "got 0x%x\n", ecckey->dwMagic);
3258 ok(ecckey->cbKey == 48, "got %u\n", ecckey->cbKey);
3259 ok(size == sizeof(*ecckey) + ecckey->cbKey * 2, "got %u\n", size);
3260
3261 status = pBCryptImportKeyPair(alg, NULL, BCRYPT_PUBLIC_KEY_BLOB, &pubkey, buf, size, 0);
3262 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
3263 pBCryptDestroyKey(pubkey);
3264
3265 status = pBCryptImportKeyPair(alg, NULL, BCRYPT_ECCPUBLIC_BLOB, &pubkey, buf, size, 0);
3266 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
3267 free(buf);
3268 pBCryptDestroyKey(pubkey);
3269 pBCryptCloseAlgorithmProvider(alg, 0);
3270}
static BYTE eccprivkey[]
Definition: bcrypt.c:3053
BCryptBufferDesc hash_params
Definition: bcrypt.c:3089
static BYTE ecdh_pubkey[]
Definition: bcrypt.c:3064
static BYTE hashed_secret[]
Definition: bcrypt.c:3096
BCryptBuffer hash_param_buffers[]
Definition: bcrypt.c:3080
static BYTE ecdh_secret[]
Definition: bcrypt.c:3074
#define BCRYPT_ECDH_P384_ALGORITHM
Definition: bcrypt.h:92
#define BCRYPT_ECDH_PRIVATE_P256_MAGIC
Definition: bcrypt.h:133
#define BCRYPT_ECCPUBLIC_BLOB
Definition: bcrypt.h:65
#define BCRYPT_ECDH_PUBLIC_P384_MAGIC
Definition: bcrypt.h:134
#define BCRYPTBUFFER_VERSION
Definition: bcrypt.h:358
#define BCRYPT_ECDH_PUBLIC_P256_MAGIC
Definition: bcrypt.h:132
#define BCRYPT_ECCPRIVATE_BLOB
Definition: bcrypt.h:66
#define BCRYPT_RNG_ALGORITHM
Definition: bcrypt.h:101
#define BCRYPT_ECDH_P256_ALGORITHM
Definition: bcrypt.h:91
#define STATUS_NOT_FOUND
Definition: shellext.h:72
ULONG ulVersion
Definition: bcrypt.h:362
ULONG cbBuffer
Definition: bcrypt.h:353
void * pvBuffer
Definition: bcrypt.h:355

Referenced by START_TEST().

◆ test_ECDSA()

static void test_ECDSA ( void  )
static

Definition at line 2264 of file bcrypt.c.

2265{
2266 BYTE buffer[sizeof(BCRYPT_ECCKEY_BLOB) + sizeof(eccPrivkey)];
2267 BCRYPT_ECCKEY_BLOB *ecckey = (void *)buffer;
2271 DWORD keylen;
2272 ULONG size;
2273
2274 status = pBCryptOpenAlgorithmProvider(&alg, BCRYPT_ECDSA_P256_ALGORITHM, NULL, 0);
2275 ok(!status, "got 0x%x\n", status);
2276
2278 memcpy(ecckey + 1, eccPubkey, sizeof(eccPubkey));
2279
2280 ecckey->cbKey = 2;
2281 size = sizeof(BCRYPT_ECCKEY_BLOB) + sizeof(eccPubkey);
2282 status = pBCryptImportKeyPair(alg, NULL, BCRYPT_ECCPUBLIC_BLOB, &key, buffer, size, 0);
2283 ok(status == STATUS_INVALID_PARAMETER, "Expected STATUS_INVALID_PARAMETER, got 0x%x\n", status);
2284
2286 ecckey->cbKey = 32;
2287 status = pBCryptImportKeyPair(alg, NULL, BCRYPT_ECCPUBLIC_BLOB, &key, buffer, size, 0);
2288 ok(status == STATUS_INVALID_PARAMETER, "Expected STATUS_INVALID_PARAMETER, got 0x%x\n", status);
2289
2291 ecckey->cbKey = 32;
2292 status = pBCryptImportKeyPair(alg, NULL, BCRYPT_PUBLIC_KEY_BLOB, &key, buffer, size, 0);
2293 ok(!status, "BCryptImportKeyPair failed: 0x%x\n", status);
2294 pBCryptDestroyKey(key);
2295
2296 if (pBCryptHash)
2297 {
2299 size, 0);
2300 ok(!status, "BCryptImportKeyPair failed: 0x%x\n", status);
2301 pBCryptDestroyKey(key);
2302 }
2303
2304 status = pBCryptImportKeyPair(alg, NULL, BCRYPT_ECCPUBLIC_BLOB, &key, buffer, size, 0);
2305 ok(!status, "BCryptImportKeyPair failed: 0x%x\n", status);
2306
2307 keylen = 0;
2308 status = pBCryptGetProperty(key, BCRYPT_KEY_STRENGTH, (UCHAR *)&keylen, sizeof(keylen), &size, 0);
2309 ok(!status, "got 0x%x\n", status);
2310 ok(size == sizeof(keylen), "got %u\n", size);
2311 ok(keylen == 256, "got %u\n", keylen);
2312
2313 memset(buffer, 0xcc, sizeof(buffer));
2314 status = pBCryptExportKey(key, NULL, BCRYPT_ECCPUBLIC_BLOB, buffer, sizeof(buffer), &size, 0);
2315 ok(!status, "Got unexpected status 0x%x\n", status);
2316 ok(ecckey->dwMagic == BCRYPT_ECDSA_PUBLIC_P256_MAGIC, "Got unexpected magic 0x%x.\n", ecckey->dwMagic);
2317 ok(ecckey->cbKey == 32, "got %u\n", ecckey->cbKey);
2318 ok(!memcmp(ecckey + 1, eccPubkey, sizeof(eccPubkey)), "Got unexpected key data.\n");
2319
2320 status = pBCryptExportKey(key, NULL, BCRYPT_ECCPRIVATE_BLOB, buffer, sizeof(buffer), &size, 0);
2321 ok(status == STATUS_INVALID_PARAMETER, "Got unexpected status 0x%x\n", status);
2322
2323 status = pBCryptVerifySignature(key, NULL, certHash, sizeof(certHash) - 1, certSignature, sizeof(certSignature), 0);
2324 ok(status == STATUS_INVALID_SIGNATURE, "Expected STATUS_INVALID_SIGNATURE, got 0x%x\n", status);
2325
2326 status = pBCryptVerifySignature(key, NULL, certHash, sizeof(certHash), certSignature, sizeof(certSignature), 0);
2327 ok(!status, "BCryptVerifySignature failed: 0x%x\n", status);
2328 pBCryptDestroyKey(key);
2329
2331 memcpy(ecckey + 1, eccPrivkey, sizeof(eccPrivkey));
2332
2333 ecckey->cbKey = 2;
2334 size = sizeof(BCRYPT_ECCKEY_BLOB) + sizeof(eccPrivkey);
2335 status = pBCryptImportKeyPair(alg, NULL, BCRYPT_ECCPRIVATE_BLOB, &key, buffer, size, 0);
2336 ok(status == STATUS_INVALID_PARAMETER, "Expected STATUS_INVALID_PARAMETER, got 0x%x\n", status);
2337
2339 ecckey->cbKey = 32;
2340 status = pBCryptImportKeyPair(alg, NULL, BCRYPT_ECCPRIVATE_BLOB, &key, buffer, size, 0);
2341 ok(status == STATUS_INVALID_PARAMETER, "Expected STATUS_INVALID_PARAMETER, got 0x%x\n", status);
2342
2344 ecckey->cbKey = 32;
2345 status = pBCryptImportKeyPair(alg, NULL, BCRYPT_ECCPRIVATE_BLOB, &key, buffer, size, 0);
2346 ok(!status, "BCryptImportKeyPair failed: 0x%x\n", status);
2347
2348 memset( buffer, 0xcc, sizeof(buffer) );
2349 status = pBCryptExportKey(key, NULL, BCRYPT_ECCPUBLIC_BLOB, buffer, sizeof(buffer), &size, 0);
2350 ok(!status, "Got unexpected status 0x%x\n", status);
2351 ok(ecckey->dwMagic == BCRYPT_ECDSA_PUBLIC_P256_MAGIC, "got 0x%x\n", ecckey->dwMagic);
2352 ok(ecckey->cbKey == 32, "got %u\n", ecckey->cbKey);
2353 ok(!memcmp(ecckey + 1, eccPrivkey, sizeof(eccPubkey)), "Got unexpected key data.\n");
2354
2355 size = sizeof(BCRYPT_ECCKEY_BLOB) + sizeof(eccPrivkey);
2356 memset( buffer, 0, sizeof(buffer) );
2357 status = pBCryptExportKey(key, NULL, BCRYPT_ECCPRIVATE_BLOB, buffer, size, &size, 0);
2358 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
2359 ecckey = (BCRYPT_ECCKEY_BLOB *)buffer;
2360 ok(ecckey->dwMagic == BCRYPT_ECDSA_PRIVATE_P256_MAGIC, "got 0x%x\n", ecckey->dwMagic);
2361 ok(ecckey->cbKey == 32, "got %u\n", ecckey->cbKey);
2362 ok(size == sizeof(*ecckey) + ecckey->cbKey * 3, "got %u\n", size);
2363
2364 pBCryptDestroyKey(key);
2365 pBCryptCloseAlgorithmProvider(alg, 0);
2366}
static BYTE eccPrivkey[]
Definition: bcrypt.c:2228
static BYTE certSignature[]
Definition: bcrypt.c:2254
static BYTE certHash[]
Definition: bcrypt.c:2249
static BYTE eccPubkey[]
Definition: bcrypt.c:2240
#define BCRYPT_ECDSA_PUBLIC_P256_MAGIC
Definition: bcrypt.h:125
struct _BCRYPT_ECCKEY_BLOB BCRYPT_ECCKEY_BLOB
#define BCRYPT_ECDSA_PRIVATE_P256_MAGIC
Definition: bcrypt.h:126
#define BCRYPT_ECDSA_P256_ALG_HANDLE
Definition: bcrypt.h:423
#define STATUS_INVALID_SIGNATURE
Definition: ntstatus.h:1397

Referenced by START_TEST().

◆ test_hash()

static void test_hash ( const struct hash_test test)
static

Definition at line 238 of file bcrypt.c.

239{
242 UCHAR buf[512], buf_hmac[1024], hash_buf[128], hmac_hash[128];
243 char str[512];
245 ULONG len;
246
247 alg = NULL;
248 ret = pBCryptOpenAlgorithmProvider(&alg, test->alg, MS_PRIMITIVE_PROVIDER, 0);
249 ok(ret == STATUS_SUCCESS, "got 0x%08x\n", ret);
250 ok(alg != NULL, "alg not set\n");
251
253 test_hash_length(alg, test->hash_size);
254 test_alg_name(alg, test->alg);
255
256 hash = NULL;
257 len = sizeof(buf);
258 ret = pBCryptCreateHash(alg, &hash, buf, len, NULL, 0, 0);
259 ok(ret == STATUS_SUCCESS, "got 0x%08x\n", ret);
260 ok(hash != NULL, "hash not set\n");
261
262 ret = pBCryptHashData(hash, NULL, 0, 0);
263 ok(ret == STATUS_SUCCESS, "got 0x%08x\n", ret);
264
265 ret = pBCryptHashData(hash, (UCHAR *)"test", sizeof("test"), 0);
266 ok(ret == STATUS_SUCCESS, "got 0x%08x\n", ret);
267
268 test_hash_length(hash, test->hash_size);
269 test_alg_name(hash, test->alg);
270
271 memset(hash_buf, 0, sizeof(hash_buf));
272 ret = pBCryptFinishHash(hash, hash_buf, test->hash_size, 0);
273 ok(ret == STATUS_SUCCESS, "got 0x%08x\n", ret);
274 format_hash( hash_buf, test->hash_size, str );
275 ok(!strcmp(str, test->hash), "got %s\n", str);
276
277 ret = pBCryptDestroyHash(hash);
278 ok(ret == STATUS_SUCCESS, "got 0x%08x\n", ret);
279
280 hash = NULL;
281 len = sizeof(buf);
282 ret = pBCryptCreateHash(alg, &hash, buf, len, NULL, 0, BCRYPT_HASH_REUSABLE_FLAG);
283 ok(ret == STATUS_SUCCESS || broken(ret == STATUS_INVALID_PARAMETER) /* < win8 */, "got 0x%08x\n", ret);
284 if (ret == STATUS_SUCCESS)
285 {
286 ret = pBCryptHashData(hash, (UCHAR *)"test", sizeof("test"), 0);
287 ok(ret == STATUS_SUCCESS, "got 0x%08x\n", ret);
288
289 memset(hash_buf, 0, sizeof(hash_buf));
290 ret = pBCryptFinishHash(hash, hash_buf, test->hash_size, 0);
291 ok(ret == STATUS_SUCCESS, "got 0x%08x\n", ret);
292 format_hash( hash_buf, test->hash_size, str );
293 ok(!strcmp(str, test->hash), "got %s\n", str);
294
295 /* reuse it */
296 ret = pBCryptHashData(hash, (UCHAR *)"tset", sizeof("tset"), 0);
297 ok(ret == STATUS_SUCCESS, "got 0x%08x\n", ret);
298
299 memset(hash_buf, 0, sizeof(hash_buf));
300 ret = pBCryptFinishHash(hash, hash_buf, test->hash_size, 0);
301 ok(ret == STATUS_SUCCESS, "got 0x%08x\n", ret);
302 format_hash( hash_buf, test->hash_size, str );
303 ok(!strcmp(str, test->hash2), "got %s\n", str);
304
305 ret = pBCryptDestroyHash(hash);
306 ok(ret == STATUS_SUCCESS, "got 0x%08x\n", ret);
307 }
308
309 ret = pBCryptCloseAlgorithmProvider(alg, 0);
310 ok(ret == STATUS_SUCCESS, "got 0x%08x\n", ret);
311
312 alg = NULL;
313 ret = pBCryptOpenAlgorithmProvider(&alg, test->alg, MS_PRIMITIVE_PROVIDER, BCRYPT_ALG_HANDLE_HMAC_FLAG);
314 ok(ret == STATUS_SUCCESS, "got 0x%08x\n", ret);
315 ok(alg != NULL, "alg not set\n");
316
317 hash = NULL;
318 len = sizeof(buf_hmac);
319 ret = pBCryptCreateHash(alg, &hash, buf_hmac, len, (UCHAR *)"key", sizeof("key"), 0);
320 ok(ret == STATUS_SUCCESS, "got 0x%08x\n", ret);
321 ok(hash != NULL, "hash not set\n");
322
323 ret = pBCryptHashData(hash, (UCHAR *)"test", sizeof("test"), 0);
324 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
325
326 test_hash_length(hash, test->hash_size);
327 test_alg_name(hash, test->alg);
328
329 memset(hmac_hash, 0, sizeof(hmac_hash));
330 ret = pBCryptFinishHash(hash, hmac_hash, test->hash_size, 0);
331 ok(ret == STATUS_SUCCESS, "got 0x%08x\n", ret);
332 format_hash( hmac_hash, test->hash_size, str );
333 ok(!strcmp(str, test->hmac_hash), "got %s\n", str);
334
335 ret = pBCryptDestroyHash(hash);
336 ok(ret == STATUS_SUCCESS, "got 0x%08x\n", ret);
337
338 hash = NULL;
339 len = sizeof(buf_hmac);
340 ret = pBCryptCreateHash(alg, &hash, buf_hmac, len, (UCHAR *)"key", sizeof("key"), BCRYPT_HASH_REUSABLE_FLAG);
341 ok(ret == STATUS_SUCCESS || broken(ret == STATUS_INVALID_PARAMETER) /* < win8 */, "got 0x%x\n", ret);
342 if (ret == STATUS_SUCCESS)
343 {
344 ret = pBCryptHashData(hash, (UCHAR *)"test", sizeof("test"), 0);
345 ok(ret == STATUS_SUCCESS, "got 0x%08x\n", ret);
346
347 memset(hmac_hash, 0, sizeof(hmac_hash));
348 ret = pBCryptFinishHash(hash, hmac_hash, test->hash_size, 0);
349 ok(ret == STATUS_SUCCESS, "got 0x%08x\n", ret);
350 format_hash( hmac_hash, test->hash_size, str );
351 ok(!strcmp(str, test->hmac_hash), "got %s\n", str);
352
353 /* reuse it */
354 ret = pBCryptHashData(hash, (UCHAR *)"tset", sizeof("tset"), 0);
355 ok(ret == STATUS_SUCCESS, "got 0x%08x\n", ret);
356
357 memset(hmac_hash, 0, sizeof(hmac_hash));
358 ret = pBCryptFinishHash(hash, hmac_hash, test->hash_size, 0);
359 ok(ret == STATUS_SUCCESS, "got 0x%08x\n", ret);
360 format_hash( hmac_hash, test->hash_size, str );
361 ok(!strcmp(str, test->hmac_hash2), "got %s\n", str);
362
363 ret = pBCryptDestroyHash(hash);
364 ok(ret == STATUS_SUCCESS, "got 0x%08x\n", ret);
365 }
366
367 ret = pBCryptDestroyHash(hash);
368 ok(ret == STATUS_INVALID_PARAMETER, "got 0x%08x\n", ret);
369
370 ret = pBCryptDestroyHash(NULL);
371 ok(ret == STATUS_INVALID_PARAMETER, "got 0x%08x\n", ret);
372
373 ret = pBCryptCloseAlgorithmProvider(alg, 0);
374 ok(ret == STATUS_SUCCESS, "got 0x%08x\n", ret);
375
376 if (pBCryptHash)
377 {
378 ret = pBCryptHash(BCRYPT_SHA1_ALG_HANDLE, NULL, 0, NULL, 0, hash_buf, 20);
379 ok(ret == STATUS_SUCCESS, "got 0x%08x\n", ret);
380 ret = pBCryptHash(BCRYPT_SHA1_ALG_HANDLE, NULL, 0, (UCHAR *)"test", sizeof("test"), NULL, 20);
381 ok(ret == STATUS_INVALID_PARAMETER, "got 0x%08x\n", ret);
382 ret = pBCryptHash(BCRYPT_SHA1_ALG_HANDLE, NULL, 0, (UCHAR *)"test", sizeof("test"), hash_buf, 21);
383 ok(ret == STATUS_INVALID_PARAMETER, "got 0x%08x\n", ret);
384 ret = pBCryptHash(BCRYPT_SHA1_ALG_HANDLE, NULL, 0, (UCHAR *)"test", sizeof("test"), hash_buf, 20);
385 ok(ret == STATUS_SUCCESS, "got 0x%08x\n", ret);
386
387 ret = pBCryptCreateHash(BCRYPT_SHA1_ALG_HANDLE, &hash, NULL, 0, NULL, 0, 0);
388 ok(ret == STATUS_SUCCESS, "got 0x%08x\n", ret);
389 ret = pBCryptHashData(hash, (UCHAR *)"test", sizeof("test"), 0);
390 ok(ret == STATUS_SUCCESS, "got 0x%08x\n", ret);
391 ret = pBCryptFinishHash(hash, hash_buf, 21, 0);
392 ok(ret == STATUS_INVALID_PARAMETER, "got 0x%x\n", ret);
393 ret = pBCryptFinishHash(hash, hash_buf, 20, 0);
394 ok(ret == STATUS_SUCCESS, "got 0x%08x\n", ret);
395 ret = pBCryptDestroyHash(hash);
396 ok(ret == STATUS_SUCCESS, "got 0x%08x\n", ret);
397 }
398}
#define test_object_length(a)
Definition: bcrypt.c:165
#define BCRYPT_HASH_REUSABLE_FLAG
Definition: bcrypt.h:447
#define BCRYPT_SHA1_ALG_HANDLE
Definition: bcrypt.h:380

Referenced by test_hashes().

◆ test_hashes()

static void test_hashes ( void  )
static

Definition at line 400 of file bcrypt.c.

401{
402 static const struct hash_test tests[] =
403 {
404 { L"SHA1", 20,
405 "961fa64958818f767707072755d7018dcd278e94",
406 "9314f62ff64197143c91fc86de37e9ae776a3fb8",
407 "2472cf65d0e090618d769d3e46f0d9446cf212da",
408 "b2d2ba8cfd714d474cf0d9622cc5d15e1f53d53f",
409 },
410 { L"SHA256", 32,
411 "ceb73749c899693706ede1e30c9929b3fd5dd926163831c2fb8bd41e6efb1126",
412 "ea0938c118a7b15954f41b85195f2b42aec3a9429c63f593cfa65c137ffaa986",
413 "34c1aa473a4468a91d06e7cdbc75bc4f93b830ccfc2a47ffd74e8e6ed29e4c72",
414 "55feb7052060bd99e33f36eb0982c7f4856eb6a84fbefe19a1afd9faafc3af6f",
415 },
416 { L"SHA384", 48,
417 "62b21e90c9022b101671ba1f808f8631a8149f0f12904055839a35c1ca78ae53"
418 "63eed1e743a692d70e0504b0cfd12ef9",
419 "724db7c0bbc51ef1ac3fc793083fc54c0e5c423faec9b11378c01c236b19aaaf"
420 "a45177ad055feaf003968cc40ece44c7",
421 "4b3e6d6ff2da121790ab7e7b9247583e3a7eed2db5bd4dabc680303b1608f37d"
422 "fdc836d96a704c03283bc05b4f6c5eb8",
423 "03e1818e5c165a0e54619e513acb06c393e1a6cb0ddbb4036b5f29617b334642"
424 "e6e0be8b214d8508595b17a8c4b4e7db",
425 },
426 { L"SHA512", 64,
427 "d55ced17163bf5386f2cd9ff21d6fd7fe576a915065c24744d09cfae4ec84ee1"
428 "ef6ef11bfbc5acce3639bab725b50a1fe2c204f8c820d6d7db0df0ecbc49c5ca",
429 "7752d707b54d2b00e7d1c09120d189475b0fd2e31ebb988cf0a01fc8492ddc0b"
430 "3ca9c9ca61d9d7d1fb65ca7665e87f043c1d5bc9f786f8345e951c2d91ac594f",
431 "415fb6b10018ca03b38a1b1399c42ac0be5e8aceddb9a73103f5e543bf2d888f"
432 "2eecf91373941f9315dd730a77937fa92444450fbece86f409d9cb5ec48c6513",
433 "1487bcecba46ae677622fa499e4cb2f0fdf92f6f3427cba76382d537a06e49c3"
434 "3e70a2fc1fc730092bf21128c3704cc6387f6dfbf7e2f9f315bbb894505a1205",
435 },
436 { L"MD2", 16,
437 "1bb33606ba908912a84221109d29cd7e",
438 "b9a6ad9323b17e2d0cd389dddd6ef78a",
439 "7f05b0638d77f4a27f3a9c4d353cd648",
440 "05980873e6bfdd05dd7b30078de7e42a",
441 },
442 { L"MD4", 16,
443 "74b5db93c0b41e36ca7074338fc0b637",
444 "a14a9ff2059a8c28f47b01e6bc48a1bf",
445 "bc2e8ac4d8248ed21b8d26227a30ea3a",
446 "b609db0eb4b8669db74f2c20099701e4",
447 },
448 { L"MD5", 16,
449 "e2a3e68d23ce348b8f68b3079de3d4c9",
450 "bcdd7ca574342aa9db0e212348eacb16",
451 "7bda029b93fa8d817fcc9e13d6bdf092",
452 "dd636ab8e9592c5088e57c37d44c5bb3",
453 }
454 };
455 unsigned i;
456
457 for(i = 0; i < ARRAY_SIZE(tests); i++)
459}
static void test_hash(const struct hash_test *test)
Definition: bcrypt.c:238
static struct test_info tests[]

Referenced by START_TEST().

◆ test_key_import_export()

static void test_key_import_export ( void  )
static

Definition at line 2121 of file bcrypt.c.

2122{
2123 static const UCHAR encrypted_blob[40] = {0x33,0x6e,0x51,0x10,
2124 0x25,0xba,0xdb,0xce,0xcb,0x25,0x00,0x85,0x51,0xc0,0xfa,0x21,
2125 0x66,0xdd,0x6d,0x67,0x46,0x76,0x0f,0x8a,0x44,0xe5,0x65,0x31,
2126 0xcb,0x02,0x52,0x9c,0x69,0x59,0x1a,0xec,0x67,0x27,0x11,0xaa};
2127 UCHAR buffer1[sizeof(BCRYPT_KEY_DATA_BLOB_HEADER) + 16];
2128 UCHAR buffer2[sizeof(BCRYPT_KEY_DATA_BLOB_HEADER) + 32], *buf;
2129 UCHAR buffer3[32 + 8], buffer4[sizeof(BCRYPT_KEY_DATA_BLOB_HEADER) + 32];
2130 BCRYPT_KEY_DATA_BLOB_HEADER *key_data1 = (void*)buffer1;
2131 BCRYPT_KEY_DATA_BLOB_HEADER *key_data2 = (void*)buffer2;
2133 BCRYPT_KEY_HANDLE key, key2, key3;
2134 NTSTATUS ret;
2135 ULONG size;
2136
2137 ret = pBCryptOpenAlgorithmProvider(&aes, BCRYPT_AES_ALGORITHM, NULL, 0);
2138 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2139
2140 key_data1->dwMagic = BCRYPT_KEY_DATA_BLOB_MAGIC;
2141 key_data1->dwVersion = BCRYPT_KEY_DATA_BLOB_VERSION1;
2142 key_data1->cbKeyData = 16;
2143 memset(&key_data1[1], 0x11, 16);
2144
2145 key = NULL;
2146 ret = pBCryptImportKey(aes, NULL, BCRYPT_KEY_DATA_BLOB, &key, NULL, 0, buffer1, sizeof(buffer1), 0);
2147 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2148 ok(key != NULL, "key not set\n");
2149
2152 key_data2->cbKeyData = 32;
2153 memset(&key_data2[1], 0x22, 32);
2154 key2 = NULL;
2155 ret = pBCryptImportKey(aes, NULL, BCRYPT_KEY_DATA_BLOB, &key2, NULL, 0, buffer2, sizeof(buffer2), 0);
2156 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2157 ok(key2 != NULL, "key not set\n");
2158
2159 size = 0;
2160 ret = pBCryptExportKey(key2, key, BCRYPT_AES_WRAP_KEY_BLOB, NULL, 0, &size, 0);
2161 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2162 ok(size == sizeof(buffer3), "got %u\n", size);
2163
2164 ret = pBCryptExportKey(key2, key, BCRYPT_AES_WRAP_KEY_BLOB, buffer3, size, &size, 0);
2165 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2166 ok(!memcmp(buffer3, encrypted_blob, sizeof(encrypted_blob)), "blobs didn't match\n");
2167
2168 key3 = NULL;
2169 ret = pBCryptImportKey(aes, key, BCRYPT_AES_WRAP_KEY_BLOB, &key3, NULL, 0, buffer3, sizeof(buffer3), 0);
2170 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2171 ok(key3 != NULL, "key not set\n");
2172
2173 size = 0;
2174 memset(buffer4, 0xff, sizeof(buffer4));
2175 ret = pBCryptExportKey(key3, NULL, BCRYPT_KEY_DATA_BLOB, buffer4, sizeof(buffer4), &size, 0);
2176 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2177 ok(size == sizeof(buffer2), "Got %u\n", size);
2178 ok(!memcmp(buffer4, buffer2, sizeof(buffer2)), "Expected exported key to match imported key\n");
2179
2180 pBCryptDestroyKey(key3);
2181 pBCryptDestroyKey(key2);
2182
2183 size = 0;
2184 ret = pBCryptExportKey(key, NULL, BCRYPT_KEY_DATA_BLOB, buffer1, 0, &size, 0);
2185 ok(ret == STATUS_BUFFER_TOO_SMALL, "got 0x%x\n", ret);
2186 ok(size == sizeof(buffer1), "got %u\n", size);
2187
2188 size = 0;
2189 memset(buffer2, 0xff, sizeof(buffer2));
2190 ret = pBCryptExportKey(key, NULL, BCRYPT_KEY_DATA_BLOB, buffer2, sizeof(buffer2), &size, 0);
2191 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2192 ok(size == sizeof(buffer1), "Got %u\n", size);
2193 ok(!memcmp(buffer1, buffer2, sizeof(buffer1)), "Expected exported key to match imported key\n");
2194
2195 /* opaque blob */
2196 size = 0;
2197 ret = pBCryptExportKey(key, NULL, BCRYPT_OPAQUE_KEY_BLOB, buffer2, 0, &size, 0);
2198 ok(ret == STATUS_BUFFER_TOO_SMALL, "got 0x%x\n", ret);
2199 ok(size > 0, "got zero\n");
2200
2201 buf = malloc(size);
2202 ret = pBCryptExportKey(key, NULL, BCRYPT_OPAQUE_KEY_BLOB, buf, size, &size, 0);
2203 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2204
2205 ret = pBCryptDestroyKey(key);
2206 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2207
2208 key = NULL;
2209 ret = pBCryptImportKey(aes, NULL, BCRYPT_OPAQUE_KEY_BLOB, &key, NULL, 0, buf, size, 0);
2210 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2211 ok(key != NULL, "key not set\n");
2212
2213 ret = pBCryptDestroyKey(key);
2214 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2215
2216 if (pBCryptHash)
2217 {
2218 ret = pBCryptImportKey(BCRYPT_AES_CBC_ALG_HANDLE, NULL, BCRYPT_OPAQUE_KEY_BLOB, &key, NULL, 0, buf, size, 0);
2219 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2220 pBCryptDestroyKey(key);
2221 }
2222
2223 free(buf);
2224 ret = pBCryptCloseAlgorithmProvider(aes, 0);
2225 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2226}
#define BCRYPT_AES_WRAP_KEY_BLOB
Definition: bcrypt.h:64
#define BCRYPT_OPAQUE_KEY_BLOB
Definition: bcrypt.h:62

Referenced by START_TEST().

◆ test_PBKDF2()

static void test_PBKDF2 ( void  )
static

Definition at line 4424 of file bcrypt.c.

4425{
4426 static char salt[] = "cCxuHMEHLibcglJOG88dIw==";
4427 static ULONGLONG iter_count = 25;
4428 static BCryptBuffer pbkdf2_param_buffers[] =
4429 {
4430 {
4431 sizeof(BCRYPT_SHA1_ALGORITHM),
4433 (void *)BCRYPT_SHA1_ALGORITHM,
4434 },
4435 {
4436 sizeof(salt) - 1,
4437 KDF_SALT,
4438 salt,
4439 },
4440 {
4441 sizeof(iter_count),
4443 (void *)&iter_count,
4444 }
4445 };
4446 static BCryptBufferDesc pbkdf2_params =
4447 {
4449 ARRAY_SIZE(pbkdf2_param_buffers),
4450 pbkdf2_param_buffers,
4451 };
4452 static UCHAR pbkdf2_hash[] =
4453 {
4454 0x18, 0xf2, 0x58, 0x0b, 0x92, 0x6e, 0x6d, 0xfe,
4455 0x55, 0xbb, 0x62, 0x87, 0x5b, 0x1f, 0x61, 0x83,
4456 0x4d, 0x16, 0xe4, 0x04, 0xcd, 0xab, 0x43, 0x77,
4457 0x25, 0x3e, 0x1d, 0xb4, 0x95, 0x5f, 0xf7, 0x01,
4458 };
4459
4460 BCRYPT_KEY_LENGTHS_STRUCT key_lengths;
4464 ULONG val, size;
4465 static BYTE buf[32];
4466
4467 status = pBCryptOpenAlgorithmProvider(&alg, BCRYPT_PBKDF2_ALGORITHM, NULL, 0);
4468 if (status == STATUS_NOT_FOUND)
4469 {
4470 win_skip("PBKDF2 not available\n");
4471 return;
4472 }
4473 ok(!status, "got 0x%x\n", status);
4474 ok(pBCryptKeyDerivation != NULL, "BCryptKeyDerivation not available\n");
4475
4476 val = size = 0;
4477 status = pBCryptGetProperty(alg, BCRYPT_OBJECT_LENGTH, (UCHAR *)&val, sizeof(val), &size, 0);
4478 ok(!status, "got 0x%x\n", status);
4479 ok(val, "got %u\n", val);
4480 ok(size == sizeof(val), "got %u\n", size);
4481
4482 val = size = 0;
4483 status = pBCryptGetProperty(alg, BCRYPT_BLOCK_LENGTH, (UCHAR *)&val, sizeof(val), &size, 0);
4484 ok(status == STATUS_NOT_SUPPORTED, "got 0x%x\n", status);
4485
4486 memset(&key_lengths, 0xfe, sizeof(key_lengths));
4487 size = 0;
4488 status = pBCryptGetProperty(alg, BCRYPT_KEY_LENGTHS, (UCHAR *)&key_lengths, sizeof(key_lengths), &size, 0);
4489 ok(!status, "got 0x%x\n", status);
4490 ok(size == sizeof(key_lengths), "got %u\n", size);
4491 ok(key_lengths.dwMinLength == 0, "got %u\n", key_lengths.dwMinLength);
4492 ok(key_lengths.dwMaxLength == 16384, "got %u\n", key_lengths.dwMaxLength);
4493 ok(key_lengths.dwIncrement == 8, "got %u\n", key_lengths.dwIncrement);
4494
4495 key = 0;
4496 status = pBCryptGenerateSymmetricKey(alg, &key, NULL, 0, (UCHAR *)"test", 4, 0);
4497 ok(!status, "got 0x%x\n", status);
4498 val = size = 0;
4499 status = pBCryptGetProperty(key, BCRYPT_KEY_STRENGTH, (UCHAR *)&val, sizeof(val), &size, 0);
4500 ok(!status, "got 0x%x\n", status);
4501 ok(val == strlen("test") * 8, "got %u\n", val);
4502
4503 status = pBCryptKeyDerivation(key, &pbkdf2_params, NULL, 0, &size, 0);
4504 ok(status == STATUS_INVALID_PARAMETER, "got 0x%x\n", status);
4505
4506 buf[0] = buf[1] = 'x';
4507 status = pBCryptKeyDerivation(key, &pbkdf2_params, buf, 1, &size, 0);
4508 ok(!status, "got 0x%x\n", status);
4509 ok(size == 1, "size = %u\n", size);
4510 ok(buf[0] == pbkdf2_hash[0], "buf[0] = %x\n", buf[0]);
4511 ok(buf[1] == 'x', "buf[1] = %x\n", buf[1]);
4512
4513 memset(buf, 'x', sizeof(buf));
4514 status = pBCryptKeyDerivation(key, &pbkdf2_params, buf, sizeof(buf), &size, 0);
4515 ok(!status, "got 0x%x\n", status);
4516 ok(size == sizeof(buf), "size = %u\n", size);
4517 ok(!memcmp(buf, pbkdf2_hash, sizeof(pbkdf2_hash)),
4518 "wrong data (%s)\n", wine_dbgstr_an((char *)buf, size));
4519
4520 status = pBCryptDestroyKey(key);
4521 ok(!status, "got 0x%x\n", status);
4522 status = pBCryptCloseAlgorithmProvider(alg, 0);
4523 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
4524}
#define KDF_SALT
Definition: bcrypt.h:348
#define KDF_ITERATION_COUNT
Definition: bcrypt.h:349
#define BCRYPT_PBKDF2_ALGORITHM
Definition: bcrypt.h:108
#define KDF_HASH_ALGORITHM
Definition: bcrypt.h:333
const char * wine_dbgstr_an(const char *str, int n)
Definition: compat.c:313
_ACRTIMP size_t __cdecl strlen(const char *)
Definition: string.c:1597
GLuint GLfloat * val
Definition: glext.h:7180
uint64_t ULONGLONG
Definition: typedefs.h:67

Referenced by START_TEST().

◆ test_RC4()

static void test_RC4 ( void  )
static

Definition at line 4395 of file bcrypt.c.

4396{
4399 ULONG len, size;
4400
4401 status = pBCryptOpenAlgorithmProvider(&alg, BCRYPT_RC4_ALGORITHM, NULL, 0);
4402 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
4403
4404 len = size = 0;
4405 status = pBCryptGetProperty(alg, BCRYPT_OBJECT_LENGTH, (UCHAR *)&len, sizeof(len), &size, 0);
4406 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
4407 ok(len, "expected non-zero len\n");
4408 ok(size == sizeof(len), "got %u\n", size);
4409
4410 len = size = 0;
4411 status = pBCryptGetProperty(alg, BCRYPT_BLOCK_LENGTH, (UCHAR *)&len, sizeof(len), &size, 0);
4412 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
4413 ok(len == 1, "got %u\n", len);
4414 ok(size == sizeof(len), "got %u\n", size);
4415
4416 size = sizeof(BCRYPT_CHAIN_MODE_NA);
4417 status = pBCryptSetProperty(alg, BCRYPT_CHAINING_MODE, (UCHAR *)BCRYPT_CHAIN_MODE_NA, size, 0);
4418 ok(!status, "got 0x%x\n", status);
4419
4420 status = pBCryptCloseAlgorithmProvider(alg, 0);
4421 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
4422}
#define BCRYPT_RC4_ALGORITHM
Definition: bcrypt.h:100
#define BCRYPT_CHAIN_MODE_NA
Definition: bcrypt.h:110

Referenced by START_TEST().

◆ test_rng()

static void test_rng ( void  )
static

Definition at line 597 of file bcrypt.c.

598{
600 ULONG size, len;
601 UCHAR buf[16];
603
604 alg = NULL;
605 ret = pBCryptOpenAlgorithmProvider(&alg, BCRYPT_RNG_ALGORITHM, MS_PRIMITIVE_PROVIDER, 0);
606 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
607 ok(alg != NULL, "alg not set\n");
608
609 len = size = 0xdeadbeef;
610 ret = pBCryptGetProperty(alg, BCRYPT_OBJECT_LENGTH, (UCHAR *)&len, sizeof(len), &size, 0);
611 ok(ret == STATUS_NOT_SUPPORTED, "got 0x%x\n", ret);
612
613 len = size = 0xdeadbeef;
614 ret = pBCryptGetProperty(alg, BCRYPT_HASH_LENGTH, (UCHAR *)&len, sizeof(len), &size, 0);
615 ok(ret == STATUS_NOT_SUPPORTED, "got 0x%x\n", ret);
616
617 test_alg_name(alg, L"RNG");
618
619 memset(buf, 0, 16);
620 ret = pBCryptGenRandom(alg, buf, 8, 0);
621 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
622 ok(memcmp(buf, buf + 8, 8), "got zeroes\n");
623
624 ret = pBCryptCloseAlgorithmProvider(alg, 0);
625 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
626}

Referenced by START_TEST().

◆ test_RSA()

static void test_RSA ( void  )
static

Definition at line 2704 of file bcrypt.c.

2705{
2706 static UCHAR hash[] =
2707 {0x7e,0xe3,0x74,0xe7,0xc5,0x0b,0x6b,0x70,0xdb,0xab,0x32,0x6d,0x1d,0x51,0xd6,0x74,0x79,0x8e,0x5b,0x4b};
2708 static UCHAR hash48[] =
2709 {0x62,0xb2,0x1e,0x90,0xc9,0x02,0x2b,0x10,0x16,0x71,0xba,0x1f,0x80,0x8f,0x86,0x31,0xa8,0x14,0x9f,0x0f,
2710 0x12,0x90,0x40,0x55,0x83,0x9a,0x35,0xc1,0xca,0x78,0xae,0x53,0x1b,0xb3,0x36,0x06,0xba,0x90,0x89,0x12,
2711 0xa8,0x42,0x21,0x10,0x9d,0x29,0xcd,0x7e};
2716 BCRYPT_RSAKEY_BLOB *rsablob;
2717 UCHAR sig[256], sig_pss[256];
2718 ULONG len, size, size2, schemes;
2719 NTSTATUS ret;
2720 BYTE *buf;
2721 DWORD keylen;
2722
2723 ret = pBCryptOpenAlgorithmProvider(&alg, BCRYPT_RSA_ALGORITHM, NULL, 0);
2724 ok(!ret, "got 0x%x\n", ret);
2725
2726 schemes = size = 0;
2727 ret = pBCryptGetProperty(alg, L"PaddingSchemes", (UCHAR *)&schemes, sizeof(schemes), &size, 0);
2728 ok(!ret, "got 0x%x\n", ret);
2729 ok(schemes, "schemes not set\n");
2730 ok(size == sizeof(schemes), "got %u\n", size);
2731
2732 ret = pBCryptImportKeyPair(alg, NULL, BCRYPT_PUBLIC_KEY_BLOB, &key, rsaPublicBlob, sizeof(rsaPublicBlob), 0);
2733 ok(!ret, "BCryptImportKeyPair failed: 0x%x\n", ret);
2734 pBCryptDestroyKey(key);
2735
2736 ret = pBCryptImportKeyPair(alg, NULL, BCRYPT_RSAPUBLIC_BLOB, &key, rsaPublicBlob, sizeof(rsaPublicBlob), 0);
2737 ok(!ret, "BCryptImportKeyPair failed: 0x%x\n", ret);
2738
2739 keylen = 0;
2740 ret = pBCryptGetProperty(key, BCRYPT_KEY_STRENGTH, (UCHAR *)&keylen, sizeof(keylen), &size, 0);
2741 ok(!ret, "got 0x%x\n", ret);
2742 ok(size == sizeof(keylen), "got %u\n", size);
2743 ok(keylen == 2048, "got %u\n", keylen);
2744
2746 ret = pBCryptVerifySignature(key, &pad, rsaHash, sizeof(rsaHash), rsaSignature, sizeof(rsaSignature), BCRYPT_PAD_PKCS1);
2747 ok(!ret, "BCryptVerifySignature failed: 0x%x\n", ret);
2748
2749 ret = pBCryptVerifySignature(key, NULL, rsaHash, sizeof(rsaHash), rsaSignature, sizeof(rsaSignature), BCRYPT_PAD_PKCS1);
2750 ok(ret == STATUS_INVALID_PARAMETER, "Expected STATUS_INVALID_PARAMETER, got 0x%x\n", ret);
2751
2753 ret = pBCryptVerifySignature(key, &pad, rsaHash, sizeof(rsaHash), rsaSignature, sizeof(rsaSignature), 0);
2754 ok(ret == STATUS_INVALID_PARAMETER, "Expected STATUS_INVALID_PARAMETER, got 0x%x\n", ret);
2755
2756 ret = pBCryptVerifySignature(key, NULL, rsaHash, sizeof(rsaHash), rsaSignature, sizeof(rsaSignature), 0);
2757 ok(ret == STATUS_INVALID_PARAMETER, "Expected STATUS_INVALID_PARAMETER, got 0x%x\n", ret);
2758
2760 ret = pBCryptVerifySignature(key, &pad, rsaHash, sizeof(rsaHash), rsaSignature, sizeof(rsaSignature), BCRYPT_PAD_PKCS1);
2761 ok(ret == STATUS_NOT_SUPPORTED, "Expected STATUS_NOT_SUPPORTED, got 0x%x\n", ret);
2762
2763 pad.pszAlgId = NULL;
2764 ret = pBCryptVerifySignature(key, &pad, rsaHash, sizeof(rsaHash), rsaSignature, sizeof(rsaSignature), BCRYPT_PAD_PKCS1);
2765 ok(ret == STATUS_INVALID_SIGNATURE, "Expected STATUS_INVALID_SIGNATURE, got 0x%x\n", ret);
2766
2767 ret = pBCryptDestroyKey(key);
2768 ok(!ret, "BCryptDestroyKey failed: 0x%x\n", ret);
2769
2770 /* sign/verify with export/import round-trip */
2771 ret = pBCryptGenerateKeyPair(alg, &key, 1024, 0);
2772 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2773
2774 keylen = 2048;
2775 ret = pBCryptSetProperty(key, BCRYPT_KEY_LENGTH, (UCHAR *)&keylen, 2, 0);
2776 ok(ret == STATUS_INVALID_PARAMETER, "got 0x%x\n", ret);
2777 ret = pBCryptSetProperty(key, BCRYPT_KEY_LENGTH, (UCHAR *)&keylen, sizeof(keylen), 0);
2778 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2779
2780 ret = pBCryptFinalizeKeyPair(key, 0);
2781 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2782
2783 keylen = 0;
2784 ret = pBCryptGetProperty(key, BCRYPT_KEY_STRENGTH, (UCHAR *)&keylen, sizeof(keylen), &size, 0);
2785 ok(!ret, "got 0x%x\n", ret);
2786 ok(size == sizeof(keylen), "got %u\n", size);
2787 ok(keylen == 2048, "got %u\n", keylen);
2788
2789 ret = pBCryptSetProperty(key, BCRYPT_KEY_LENGTH, (UCHAR *)&keylen, sizeof(keylen), 0);
2790 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2791
2793 memset(sig, 0, sizeof(sig));
2794 len = 0;
2795 ret = pBCryptSignHash(key, &pad, hash, 16, sig, sizeof(sig), &len, BCRYPT_PAD_PKCS1);
2796 ok(!ret, "got 0x%x\n", ret);
2797 ok(len == 256, "got %u\n", len);
2799 ret = pBCryptVerifySignature(key, &pad, hash, 16, sig, len, BCRYPT_PAD_PKCS1);
2800 ok(!ret, "BCryptVerifySignature failed: 0x%x\n", ret);
2801
2803 memset(sig, 0, sizeof(sig));
2804 len = 0;
2805 ret = pBCryptSignHash(key, &pad, hash, sizeof(hash), sig, sizeof(sig), &len, BCRYPT_PAD_PKCS1);
2806 ok(!ret, "got 0x%x\n", ret);
2807 ok(len == 256, "got %u\n", len);
2809 ret = pBCryptVerifySignature(key, &pad, hash, sizeof(hash), sig, len, BCRYPT_PAD_PKCS1);
2810 ok(!ret, "BCryptVerifySignature failed: 0x%x\n", ret);
2811
2812 pad.pszAlgId = NULL;
2813 memset(sig, 0, sizeof(sig));
2814 len = 0;
2815 ret = pBCryptSignHash(key, &pad, hash, sizeof(hash), sig, sizeof(sig), &len, BCRYPT_PAD_PKCS1);
2816 ok(!ret, "got 0x%x\n", ret);
2817 ok(len == 256, "got %u\n", len);
2818
2820 ret = pBCryptVerifySignature(key, &pad, hash, sizeof(hash), sig, len, BCRYPT_PAD_PKCS1);
2821 ok(ret == STATUS_INVALID_SIGNATURE, "BCryptVerifySignature failed: 0x%x, len %d\n", ret, len);
2822
2823 pad.pszAlgId = NULL;
2824 ret = pBCryptVerifySignature(key, &pad, hash, sizeof(hash), sig, len, BCRYPT_PAD_PKCS1);
2825 ok(!ret, "BCryptVerifySignature failed: 0x%x, len %d\n", ret, len);
2826
2828 pad_pss.cbSalt = 48;
2829 memset(sig_pss, 0, sizeof(sig_pss));
2830 len = 0;
2831 ret = pBCryptSignHash(key, &pad_pss, hash48, sizeof(hash48), sig_pss, sizeof(sig_pss), &len, BCRYPT_PAD_PSS);
2832 ok(!ret, "got 0x%x\n", ret);
2833 ok(len == 256, "got %u\n", len);
2834
2835 /* export private key */
2836 size = 0;
2837 ret = pBCryptExportKey(key, NULL, BCRYPT_RSAPRIVATE_BLOB, NULL, 0, &size, 0);
2838 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2839 ok(size, "size not set\n");
2840
2841 buf = malloc(size);
2842 ret = pBCryptExportKey(key, NULL, BCRYPT_RSAPRIVATE_BLOB, buf, size, &size, 0);
2843 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2844 rsablob = (BCRYPT_RSAKEY_BLOB *)buf;
2845 ok(rsablob->Magic == BCRYPT_RSAPRIVATE_MAGIC, "got 0x%x\n", rsablob->Magic);
2846 ok(rsablob->BitLength == 2048, "got %u\n", rsablob->BitLength);
2847 ok(rsablob->cbPublicExp == 3, "got %u\n", rsablob->cbPublicExp);
2848 ok(rsablob->cbModulus == 256, "got %u\n", rsablob->cbModulus);
2849 ok(rsablob->cbPrime1 == 128, "got %u\n", rsablob->cbPrime1);
2850 ok(rsablob->cbPrime2 == 128, "got %u\n", rsablob->cbPrime2);
2851 size2 = sizeof(*rsablob) + rsablob->cbPublicExp + rsablob->cbModulus + rsablob->cbPrime1 + rsablob->cbPrime2;
2852 ok(size == size2, "got %u expected %u\n", size2, size);
2853 free(buf);
2854
2855 size = 0;
2856 ret = pBCryptExportKey(key, NULL, BCRYPT_RSAFULLPRIVATE_BLOB, NULL, 0, &size, 0);
2857 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2858 ok(size, "size not set\n");
2859
2860 buf = malloc(size);
2861 ret = pBCryptExportKey(key, NULL, BCRYPT_RSAFULLPRIVATE_BLOB, buf, size, &size, 0);
2862 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2863 rsablob = (BCRYPT_RSAKEY_BLOB *)buf;
2864 ok(rsablob->Magic == BCRYPT_RSAFULLPRIVATE_MAGIC, "got 0x%x\n", rsablob->Magic);
2865 ok(rsablob->BitLength == 2048, "got %u\n", rsablob->BitLength);
2866 ok(rsablob->cbPublicExp == 3, "got %u\n", rsablob->cbPublicExp);
2867 ok(rsablob->cbModulus == 256, "got %u\n", rsablob->cbModulus);
2868 ok(rsablob->cbPrime1 == 128, "got %u\n", rsablob->cbPrime1);
2869 ok(rsablob->cbPrime2 == 128, "got %u\n", rsablob->cbPrime2);
2870 size2 = sizeof(*rsablob) + rsablob->cbPublicExp + rsablob->cbModulus * 2 + rsablob->cbPrime1 * 3 + rsablob->cbPrime2 * 2;
2871 ok(size == size2, "got %u expected %u\n", size2, size);
2872 free(buf);
2873
2874 /* import/export public key */
2875 size = 0;
2876 ret = pBCryptExportKey(key, NULL, BCRYPT_RSAPUBLIC_BLOB, NULL, 0, &size, 0);
2877 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2878 ok(size, "size not set\n");
2879
2880 buf = malloc(size);
2881 ret = pBCryptExportKey(key, NULL, BCRYPT_RSAPUBLIC_BLOB, buf, size, &size, 0);
2882 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2883 rsablob = (BCRYPT_RSAKEY_BLOB *)buf;
2884 ok(rsablob->Magic == BCRYPT_RSAPUBLIC_MAGIC, "got 0x%x\n", rsablob->Magic);
2885 ok(rsablob->BitLength == 2048, "got %u\n", rsablob->BitLength);
2886 ok(rsablob->cbPublicExp == 3, "got %u\n", rsablob->cbPublicExp);
2887 ok(rsablob->cbModulus == 256, "got %u\n", rsablob->cbModulus);
2888 ok(!rsablob->cbPrime1, "got %u\n", rsablob->cbPrime1);
2889 ok(!rsablob->cbPrime2, "got %u\n", rsablob->cbPrime2);
2890 ok(size == sizeof(*rsablob) + rsablob->cbPublicExp + rsablob->cbModulus, "got %u\n", size);
2891 ret = pBCryptDestroyKey(key);
2892 ok(!ret, "got 0x%x\n", ret);
2893
2896 ok(ret == NTE_BAD_DATA, "got 0x%x\n", ret);
2897
2898 ret = pBCryptImportKeyPair(alg, NULL, BCRYPT_RSAPUBLIC_BLOB, &key, buf, size, 0);
2899 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2900 free(buf);
2901
2902 ret = pBCryptVerifySignature(key, &pad, hash, sizeof(hash), sig, sizeof(sig), BCRYPT_PAD_PKCS1);
2903 ok(!ret, "got 0x%x\n", ret);
2904 ret = pBCryptVerifySignature(key, &pad_pss, hash48, sizeof(hash48), sig_pss, sizeof(sig_pss), BCRYPT_PAD_PSS);
2905 ok(!ret, "got 0x%x\n", ret);
2906 ret = pBCryptDestroyKey(key);
2907 ok(!ret, "got 0x%x\n", ret);
2908
2909 /* import/export private key */
2910 ret = pBCryptImportKeyPair(alg, NULL, BCRYPT_RSAPRIVATE_BLOB, &key, rsaPrivateBlob, sizeof(rsaPrivateBlob), 0);
2911 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2912
2913 ret = pBCryptFinalizeKeyPair(key, 0);
2914 ok(ret == STATUS_INVALID_HANDLE, "got 0x%x\n", ret);
2915
2916 size = 0;
2917 buf = malloc(sizeof(rsaPrivateBlob));
2918 ret = pBCryptExportKey(key, NULL, BCRYPT_RSAPRIVATE_BLOB, buf, sizeof(rsaPrivateBlob), &size, 0);
2919 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2920 ok(size == sizeof(rsaPrivateBlob), "got %u\n", size);
2921 ok(!memcmp(buf, rsaPrivateBlob, size), "wrong data\n");
2922 free(buf);
2923 pBCryptDestroyKey(key);
2924
2925 /* import/export full private key */
2926 ret = pBCryptImportKeyPair(alg, NULL, BCRYPT_RSAFULLPRIVATE_BLOB, &key, rsaFullPrivateBlob, sizeof(rsaFullPrivateBlob), 0);
2927 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2928
2929 size = 0;
2930 buf = malloc(sizeof(rsaFullPrivateBlob));
2931 ret = pBCryptExportKey(key, NULL, BCRYPT_RSAFULLPRIVATE_BLOB, buf, sizeof(rsaFullPrivateBlob), &size, 0);
2932 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2933 ok(size == sizeof(rsaFullPrivateBlob), "got %u\n", size);
2934 ok(!memcmp(buf, rsaFullPrivateBlob, size), "wrong data\n");
2935 free(buf);
2936 pBCryptDestroyKey(key);
2937
2938 ret = pBCryptCloseAlgorithmProvider(alg, 0);
2939 ok(!ret, "got 0x%x\n", ret);
2940}
static UCHAR rsaFullPrivateBlob[]
Definition: bcrypt.c:2430
static UCHAR rsaPrivateBlob[]
Definition: bcrypt.c:2416
static UCHAR rsaPublicBlobWithInvalidPublicExpSize[]
Definition: bcrypt.c:2504
static UCHAR rsaPublicBlob[]
Definition: bcrypt.c:2368
static UCHAR rsaSignature[]
Definition: bcrypt.c:2396
static UCHAR rsaHash[]
Definition: bcrypt.c:2390
#define BCRYPT_RSAFULLPRIVATE_MAGIC
Definition: bcrypt.h:205
#define BCRYPT_RSAPRIVATE_MAGIC
Definition: bcrypt.h:204
#define BCRYPT_PAD_PSS
Definition: bcrypt.h:238
#define BCRYPT_RSAPRIVATE_BLOB
Definition: bcrypt.h:68
#define BCRYPT_RSAPUBLIC_MAGIC
Definition: bcrypt.h:203
#define BCRYPT_SHA384_ALGORITHM
Definition: bcrypt.h:106
#define BCRYPT_RSAFULLPRIVATE_BLOB
Definition: bcrypt.h:69
#define NTE_BAD_DATA
Definition: winerror.h:4252

Referenced by START_TEST().

◆ test_rsa_encrypt()

static void test_rsa_encrypt ( void  )
static

Definition at line 2529 of file bcrypt.c.

2530{
2531 UCHAR input[] = "Hello World!", input_no_padding[64] = { 0 }, encrypted[64], decrypted[64];
2533 BCRYPT_KEY_HANDLE key, key2;
2534 NTSTATUS ret;
2535 DWORD encrypted_size, decrypted_size;
2536 UCHAR *encrypted_a = NULL, *encrypted_b = NULL;
2537 BCRYPT_OAEP_PADDING_INFO oaep_pad;
2538
2540 oaep_pad.pbLabel = (UCHAR *)"test";
2541 oaep_pad.cbLabel = 5;
2542
2543 ret = pBCryptOpenAlgorithmProvider(&rsa, BCRYPT_RSA_ALGORITHM, NULL, 0);
2544 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2545 ret = pBCryptGenerateKeyPair(rsa, &key, 512, 0);
2546 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2547
2548 /* Not finalized key */
2549 ret = pBCryptEncrypt(key, input, sizeof(input), NULL, NULL, 0, NULL, 0, &encrypted_size, 0);
2550 ok(ret == STATUS_INVALID_HANDLE, "got 0x%x\n", ret);
2551 pBCryptDestroyKey(key);
2552
2553 /* Import a different public key first to make sure a public key from private key improted next
2554 * overrides it. */
2555 ret = pBCryptImportKeyPair(rsa, NULL, BCRYPT_RSAPUBLIC_BLOB, &key, rsaPublicBlob, sizeof(rsaPublicBlob), 0);
2556 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2557
2558 ret = pBCryptImportKeyPair(rsa, NULL, BCRYPT_RSAPRIVATE_BLOB, &key, rsaPrivateBlob, sizeof(rsaPrivateBlob), 0);
2559 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2560
2561 /* No padding */
2562 todo_wine {
2563 memset(input_no_padding, 0, sizeof(input_no_padding));
2564 strcpy((char *)input_no_padding, "Hello World");
2565 encrypted_size = 0;
2566 ret = pBCryptEncrypt(key, input_no_padding, sizeof(input_no_padding), NULL, NULL, 0, NULL, 0, &encrypted_size, BCRYPT_PAD_NONE);
2567 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2568 ok(encrypted_size == 64, "got size of %d\n", encrypted_size);
2569
2570 encrypted_a = malloc(encrypted_size);
2571 memset(encrypted_a, 0, encrypted_size);
2572 encrypted_b = malloc(encrypted_size);
2573 memset(encrypted_b, 0xff, encrypted_size);
2574
2575 ret = pBCryptEncrypt(key, input, sizeof(input), NULL, NULL, 0, encrypted_a, encrypted_size, &encrypted_size, BCRYPT_PAD_NONE);
2576 ok(ret == STATUS_INVALID_PARAMETER, "got 0x%x\n", ret);
2577
2578 ret = pBCryptEncrypt(key, input_no_padding, sizeof(input_no_padding), NULL, NULL, 0, encrypted_a, 12, &encrypted_size, BCRYPT_PAD_NONE);
2579 ok(ret == STATUS_BUFFER_TOO_SMALL, "got 0x%x\n", ret);
2580 ok(encrypted_size == 64, "got size of %d\n", encrypted_size);
2581
2582 ret = pBCryptEncrypt(key, input_no_padding, sizeof(input_no_padding), NULL, NULL, 0, encrypted_a, encrypted_size, &encrypted_size, BCRYPT_PAD_NONE);
2583 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2584 ok(encrypted_size == 64, "got size of %d\n", encrypted_size);
2585
2586 ret = pBCryptEncrypt(key, input_no_padding, sizeof(input_no_padding), NULL, NULL, 0, encrypted_b, encrypted_size, &encrypted_size, BCRYPT_PAD_NONE);
2587 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2588 }
2589 ok(!memcmp(encrypted_a, encrypted_b, encrypted_size), "Both outputs should be the same\n");
2590 ok(!memcmp(encrypted_b, rsa_encrypted_no_padding, encrypted_size), "Data mismatch.\n");
2591
2592 todo_wine {
2593 decrypted_size = 0;
2594 ret = pBCryptDecrypt(key, encrypted_a, encrypted_size, NULL, NULL, 0, NULL, 0, &decrypted_size, BCRYPT_PAD_NONE);
2595 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2596 ok(decrypted_size == sizeof(input_no_padding), "got %u\n", decrypted_size);
2597
2598 ret = pBCryptDecrypt(key, encrypted_a, encrypted_size, NULL, NULL, 0, decrypted, decrypted_size, &decrypted_size, BCRYPT_PAD_NONE);
2599 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2600 ok(decrypted_size == sizeof(input_no_padding), "got %u\n", decrypted_size);
2601 ok(!memcmp(decrypted, input_no_padding, sizeof(input_no_padding)), "unexpected output\n");
2602 }
2603
2604 /* PKCS1 Padding */
2605 encrypted_size = 0;
2606 ret = pBCryptEncrypt(key, input, sizeof(input), NULL, NULL, 0, NULL, 0, &encrypted_size, BCRYPT_PAD_PKCS1);
2607 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2608 ok(encrypted_size == 64, "got size of %d\n", encrypted_size);
2609
2610 encrypted_a = realloc(encrypted_a, encrypted_size);
2611 memset(encrypted_a, 0, encrypted_size);
2612 encrypted_b = realloc(encrypted_b, encrypted_size);
2613 memset(encrypted_b, 0, encrypted_size);
2614
2615 ret = pBCryptEncrypt(key, input, sizeof(input), NULL, NULL, 0, encrypted_a, encrypted_size, &encrypted_size, BCRYPT_PAD_PKCS1);
2616 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2617 ok(encrypted_size == 64, "got size of %d\n", encrypted_size);
2618
2619 ret = pBCryptEncrypt(key, input, sizeof(input), NULL, NULL, 0, encrypted_b, encrypted_size, &encrypted_size, BCRYPT_PAD_PKCS1);
2620 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2621 ok(encrypted_size == 64, "got size of %d\n", encrypted_size);
2622 ok(memcmp(encrypted_a, encrypted_b, encrypted_size), "Both outputs are the same\n");
2623
2624 decrypted_size = 0;
2625 ret = pBCryptDecrypt(key, encrypted_a, encrypted_size, NULL, NULL, 0, NULL, 0, &decrypted_size, BCRYPT_PAD_PKCS1);
2626 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2627 ok(decrypted_size == sizeof(input), "got size of %d\n", decrypted_size);
2628
2629 ret = pBCryptDecrypt(key, encrypted_a, encrypted_size, NULL, NULL, 0, decrypted, decrypted_size, &decrypted_size, BCRYPT_PAD_PKCS1);
2630 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2631 ok(decrypted_size == sizeof(input), "got size of %d\n", decrypted_size);
2632 ok(!memcmp(decrypted, input, sizeof(input)), "unexpected output\n");
2633
2634 ret = pBCryptImportKeyPair(rsa, NULL, LEGACY_RSAPRIVATE_BLOB, &key2, (UCHAR *)&rsaLegacyPrivateBlob,
2635 sizeof(rsaLegacyPrivateBlob), 0);
2636 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2637
2638 ret = pBCryptEncrypt(key2, input, sizeof(input), NULL, NULL, 0, encrypted, sizeof(encrypted),
2639 &encrypted_size, BCRYPT_PAD_PKCS1);
2640 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2641 ok(encrypted_size == 64, "got size of %d\n", encrypted_size);
2642
2643 memset(decrypted, 0, sizeof(decrypted));
2644 ret = pBCryptDecrypt(key, encrypted, sizeof(encrypted), NULL, NULL, 0, decrypted, sizeof(decrypted),
2645 &decrypted_size, BCRYPT_PAD_PKCS1);
2646 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2647 ok(decrypted_size == sizeof(input), "got size of %d\n", decrypted_size);
2648 ok(!memcmp(decrypted, input, sizeof(input)), "unexpected output\n");
2649 pBCryptDestroyKey(key2);
2650 pBCryptDestroyKey(key);
2651
2652 /* OAEP Padding */
2653 ret = pBCryptGenerateKeyPair(rsa, &key, 640 /* minimum size for sha256 hash */, 0);
2654 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2655
2656 ret = pBCryptFinalizeKeyPair(key, 0);
2657 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2658
2659 todo_wine {
2660 encrypted_size = 0;
2661 ret = pBCryptEncrypt(key, input, sizeof(input), &oaep_pad, NULL, 0, NULL, 0, &encrypted_size, BCRYPT_PAD_OAEP);
2662 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2663 ok(encrypted_size == 80, "got size of %d\n", encrypted_size);
2664
2665 encrypted_a = realloc(encrypted_a, encrypted_size);
2666 memset(encrypted_a, 0, encrypted_size);
2667 encrypted_b = realloc(encrypted_b, encrypted_size);
2668 memset(encrypted_b, 0, encrypted_size);
2669
2670 ret = pBCryptEncrypt(key, input, sizeof(input), &oaep_pad, NULL, 0, encrypted_a, encrypted_size, &encrypted_size, BCRYPT_PAD_OAEP);
2671 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2672 ok(encrypted_size == 80, "got size of %d\n", encrypted_size);
2673
2674 ret = pBCryptEncrypt(key, input, sizeof(input), &oaep_pad, NULL, 0, encrypted_b, encrypted_size, &encrypted_size, BCRYPT_PAD_OAEP);
2675 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2676 ok(encrypted_size == 80, "got size of %d\n", encrypted_size);
2677 ok(memcmp(encrypted_a, encrypted_b, encrypted_size), "Both outputs are the same\n");
2678
2679 decrypted_size = 0;
2680 memset(decrypted, 0, sizeof(decrypted));
2681 ret = pBCryptDecrypt(key, encrypted_a, encrypted_size, &oaep_pad, NULL, 0, NULL, 0, &decrypted_size, BCRYPT_PAD_OAEP);
2682 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2683 ok(decrypted_size == sizeof(input), "got %u\n", decrypted_size);
2684
2685 ret = pBCryptDecrypt(key, encrypted_a, encrypted_size, &oaep_pad, NULL, 0, decrypted, decrypted_size, &decrypted_size, BCRYPT_PAD_OAEP);
2686 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2687 ok(decrypted_size == sizeof(input), "got %u\n", decrypted_size);
2688 ok(!memcmp(decrypted, input, sizeof(input)), "unexpected output\n");
2689 }
2690
2691 free(encrypted_a);
2692 free(encrypted_b);
2693
2694 pBCryptDestroyKey(key);
2695
2696 if (pBCryptHash)
2697 {
2698 ret = pBCryptGenerateKeyPair(BCRYPT_RSA_ALG_HANDLE, &key, 512, 0);
2699 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
2700 pBCryptDestroyKey(key);
2701 }
2702}
static struct @1815 rsaLegacyPrivateBlob
static const UCHAR rsa_encrypted_no_padding[]
Definition: bcrypt.c:2521
#define LEGACY_RSAPRIVATE_BLOB
Definition: bcrypt.h:81
#define BCRYPT_RSA_ALG_HANDLE
Definition: bcrypt.h:391
#define BCRYPT_SHA256_ALGORITHM
Definition: bcrypt.h:105
#define BCRYPT_PAD_OAEP
Definition: bcrypt.h:237
#define BCRYPT_PAD_NONE
Definition: bcrypt.h:235
#define realloc
Definition: debug_ros.c:6
strcpy
Definition: string.h:131

Referenced by START_TEST().

◆ test_RSA_SIGN()

static void test_RSA_SIGN ( void  )
static

Definition at line 2942 of file bcrypt.c.

2943{
2945 BCRYPT_ALG_HANDLE alg = NULL;
2947 BCRYPT_RSAKEY_BLOB *rsablob;
2948 NTSTATUS ret;
2949 ULONG size, size2;
2950 BYTE *buf, buf2[sizeof(BCRYPT_RSAKEY_BLOB) + sizeof(rsaPublicBlob)];
2951
2952 ret = pBCryptOpenAlgorithmProvider(&alg, BCRYPT_RSA_SIGN_ALGORITHM, NULL, 0);
2953 ok(!ret, "got 0x%x\n", ret);
2954
2955 ret = pBCryptImportKeyPair(alg, NULL, BCRYPT_RSAPUBLIC_BLOB, &key, rsaPublicBlob, sizeof(rsaPublicBlob), 0);
2956 ok(!ret, "BCryptImportKeyPair failed: 0x%x\n", ret);
2957
2958 memset(buf2, 0xcc, sizeof(buf2));
2959 ret = pBCryptExportKey(key, NULL, BCRYPT_RSAPUBLIC_BLOB, buf2, sizeof(buf2), &size, 0);
2960 ok(!ret, "got 0x%x\n", ret);
2961 rsablob = (BCRYPT_RSAKEY_BLOB *)buf2;
2962 ok(rsablob->Magic == BCRYPT_RSAPUBLIC_MAGIC, "got 0x%x\n", rsablob->Magic);
2963 ok(rsablob->BitLength == 2048, "got %u\n", rsablob->BitLength);
2964 ok(rsablob->cbPublicExp == 3, "got %u\n", rsablob->cbPublicExp);
2965 ok(rsablob->cbModulus == 256, "got %u\n", rsablob->cbModulus);
2966 ok(rsablob->cbPrime1 == 0, "got %u\n", rsablob->cbPrime1);
2967 ok(rsablob->cbPrime2 == 0, "got %u\n", rsablob->cbPrime2);
2968 size2 = sizeof(*rsablob) + rsablob->cbPublicExp + rsablob->cbModulus + rsablob->cbPrime1 + rsablob->cbPrime2;
2969 ok(size == size2, "got %u expected %u\n", size2, size);
2970
2971 ret = pBCryptExportKey(key, NULL, BCRYPT_RSAPRIVATE_BLOB, buf2, sizeof(buf2), &size, 0);
2972 ok(ret == STATUS_INVALID_PARAMETER, "got 0x%x\n", ret);
2973
2974 pad.pszAlgId = NULL;
2975 ret = pBCryptVerifySignature(key, &pad, rsaHash, sizeof(rsaHash), rsaSignature, sizeof(rsaSignature), BCRYPT_PAD_PKCS1);
2976 ok(ret == STATUS_INVALID_SIGNATURE, "BCryptVerifySignature failed: 0x%x\n", ret);
2977
2979 ret = pBCryptVerifySignature(key, &pad, rsaHash, sizeof(rsaHash), rsaSignature, sizeof(rsaSignature), BCRYPT_PAD_PKCS1);
2980 ok(!ret, "BCryptVerifySignature failed: 0x%x\n", ret);
2981
2982 ret = pBCryptVerifySignature(key, NULL, rsaHash, sizeof(rsaHash), rsaSignature, sizeof(rsaSignature), BCRYPT_PAD_PKCS1);
2983 ok(ret == STATUS_INVALID_PARAMETER, "Expected STATUS_INVALID_PARAMETER, got 0x%x\n", ret);
2984
2986 ret = pBCryptVerifySignature(key, &pad, rsaHash, sizeof(rsaHash), rsaSignature, sizeof(rsaSignature), 0);
2987 ok(ret == STATUS_INVALID_PARAMETER, "Expected STATUS_INVALID_PARAMETER, got 0x%x\n", ret);
2988
2989 ret = pBCryptVerifySignature(key, NULL, rsaHash, sizeof(rsaHash), rsaSignature, sizeof(rsaSignature), 0);
2990 ok(ret == STATUS_INVALID_PARAMETER, "Expected STATUS_INVALID_PARAMETER, got 0x%x\n", ret);
2991
2993 ret = pBCryptVerifySignature(key, &pad, rsaHash, sizeof(rsaHash), rsaSignature, sizeof(rsaSignature), BCRYPT_PAD_PKCS1);
2994 ok(ret == STATUS_NOT_SUPPORTED, "Expected STATUS_NOT_SUPPORTED, got 0x%x\n", ret);
2995
2996 pad.pszAlgId = NULL;
2997 ret = pBCryptVerifySignature(key, &pad, rsaHash, sizeof(rsaHash), rsaSignature, sizeof(rsaSignature), BCRYPT_PAD_PKCS1);
2998 ok(ret == STATUS_INVALID_SIGNATURE, "Expected STATUS_INVALID_SIGNATURE, got 0x%x\n", ret);
2999
3000 ret = pBCryptDestroyKey(key);
3001 ok(!ret, "BCryptDestroyKey failed: 0x%x\n", ret);
3002
3003 /* export private key */
3004 ret = pBCryptGenerateKeyPair(alg, &key, 512, 0);
3005 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
3006
3007 ret = pBCryptFinalizeKeyPair(key, 0);
3008 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
3009
3010 size = 0;
3011 ret = pBCryptExportKey(key, NULL, BCRYPT_RSAPRIVATE_BLOB, NULL, 0, &size, 0);
3012 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
3013 ok(size, "size not set\n");
3014
3015 buf = malloc(size);
3016 ret = pBCryptExportKey(key, NULL, BCRYPT_RSAPRIVATE_BLOB, buf, size, &size, 0);
3017 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
3018 rsablob = (BCRYPT_RSAKEY_BLOB *)buf;
3019 ok(rsablob->Magic == BCRYPT_RSAPRIVATE_MAGIC, "got 0x%x\n", rsablob->Magic);
3020 ok(rsablob->BitLength == 512, "got %u\n", rsablob->BitLength);
3021 ok(rsablob->cbPublicExp == 3, "got %u\n", rsablob->cbPublicExp);
3022 ok(rsablob->cbModulus == 64, "got %u\n", rsablob->cbModulus);
3023 ok(rsablob->cbPrime1 == 32, "got %u\n", rsablob->cbPrime1);
3024 ok(rsablob->cbPrime2 == 32, "got %u\n", rsablob->cbPrime2);
3025 size2 = sizeof(*rsablob) + rsablob->cbPublicExp + rsablob->cbModulus + rsablob->cbPrime1 + rsablob->cbPrime2;
3026 ok(size == size2, "got %u expected %u\n", size2, size);
3027 free(buf);
3028
3029 size = 0;
3030 ret = pBCryptExportKey(key, NULL, BCRYPT_RSAFULLPRIVATE_BLOB, NULL, 0, &size, 0);
3031 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
3032 ok(size, "size not set\n");
3033
3034 buf = malloc(size);
3035 ret = pBCryptExportKey(key, NULL, BCRYPT_RSAFULLPRIVATE_BLOB, buf, size, &size, 0);
3036 ok(ret == STATUS_SUCCESS, "got 0x%x\n", ret);
3037 rsablob = (BCRYPT_RSAKEY_BLOB *)buf;
3038 ok(rsablob->Magic == BCRYPT_RSAFULLPRIVATE_MAGIC, "got 0x%x\n", rsablob->Magic);
3039 ok(rsablob->BitLength == 512, "got %u\n", rsablob->BitLength);
3040 ok(rsablob->cbPublicExp == 3, "got %u\n", rsablob->cbPublicExp);
3041 ok(rsablob->cbModulus == 64, "got %u\n", rsablob->cbModulus);
3042 ok(rsablob->cbPrime1 == 32, "got %u\n", rsablob->cbPrime1);
3043 ok(rsablob->cbPrime2 == 32, "got %u\n", rsablob->cbPrime2);
3044 size2 = sizeof(*rsablob) + rsablob->cbPublicExp + rsablob->cbModulus * 2 + rsablob->cbPrime1 * 3 + rsablob->cbPrime2 * 2;
3045 ok(size == size2, "got %u expected %u\n", size2, size);
3046 free(buf);
3047 pBCryptDestroyKey(key);
3048
3049 ret = pBCryptCloseAlgorithmProvider(alg, 0);
3050 ok(!ret, "BCryptCloseAlgorithmProvider failed: 0x%x\n", ret);
3051}
struct _BCRYPT_RSAKEY_BLOB BCRYPT_RSAKEY_BLOB
#define BCRYPT_RSA_SIGN_ALGORITHM
Definition: bcrypt.h:103

Referenced by START_TEST().

◆ test_SecretAgreement()

static void test_SecretAgreement ( void  )
static

Definition at line 3976 of file bcrypt.c.

3977{
3979 {
3980 {
3984 }
3985 };
3987 {
3991 };
3992
3993 static const ULONG dh_private_key[] =
3994 {
3995 0xc4caf69c, 0x57b4db27, 0x36f7135f, 0x5ccba686, 0xc37b8819, 0x1d35c9b2, 0xbb07a1cf, 0x0c5d1c1b,
3996 0xc79acb10, 0x31dfdabb, 0x702e02b9, 0x1efab345, 0x262a8074, 0x5edf7698, 0x9b9dc630, 0x13c34b93,
3997 0xacbc928b, 0xb79eed8c, 0x7413dce9, 0xa5521280, 0x88d8e695, 0xa310269f, 0xca7c5719, 0xcd0c775b,
3998 0x9a6e2cf2, 0x9e235c51, 0xf49db62d, 0x28e72424, 0x4a44da5a, 0x3d98268d, 0x8e4d2be3, 0x254e44e6,
3999
4000 0x18a67e55, 0x572e13a1, 0x46f81ca8, 0xc331c9b9, 0xf8fe3dd4, 0x8a889e5a, 0x6c0505fd, 0xbd97a121,
4001 0xed2dbd67, 0xf39efa8e, 0x36f9c287, 0xf6bbfa6c, 0x461e42ad, 0x17dc170e, 0xc002dc2e, 0x4813d9a4,
4002 0x0b6fabb8, 0x6a9e1860, 0xa8a8cbd9, 0xb7ed6b5d, 0xabb34d23, 0xf2fbe1fd, 0x8670df1e, 0xba7fa4e6,
4003 0xf7039712, 0x94448f30, 0xe10c812e, 0x3e311976, 0xcfdd72c4, 0xbdbea98f, 0xc9a540d6, 0x89646d57,
4004
4005 0x7ab63b33, 0x03a1e9b6, 0x947f7a9b, 0x5ae59eeb, 0x1d12eb05, 0x3f425d92, 0xe028c6ba, 0xbf90ddc9,
4006 0xb554f55a, 0x7aeb88b6, 0x4a443a5f, 0xbab35111, 0x82c78a0c, 0x298dd482, 0x02937cb1, 0xc94cdc2e,
4007 0x59b010eb, 0x3bbc0a2b, 0xd845fee0, 0x04c1d0db, 0x0c8c9424, 0x1cafd4b2, 0x9aa7aed9, 0x6a478486,
4008 0xa8841fd7, 0xbfeff40a, 0x8fd7bcc5, 0x3bb28977, 0x2b9a7955, 0xa55cd2e4, 0x1b6ad657, 0x067cdf21,
4009
4010 0x06f36920, 0x63280e1b, 0xf17d930f, 0xa06e74a8, 0x463b3a6f, 0x2a464507, 0x93f8a982, 0x8f620a7d,
4011 0xeda32d11, 0x9706a6d4, 0x33dce588, 0x75a1c446, 0x048ab567, 0xd735aafa, 0x806f7c1c, 0xdcb9651a,
4012 0x26acf3b4, 0x45f91cc9, 0x2a0de6fc, 0xf3c03d0c, 0xf5aee0aa, 0x3eeaaf36, 0x18ccee61, 0x83faa783,
4013 0x4b2b5250, 0xf4ccea22, 0x5ac0714b, 0x3f0b2bc6, 0x481b13ce, 0x12040ea7, 0x66e0bbed, 0x158e1a67,
4014 };
4015 static const ULONG dh_private_key2[] =
4016 {
4017 0xffffffff, 0xffffffff, 0xa2da0fc9, 0x34c26821, 0x8b62c6c4, 0xd11cdc80, 0x084e0229, 0x74cc678a,
4018 0xa6be0b02, 0x229b133b, 0x79084a51, 0xdd04348e, 0xb31995ef, 0x1b433acd, 0x6d0a2b30, 0x37145ff2,
4019 0x6d35e14f, 0x45c2516d, 0x76b585e4, 0xc67e5e62, 0xe9424cf4, 0x6bed37a6, 0xb65cff0b, 0xedb706f4,
4020 0xfb6b38ee, 0xa59f895a, 0x11249fae, 0xe61f4b7c, 0x51662849, 0x8153e6ec, 0xffffffff, 0xffffffff,
4021
4022 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
4023 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
4024 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
4025 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x02000000,
4026
4027 0xa0c3c734, 0xc130c92d, 0x5265abf8, 0xff409f17, 0xbcdce187, 0xff64dae3, 0x170560aa, 0xb2423ed8,
4028 0x9ee5a8b9, 0x92548030, 0x02bba1f9, 0x823e39a4, 0x69c438f5, 0xf91016ac, 0x89bfd166, 0x7f996446,
4029 0x86224203, 0x15bf689c, 0x619354a4, 0x0c1d3a1f, 0x11bcf3d2, 0x58aae029, 0x41c69824, 0x3fafc179,
4030 0xa742747c, 0x60658c7a, 0xd3b0bde4, 0x78d3f08b, 0x6cefa061, 0x33752536, 0xe84d4901, 0x48cd73f4,
4031
4032 0x8d449700, 0x1f95120e, 0xceb31745, 0x3663177b, 0xbd9bb2d5, 0x9c23c0d9, 0x814d34f8, 0xbc54edb0,
4033 0xb874659a, 0x3bac8a30, 0xa1f3dd46, 0x1705c900, 0xbc46fefe, 0x7d13875b, 0x3064351a, 0x4bd89a1c,
4034 0x9e938761, 0x931949db, 0x34490719, 0x84fb08ca, 0xa9dd355a, 0x5b3f5061, 0x2ac96663, 0xc594429e,
4035 0xbe58395d, 0x2f7d872a, 0x303d37b3, 0xa3a9b606, 0x735a6732, 0xa095bd95, 0x3d55a7c3, 0x00e54635,
4036 };
4037 static const ULONG dh_peer_key[] =
4038 {
4039 0xffffffff, 0xffffffff, 0xa2da0fc9, 0x34c26821, 0x8b62c6c4, 0xd11cdc80, 0x084e0229, 0x74cc678a,
4040 0xa6be0b02, 0x229b133b, 0x79084a51, 0xdd04348e, 0xb31995ef, 0x1b433acd, 0x6d0a2b30, 0x37145ff2,
4041 0x6d35e14f, 0x45c2516d, 0x76b585e4, 0xc67e5e62, 0xe9424cf4, 0x6bed37a6, 0xb65cff0b, 0xedb706f4,
4042 0xfb6b38ee, 0xa59f895a, 0x11249fae, 0xe61f4b7c, 0x51662849, 0x8153e6ec, 0xffffffff, 0xffffffff,
4043
4044 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
4045 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
4046 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
4047 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x02000000,
4048
4049 0x3bf7404b, 0x6284fffe, 0x97c0d565, 0xd830c658, 0xcc21bf39, 0xcae45bb6, 0x019df7df, 0xbf4cd293,
4050 0x6bf1989d, 0x78a81f52, 0xa4ed861c, 0x6bacf493, 0xa3e700d1, 0xd06cc206, 0x411b9727, 0x01e9c9ab,
4051 0x9b7e6efa, 0xf46bb25d, 0xd1027242, 0x6130787c, 0xa7b87d8b, 0xfee41492, 0x50db6213, 0x321199b6,
4052 0x7dace53a, 0xe8b1ec51, 0x2181b113, 0x3b33e3c0, 0x5b3a2d67, 0xbd34f0c1, 0x7037c542, 0x4a8d5540,
4053 };
4054 static const ULONG dh_shared_secret_raw[] =
4055 {
4056 0x375d89b5, 0x35a9c270, 0xfbc5ba82, 0x09eb3069, 0xd50965b0, 0xace510f7, 0x981e8731, 0x80a76115,
4057 0xf386d348, 0xca17b8df, 0x0b0e84ec, 0xf81f756e, 0x5030fa20, 0x03113b71, 0x97b7e879, 0x899b5fae,
4058 0xe6913299, 0x09270076, 0x39bc813a, 0xde3ef070, 0x65ad5b3a, 0x2b7c4ba4, 0x86c98ef9, 0x3236feaf,
4059 0x3e0253f7, 0x0489d2dd, 0x97669a3d, 0x50242fca, 0x5d4aecb1, 0xcf2d805f, 0x2258afff, 0x750e92cd,
4060 };
4061 static const ULONG dh_shared_secret_raw2[] =
4062 {
4063 0x0815f37d, 0x19ee74ab, 0x9f63f123, 0xe1b3f10c, 0xbcc9be83, 0xaddf5b9d, 0x28174e72, 0xf8a33825,
4064 0xfc74e47d, 0x2c950888, 0xf5b776d9, 0xfc712fef, 0x5b213b32, 0x489a9829, 0xfc0a4d1d, 0x6e641d3b,
4065 0x3bb2ff57, 0x63500318, 0x081ee54f, 0xf33a2805, 0xb3759e98, 0xa9a64afe, 0x964b8897, 0x04691bbc,
4066 0x80f4aae1, 0x617405ee, 0xab71724d, 0x6c10c214, 0x6f60b96f, 0xdc777b0b, 0x22f40d4f, 0x8a1c4eb5,
4067 };
4068 static const ULONG dh_shared_secret_sha1[] =
4069 {
4070 0x0babba9c, 0x0bdeacbd, 0x04e36574, 0xdd504dcd, 0x0cd88db0,
4071 };
4072 static const ULONG dh_shared_secret_sha256[] =
4073 {
4074 0x3213db5b, 0x8cc8250b, 0xc829eaab, 0x00933709, 0x68160aa9, 0xfb9f1e20, 0xf92368e6, 0x2b8e18eb,
4075 };
4076 static const ULONG length = 1024;
4077 BCRYPT_DH_PARAMETER_HEADER *dh_header;
4078 BCRYPT_DH_KEY_BLOB *dh_key_blob;
4081 BCRYPT_KEY_HANDLE key, key2;
4082 UCHAR buffer[2048];
4084 ULONG size, i;
4085
4086 status = pBCryptOpenAlgorithmProvider(&alg, BCRYPT_ECDH_P256_ALGORITHM, NULL, 0);
4087 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
4088
4089 key = NULL;
4090 status = pBCryptGenerateKeyPair(alg, &key, 256, 0);
4091 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
4092 ok(key != NULL, "key not set\n");
4093
4094 status = pBCryptFinalizeKeyPair(key, 0);
4095 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
4096
4097 status = pBCryptSecretAgreement(NULL, key, &secret, 0);
4098 ok(status == STATUS_INVALID_HANDLE, "got 0x%x\n", status);
4099
4100 status = pBCryptSecretAgreement(key, NULL, &secret, 0);
4101 ok(status == STATUS_INVALID_HANDLE, "got 0x%x\n", status);
4102
4103 status = pBCryptSecretAgreement(key, key, NULL, 0);
4104 ok(status == STATUS_INVALID_PARAMETER, "got 0x%x\n", status);
4105
4106 status = pBCryptSecretAgreement(key, key, &secret, 0);
4107 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
4108
4109 status = pBCryptDeriveKey(NULL, L"HASH", NULL, NULL, 0, &size, 0);
4110 ok(status == STATUS_INVALID_HANDLE, "got 0x%x\n", status);
4111
4112 status = pBCryptDeriveKey(key, L"HASH", NULL, NULL, 0, &size, 0);
4113 ok(status == STATUS_INVALID_HANDLE, "got 0x%x\n", status);
4114
4115 status = pBCryptDeriveKey(secret, NULL, NULL, NULL, 0, &size, 0);
4116 ok(status == STATUS_INVALID_PARAMETER, "got 0x%x\n", status);
4117
4118 status = pBCryptDeriveKey(secret, L"HASH", NULL, NULL, 0, &size, 0);
4119 todo_wine
4120 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
4121
4122 status = pBCryptDestroyHash(secret);
4123 ok(status == STATUS_INVALID_PARAMETER, "got 0x%x\n", status);
4124
4125 status = pBCryptDestroyKey(secret);
4126 ok(status == STATUS_INVALID_HANDLE, "got 0x%x\n", status);
4127
4128 status = pBCryptDestroySecret(NULL);
4129 ok(status == STATUS_INVALID_HANDLE, "got 0x%x\n", status);
4130
4131 status = pBCryptDestroySecret(alg);
4132 ok(status == STATUS_INVALID_HANDLE, "got 0x%x\n", status);
4133
4134 status = pBCryptDestroySecret(secret);
4135 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
4136
4137 status = pBCryptDestroyKey(key);
4138 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
4139
4140 status = pBCryptCloseAlgorithmProvider(alg, 0);
4141 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
4142
4143 /* DH */
4144 status = pBCryptOpenAlgorithmProvider(&alg, BCRYPT_DH_ALGORITHM, NULL, 0);
4145 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
4146
4147 key = NULL;
4148 status = pBCryptGenerateKeyPair(alg, &key, 1024, 0);
4149 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
4150 ok(key != NULL, "key not set\n");
4151
4152 status = pBCryptFinalizeKeyPair(key, 0);
4154 {
4155 win_skip("broken DH detected\n");
4156 pBCryptCloseAlgorithmProvider(alg, 0);
4157 return;
4158 }
4159 todo_wine ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
4160
4161 status = pBCryptSecretAgreement(key, key, &secret, 0);
4162 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
4163
4164 status = pBCryptDestroyKey(key);
4165 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
4166
4167 status = pBCryptDeriveKey(secret, L"HASH", NULL, NULL, 0, &size, 0);
4168 todo_wine ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
4169
4170 status = pBCryptDestroySecret(secret);
4171 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
4172
4173 key = NULL;
4174 status = pBCryptGenerateKeyPair(alg, &key, 256, 0);
4175 ok(status == STATUS_INVALID_PARAMETER, "got %08x\n", status);
4176
4177 status = pBCryptGenerateKeyPair(alg, &key, length, 0);
4178 ok(status == STATUS_SUCCESS, "got %08x\n", status);
4179 ok(key != NULL, "key not set\n");
4180
4181 memset(buffer, 0xcc, sizeof(buffer));
4182 status = pBCryptGetProperty(key, BCRYPT_DH_PARAMETERS, buffer, sizeof(buffer), &size, 0);
4183 ok(status == STATUS_INVALID_HANDLE, "got %08x\n", status);
4184
4185 status = pBCryptExportKey(key, NULL, BCRYPT_DH_PUBLIC_BLOB, buffer, sizeof(buffer), &size, 0);
4186 ok(status == STATUS_INVALID_HANDLE, "got %08x\n", status);
4187
4188 status = pBCryptFinalizeKeyPair(key, 0);
4189 if (status != STATUS_SUCCESS)
4190 {
4191 pBCryptDestroyKey(key);
4192 pBCryptCloseAlgorithmProvider(alg, 0);
4193 return;
4194 }
4195 ok(status == STATUS_SUCCESS, "got %08x\n", status);
4196
4197 status = pBCryptFinalizeKeyPair(key, 0);
4198 ok(status == STATUS_INVALID_HANDLE, "got %08x\n", status);
4199
4200 size = 0xdeadbeef;
4201 status = pBCryptGetProperty(key, BCRYPT_DH_PARAMETERS, NULL, sizeof(buffer), &size, 0);
4202 ok(status == STATUS_SUCCESS, "got %08x\n", status);
4203 ok(size == sizeof(BCRYPT_DH_PARAMETER_HEADER) + length / 8 * 2, "Got unexpected size %u.\n", size);
4204
4205 size = 0xdeadbeef;
4206 status = pBCryptGetProperty(key, BCRYPT_DH_PARAMETERS, buffer, 28, &size, 0);
4207 ok(status == STATUS_BUFFER_TOO_SMALL, "got %08x\n", status);
4208 ok(size == sizeof(BCRYPT_DH_PARAMETER_HEADER) + length / 8 * 2, "Got unexpected size %u.\n", size);
4209
4210 size = 0xdeadbeef;
4211 status = pBCryptGetProperty(key, BCRYPT_DH_PARAMETERS, buffer, sizeof(buffer), &size, 0);
4212 ok(status == STATUS_SUCCESS, "got %08x\n", status);
4213 ok(size == sizeof(BCRYPT_DH_PARAMETER_HEADER) + length / 8 * 2, "Got unexpected size %u.\n", size);
4214
4215 dh_header = (BCRYPT_DH_PARAMETER_HEADER *)buffer;
4216 ok(dh_header->cbLength == sizeof(*dh_header) + length / 8 * 2, "Got unexpected length %u.\n", dh_header->cbLength);
4217 ok(dh_header->cbKeyLength == length / 8, "Got unexpected length %u.\n", dh_header->cbKeyLength);
4218 ok(dh_header->dwMagic == BCRYPT_DH_PARAMETERS_MAGIC, "Got unexpected magic 0x%x.\n", dh_header->dwMagic);
4219
4220 status = pBCryptDestroyKey(key);
4221 ok(status == STATUS_SUCCESS, "got %08x\n", status);
4222
4223 dh_key_blob = (BCRYPT_DH_KEY_BLOB *)buffer;
4224 dh_key_blob->dwMagic = BCRYPT_DH_PRIVATE_MAGIC;
4225 dh_key_blob->cbKey = length / 8;
4226 memcpy(dh_key_blob + 1, dh_private_key, sizeof(dh_private_key));
4227 size = sizeof(buffer);
4228 status = pBCryptImportKeyPair(alg, NULL, BCRYPT_DH_PRIVATE_BLOB, &key, buffer, size, 0);
4229 ok(status == STATUS_INVALID_PARAMETER, "got %08x\n", status);
4230 size = sizeof(*dh_key_blob) + length / 8 * 4;
4231 status = pBCryptImportKeyPair(alg, NULL, BCRYPT_DH_PRIVATE_BLOB, &key, buffer, size, 0);
4232 ok(status == STATUS_SUCCESS, "got %08x\n", status);
4233
4234 memset(buffer, 0xcc, sizeof(buffer));
4235 size = 0xdeadbeef;
4236 status = pBCryptExportKey(key, NULL, BCRYPT_DH_PUBLIC_BLOB, NULL, 0, &size, 0);
4237 ok(status == STATUS_SUCCESS, "got %08x\n", status);
4238 ok(size == sizeof(BCRYPT_DH_KEY_BLOB) + length / 8 * 3, "Got unexpected size %u.\n", size);
4239
4240 size = 0xdeadbeef;
4241 status = pBCryptExportKey(key, NULL, BCRYPT_DH_PUBLIC_BLOB, buffer, sizeof(buffer), &size, 0);
4242 ok(status == STATUS_SUCCESS, "got %08x\n", status);
4243 ok(size == sizeof(BCRYPT_DH_KEY_BLOB) + length / 8 * 3, "Got unexpected size %u.\n", size);
4244 dh_key_blob = (BCRYPT_DH_KEY_BLOB *)buffer;
4245 ok(dh_key_blob->dwMagic == BCRYPT_DH_PUBLIC_MAGIC, "Got unexpected magic 0x%x.\n", dh_key_blob->dwMagic);
4246 ok(dh_key_blob->cbKey == length / 8, "Got unexpected length %u.\n", dh_key_blob->cbKey);
4247 ok(!memcmp(dh_key_blob + 1, dh_private_key, length / 8 * 3), "Key data does not match.\n");
4248
4249 status = pBCryptGenerateKeyPair(alg, &key2, length, 0);
4250 ok(status == STATUS_SUCCESS, "got %08x\n", status);
4251 dh_header = (BCRYPT_DH_PARAMETER_HEADER *)buffer;
4253 dh_header->cbLength = sizeof(*dh_header) + length / 8 * 2;
4254 dh_header->cbKeyLength = length / 8;
4255 memcpy(dh_header + 1, dh_private_key, length / 8 * 2);
4256 status = pBCryptSetProperty(key2, BCRYPT_DH_PARAMETERS, buffer, dh_header->cbLength, 0);
4257 ok(status == STATUS_SUCCESS, "got %08x\n", status);
4258 status = pBCryptFinalizeKeyPair(key2, 0);
4259 ok(status == STATUS_SUCCESS, "got %08x\n", status);
4260
4261 status = pBCryptExportKey(key2, NULL, BCRYPT_DH_PUBLIC_BLOB, buffer, sizeof(buffer), &size, 0);
4262 ok(status == STATUS_SUCCESS, "got %08x\n", status);
4263 ok(size == sizeof(BCRYPT_DH_KEY_BLOB) + length / 8 * 3, "Got unexpected size %u.\n", size);
4264 ok(dh_key_blob->dwMagic == BCRYPT_DH_PUBLIC_MAGIC, "Got unexpected dwMagic 0x%x.\n", dh_key_blob->dwMagic);
4265 ok(dh_key_blob->cbKey == length / 8, "Got unexpected length %u.\n", dh_key_blob->cbKey);
4266 todo_wine ok(!memcmp(dh_key_blob + 1, dh_private_key, length / 8 * 2), "DH parameters do not match.\n");
4267 ok(memcmp((BYTE *)(dh_key_blob + 1) + length / 8 * 2, (BYTE *)dh_private_key + length / 8 * 2, length / 8),
4268 "Random public key data matches.\n");
4269
4270 memset(buffer, 0xcc, sizeof(buffer));
4271 status = pBCryptExportKey(key, NULL, BCRYPT_DH_PRIVATE_BLOB, buffer, sizeof(buffer), &size, 0);
4272 ok(status == STATUS_SUCCESS, "got %08x\n", status);
4273 dh_key_blob = (BCRYPT_DH_KEY_BLOB *)buffer;
4274 ok(size == sizeof(BCRYPT_DH_KEY_BLOB) + length / 8 * 4, "Got unexpected size %u.\n", size);
4275 ok(dh_key_blob->dwMagic == BCRYPT_DH_PRIVATE_MAGIC, "Got unexpected dwMagic 0x%x.\n", dh_key_blob->dwMagic);
4276 ok(dh_key_blob->cbKey == length / 8, "Got unexpected length %u.\n", dh_key_blob->cbKey);
4277 ok(!memcmp(dh_key_blob + 1, dh_private_key, length / 8 * 4), "Private key data does not match.\n");
4278
4279 status = pBCryptSecretAgreement(NULL, key, &secret, 0);
4280 ok(status == STATUS_INVALID_HANDLE, "got %08x\n", status);
4281
4282 status = pBCryptSecretAgreement(key, NULL, &secret, 0);
4283 ok(status == STATUS_INVALID_HANDLE, "got %08x\n", status);
4284
4285 status = pBCryptSecretAgreement(key, key, NULL, 0);
4286 ok(status == STATUS_INVALID_PARAMETER, "got %08x\n", status);
4287
4288 status = pBCryptSecretAgreement(key, key, &secret, 0);
4289 ok(status == STATUS_SUCCESS, "got %08x\n", status);
4290
4291 status = pBCryptDeriveKey(NULL, L"HASH", NULL, NULL, 0, &size, 0);
4292 ok(status == STATUS_INVALID_HANDLE, "got %08x\n", status);
4293
4294 status = pBCryptDeriveKey(key, L"HASH", NULL, NULL, 0, &size, 0);
4295 ok(status == STATUS_INVALID_HANDLE, "got %08x\n", status);
4296
4297 status = pBCryptDeriveKey(secret, NULL, NULL, NULL, 0, &size, 0);
4298 ok(status == STATUS_INVALID_PARAMETER, "got %08x\n", status);
4299
4300 size = 0xdeadbeef;
4301 status = pBCryptDeriveKey(secret, L"HASH", NULL, NULL, 0, &size, 0);
4302 ok(status == STATUS_SUCCESS, "got %08x\n", status);
4303 ok(size == 20, "Got unexpected size %u.\n", size);
4304
4305 size = 0xdeadbeef;
4306 status = pBCryptDeriveKey(secret, BCRYPT_KDF_RAW_SECRET, NULL, NULL, 0, &size, 0);
4307 ok(status == STATUS_SUCCESS, "got %08x\n", status);
4308 ok(size == length / 8, "Got unexpected size %u.\n", size);
4309
4310 status = pBCryptDeriveKey(secret, BCRYPT_KDF_RAW_SECRET, NULL, buffer, 128, &size, 0);
4311 ok(status == STATUS_SUCCESS, "got %08x\n", status);
4312 ok(size == length / 8, "Got unexpected size %u.\n", size);
4313 ok(!memcmp(buffer, dh_shared_secret_raw, size), "Raw shared secret data does not match.\n");
4314
4315 size = sizeof(buffer);
4316 memset(buffer, 0xcc, sizeof(buffer));
4317 status = pBCryptDeriveKey(secret, BCRYPT_KDF_HASH, NULL, buffer, 128, &size, 0);
4318 ok(status == STATUS_SUCCESS, "got %08x\n", status);
4319 ok(size == 20, "Got unexpected size %u.\n", size);
4320 ok(!memcmp(buffer, dh_shared_secret_sha1, sizeof(dh_shared_secret_sha1)),
4321 "sha1 shared secret data does not match.\n");
4322
4323 size = sizeof(buffer);
4324 status = pBCryptDeriveKey(secret, BCRYPT_KDF_HASH, &hash_params, buffer, size, &size, 0);
4325 ok(status == STATUS_SUCCESS, "got %08x\n", status);
4326 ok(size == 32, "Got unexpected size %u.\n", size);
4327 ok(!memcmp(buffer, dh_shared_secret_sha256, sizeof(dh_shared_secret_sha256)),
4328 "sha256 shared secret data does not match.\n");
4329
4330 for (i = size; i < sizeof(buffer); ++i)
4331 if (buffer[i] != 0xcc) break;
4332 ok(i == sizeof(buffer), "Buffer modified at %u, value %#x.\n", i, buffer[i]);
4333
4334 status = pBCryptDestroySecret(secret);
4335 ok(status == STATUS_SUCCESS, "got %08x\n", status);
4336
4337 status = pBCryptSecretAgreement(key, key2, &secret, 0);
4338 ok(status == STATUS_SUCCESS, "got %08x\n", status);
4339 status = pBCryptSecretAgreement(key2, key, &secret2, 0);
4340 ok(status == STATUS_SUCCESS, "got %08x\n", status);
4341
4342 status = pBCryptDeriveKey(secret, BCRYPT_KDF_RAW_SECRET, NULL, buffer, 128, &size, 0);
4343 ok(status == STATUS_SUCCESS, "got %08x\n", status);
4344 status = pBCryptDeriveKey(secret, BCRYPT_KDF_RAW_SECRET, NULL, buffer + size, 128, &size, 0);
4345 ok(status == STATUS_SUCCESS, "got %08x\n", status);
4346 ok(!memcmp(buffer, buffer + size, size), "Shared secrets do not match.\n");
4347
4348 status = pBCryptDestroySecret(secret);
4349 ok(status == STATUS_SUCCESS, "got %08x\n", status);
4350 status = pBCryptDestroySecret(secret2);
4351 ok(status == STATUS_SUCCESS, "got %08x\n", status);
4352
4353 status = pBCryptDestroyKey(key);
4354 ok(status == STATUS_SUCCESS, "got %08x\n", status);
4355 status = pBCryptDestroyKey(key2);
4356 ok(status == STATUS_SUCCESS, "got %08x\n", status);
4357
4358 dh_key_blob = (BCRYPT_DH_KEY_BLOB *)buffer;
4359 dh_key_blob->dwMagic = BCRYPT_DH_PRIVATE_MAGIC;
4360 dh_key_blob->cbKey = length / 8;
4361 memcpy(dh_key_blob + 1, dh_private_key2, sizeof(dh_private_key2));
4362
4363 size = sizeof(*dh_key_blob) + length / 8 * 4;
4364 status = pBCryptImportKeyPair(alg, NULL, BCRYPT_DH_PRIVATE_BLOB, &key, buffer, size, 0);
4365 ok(status == STATUS_SUCCESS, "got %08x\n", status);
4366
4367 dh_key_blob = (BCRYPT_DH_KEY_BLOB *)buffer;
4368 dh_key_blob->dwMagic = BCRYPT_DH_PUBLIC_MAGIC;
4369 dh_key_blob->cbKey = length / 8;
4370 memcpy(dh_key_blob + 1, dh_peer_key, sizeof(dh_peer_key));
4371
4372 size = sizeof(*dh_key_blob) + length / 8 * 3;
4373 status = pBCryptImportKeyPair(alg, NULL, BCRYPT_DH_PUBLIC_BLOB, &key2, buffer, size, 0);
4374 ok(status == STATUS_SUCCESS, "got %08x\n", status);
4375
4376 status = pBCryptSecretAgreement(key, key2, &secret, 0);
4377 ok(status == STATUS_SUCCESS, "got %08x\n", status);
4378
4379 status = pBCryptDeriveKey(secret, BCRYPT_KDF_RAW_SECRET, NULL, buffer, 128, &size, 0);
4380 ok(status == STATUS_SUCCESS, "got %08x\n", status);
4381 ok(size == length / 8, "Got unexpected size %u.\n", size);
4382 ok(!memcmp(buffer, dh_shared_secret_raw2, size), "Raw shared secret data does not match.\n");
4383
4384 status = pBCryptDestroySecret(secret);
4385 ok(status == STATUS_SUCCESS, "got %08x\n", status);
4386 status = pBCryptDestroyKey(key);
4387 ok(status == STATUS_SUCCESS, "got %08x\n", status);
4388 status = pBCryptDestroyKey(key2);
4389 ok(status == STATUS_SUCCESS, "got %08x\n", status);
4390
4391 status = pBCryptCloseAlgorithmProvider(alg, 0);
4392 ok(status == STATUS_SUCCESS, "got 0x%x\n", status);
4393}
#define BCRYPT_DH_PARAMETERS
Definition: bcrypt.h:123
#define BCRYPT_DH_PARAMETERS_MAGIC
Definition: bcrypt.h:289
#define BCRYPT_DH_ALGORITHM
Definition: bcrypt.h:89
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
static char secret2[]
Definition: protectdata.c:31

Referenced by START_TEST().

◆ void()

static void ( WINAPI pBCryptFreeBuffer)
static

Variable Documentation

◆ BCRYPT_ALG_HANDLE

Definition at line 61 of file bcrypt.c.

◆ BCRYPT_KEY_HANDLE

Definition at line 49 of file bcrypt.c.

Referenced by test_BCryptGenerateSymmetricKey().

◆ certHash

BYTE certHash[]
static
Initial value:
=
{
0x28, 0x19, 0x0f, 0x15, 0x6d, 0x75, 0xcc, 0xcf, 0x62, 0xf1, 0x5e, 0xe6, 0x8a, 0xc3, 0xf0, 0x5d,
0x89, 0x28, 0x2d, 0x48, 0xd8, 0x73, 0x7c, 0x05, 0x05, 0x8e, 0xbc, 0xce, 0x28, 0xb7, 0xba, 0xc9,
}

Definition at line 2249 of file bcrypt.c.

Referenced by test_ECDSA().

◆ certSignature

BYTE certSignature[]
static
Initial value:
=
{
0xd7, 0x29, 0xce, 0x5a, 0xef, 0x74, 0x85, 0xd1, 0x18, 0x5f, 0x6e, 0xf1, 0xba, 0x53, 0xd4, 0xcd,
0xdd, 0xe0, 0x5d, 0xf1, 0x5e, 0x48, 0x51, 0xea, 0x63, 0xc0, 0xe8, 0xe2, 0xf6, 0xfa, 0x4c, 0xaf,
0xe3, 0x94, 0x15, 0x3b, 0x6c, 0x71, 0x6e, 0x44, 0x22, 0xcb, 0xa0, 0x88, 0xcd, 0x0a, 0x5a, 0x50,
0x29, 0x7c, 0x5c, 0xd6, 0x6c, 0xd2, 0xe0, 0x7f, 0xcd, 0x02, 0x92, 0x21, 0x4c, 0x2c, 0x92, 0xee,
}

Definition at line 2254 of file bcrypt.c.

Referenced by test_ECDSA().

◆ coefficient

BYTE coefficient[512/16]

Definition at line 2463 of file bcrypt.c.

Referenced by CRYPT_AsnDecodeRsaPrivKey(), and test_decodeRsaPrivateKey().

◆ dh_hash_param_buffers

BCryptBuffer dh_hash_param_buffers[]
Initial value:

Definition at line 3333 of file bcrypt.c.

◆ dh_hash_params

BCryptBufferDesc dh_hash_params
Initial value:

Definition at line 3342 of file bcrypt.c.

Referenced by test_DH().

◆ dh_hashed_secret

BYTE dh_hashed_secret[]
static
Initial value:
=
{
0xa7, 0xfc, 0xff, 0x21, 0xb3, 0xd1, 0x46, 0xb8, 0x21, 0x3d, 0xc6, 0xd4, 0xe3, 0x61, 0x97, 0x5e,
0xb5, 0x0a, 0xfe, 0x8f,
}

Definition at line 3327 of file bcrypt.c.

Referenced by test_DH().

◆ dh_privkey

BYTE dh_privkey[]
static
Initial value:
=
{
0x44, 0x48, 0x50, 0x56, 0x40, 0x00, 0x00, 0x00,
0xcf, 0x18, 0xe9, 0xa9, 0xb3, 0x97, 0x59, 0xae, 0x0d, 0xac, 0xf0, 0x99, 0x39, 0xdc, 0xd2, 0xfe,
0x1e, 0xf3, 0xfc, 0x2c, 0x49, 0xdf, 0x76, 0x89, 0xff, 0x13, 0x57, 0xc7, 0xe6, 0xbd, 0xed, 0xa7,
0x42, 0xc0, 0xc3, 0xd7, 0x8e, 0x84, 0xa8, 0xdf, 0xcd, 0x52, 0x50, 0x81, 0x73, 0x8a, 0x33, 0x60,
0xde, 0x6d, 0x56, 0xeb, 0xd5, 0xec, 0x1f, 0x9f, 0x9f, 0xd6, 0x2c, 0xe4, 0x8f, 0xab, 0x58, 0x0b,
0x5f, 0xc5, 0x50, 0x9a, 0xde, 0xf6, 0x84, 0x48, 0x39, 0xa9, 0xa7, 0xb1, 0x73, 0x0c, 0x56, 0xd4,
0x28, 0xbb, 0x12, 0x93, 0x51, 0x44, 0x33, 0xdf, 0xa6, 0xe7, 0x7f, 0x0b, 0x3f, 0xe9, 0x41, 0xef,
0x32, 0x80, 0xcd, 0x8e, 0x2b, 0x38, 0x85, 0x49, 0x4d, 0x0c, 0xcc, 0x74, 0x02, 0x07, 0x92, 0xd3,
0xe4, 0x3e, 0x37, 0x84, 0x27, 0x1f, 0xa3, 0xad, 0x94, 0x8c, 0xc1, 0xc2, 0x22, 0x99, 0x36, 0xf0,
0x22, 0xaf, 0x98, 0xeb, 0xd9, 0xc4, 0xb5, 0xbd, 0xe1, 0xab, 0x19, 0x1b, 0xe3, 0x36, 0x20, 0xca,
0xff, 0xe8, 0x6c, 0x30, 0x96, 0x3c, 0x90, 0x77, 0x0e, 0xe0, 0x96, 0xae, 0xb1, 0x47, 0xd1, 0x52,
0x2c, 0xc3, 0x65, 0x5e, 0x9b, 0x41, 0x9a, 0xa6, 0xfe, 0xab, 0x54, 0xa0, 0xf0, 0x71, 0xab, 0x6c,
0xd0, 0x0e, 0x01, 0x08, 0x5b, 0x66, 0xe5, 0x62, 0xd2, 0xe5, 0x5d, 0xae, 0x9c, 0x60, 0xb2, 0xc6,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x97, 0x71, 0x3e, 0x82,
0x8b, 0xea, 0x11, 0x77, 0xc4, 0xb4, 0x62, 0xc7, 0x4d, 0xff, 0x0f, 0x63, 0xd9, 0xe2, 0xda, 0xab,
}

Definition at line 3293 of file bcrypt.c.

Referenced by test_DH().

◆ dh_pubkey

BYTE dh_pubkey[]
static
Initial value:
=
{
0x44, 0x48, 0x50, 0x42, 0x40, 0x00, 0x00, 0x00,
0xcf, 0x18, 0xe9, 0xa9, 0xb3, 0x97, 0x59, 0xae, 0x0d, 0xac, 0xf0, 0x99, 0x39, 0xdc, 0xd2, 0xfe,
0x1e, 0xf3, 0xfc, 0x2c, 0x49, 0xdf, 0x76, 0x89, 0xff, 0x13, 0x57, 0xc7, 0xe6, 0xbd, 0xed, 0xa7,
0x42, 0xc0, 0xc3, 0xd7, 0x8e, 0x84, 0xa8, 0xdf, 0xcd, 0x52, 0x50, 0x81, 0x73, 0x8a, 0x33, 0x60,
0xde, 0x6d, 0x56, 0xeb, 0xd5, 0xec, 0x1f, 0x9f, 0x9f, 0xd6, 0x2c, 0xe4, 0x8f, 0xab, 0x58, 0x0b,
0x5f, 0xc5, 0x50, 0x9a, 0xde, 0xf6, 0x84, 0x48, 0x39, 0xa9, 0xa7, 0xb1, 0x73, 0x0c, 0x56, 0xd4,
0x28, 0xbb, 0x12, 0x93, 0x51, 0x44, 0x33, 0xdf, 0xa6, 0xe7, 0x7f, 0x0b, 0x3f, 0xe9, 0x41, 0xef,
0x32, 0x80, 0xcd, 0x8e, 0x2b, 0x38, 0x85, 0x49, 0x4d, 0x0c, 0xcc, 0x74, 0x02, 0x07, 0x92, 0xd3,
0xe4, 0x3e, 0x37, 0x84, 0x27, 0x1f, 0xa3, 0xad, 0x94, 0x8c, 0xc1, 0xc2, 0x22, 0x99, 0x36, 0xf0,
0x22, 0xaf, 0x98, 0xeb, 0xd9, 0xc4, 0xb5, 0xbd, 0xe1, 0xab, 0x19, 0x1b, 0xe3, 0x36, 0x20, 0xca,
0xff, 0xe8, 0x6c, 0x30, 0x96, 0x3c, 0x90, 0x77, 0x0e, 0xe0, 0x96, 0xae, 0xb1, 0x47, 0xd1, 0x52,
0x2c, 0xc3, 0x65, 0x5e, 0x9b, 0x41, 0x9a, 0xa6, 0xfe, 0xab, 0x54, 0xa0, 0xf0, 0x71, 0xab, 0x6c,
0xd0, 0x0e, 0x01, 0x08, 0x5b, 0x66, 0xe5, 0x62, 0xd2, 0xe5, 0x5d, 0xae, 0x9c, 0x60, 0xb2, 0xc6,
}

Definition at line 3272 of file bcrypt.c.

Referenced by test_DH().

◆ dh_secret

BYTE dh_secret[]
static
Initial value:
=
{
0x73, 0x84, 0x62, 0xc1, 0x9a, 0x9c, 0xc2, 0x91, 0x9f, 0xc1, 0xc2, 0x94, 0x0c, 0xa8, 0x2f, 0x58,
0xac, 0x50, 0xcd, 0xd5, 0x29, 0x43, 0x41, 0x8e, 0x5d, 0xca, 0x73, 0x55, 0x4d, 0x46, 0x50, 0xe5,
0xb7, 0x34, 0xa9, 0xcb, 0x3a, 0x18, 0x68, 0x99, 0x30, 0xef, 0x58, 0x26, 0xd3, 0x03, 0x61, 0x02,
0x17, 0xb7, 0xba, 0x01, 0xbc, 0xae, 0xdf, 0x3f, 0xb5, 0xb5, 0x4a, 0xb0, 0x08, 0xe5, 0xea, 0xc3,
}

Definition at line 3319 of file bcrypt.c.

Referenced by test_DH().

◆ dk

const UCHAR* dk

Definition at line 543 of file bcrypt.c.

Referenced by BCryptDeriveKeyPBKDF2(), derive_key_pbkdf2(), and test_BcryptDeriveKeyPBKDF2().

◆ dk1

UCHAR dk1[] = "0c60c80f961f0e71f3a9b524af6012062fe037a6"
static

Definition at line 527 of file bcrypt.c.

◆ dk2

UCHAR dk2[] = "ea6c014dc72d6f8ccd1ed92ace1d41f0d8de8957"
static

Definition at line 528 of file bcrypt.c.

◆ dk3

UCHAR dk3[] = "4b007901b765489abead49d926f721d065a429c1"
static

Definition at line 529 of file bcrypt.c.

◆ dk4

UCHAR dk4[] = "364dd6bc200ec7d197f1b85f4a61769010717124"
static

Definition at line 530 of file bcrypt.c.

◆ dk5

UCHAR dk5[] = "3d2eec4fe41c849b80c8d83662c0e44a8b291a964cf2f07038"
static

Definition at line 531 of file bcrypt.c.

◆ dk6

UCHAR dk6[] = "56fa6aa75548099dcc37d7f03425e0c3"
static

Definition at line 532 of file bcrypt.c.

◆ dk7

UCHAR dk7[] = "8754c32c64b0f524fc50c00f788135de"
static

Definition at line 533 of file bcrypt.c.

◆ dk_len

ULONG dk_len

Definition at line 540 of file bcrypt.c.

Referenced by BCryptDeriveKeyPBKDF2(), derive_key_pbkdf2(), and test_BcryptDeriveKeyPBKDF2().

◆ dsaHash

UCHAR dsaHash[]
static
Initial value:
=
{
0x7e,0xe3,0x74,0xe7,0xc5,0x0b,0x6b,0x70,0xdb,0xab,0x32,0x6d,0x1d,0x51,0xd6,0x74,0x79,0x8e,0x5b,0x4b
}

Definition at line 3822 of file bcrypt.c.

Referenced by test_DSA().

◆ dsaPublicBlob

UCHAR dsaPublicBlob[]
static
Initial value:
=
{
0x44,0x53,0x50,0x42,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x8f,0xd2,0x92,0xbb,0x92,0xb9,0x00,0xc5,0xed,
0x52,0xcc,0x48,0x4a,0x44,0x1d,0xd3,0x74,0xfb,0x75,0xd1,0x7e,0xb6,0x24,0x9b,0x5d,0x57,0x0a,0x8a,0xc4,
0x5d,0xab,0x9c,0x26,0x86,0xc6,0x25,0x16,0x20,0xf9,0xa9,0x71,0xbc,0x1d,0x30,0xc4,0xef,0x8c,0xc4,0xdf,
0x1a,0xaf,0x96,0xdf,0x90,0xd8,0x85,0x9d,0xf9,0x2c,0x86,0x8c,0x91,0x39,0x6c,0x6d,0x11,0x4e,0x53,0x63,
0x2a,0x2b,0x26,0xa7,0xf9,0x76,0x74,0x51,0xbf,0x08,0x87,0x6f,0xe0,0x71,0x91,0x24,0x8a,0xc2,0x84,0x2d,
0x84,0x9c,0x5f,0x94,0xaa,0x38,0x53,0x77,0x84,0xba,0xbc,0xff,0x49,0x3a,0x08,0x0f,0x38,0xb5,0x91,0x5c,
0x06,0x15,0xa4,0x27,0xf4,0xa5,0x59,0xaa,0x1c,0x41,0xa3,0xa0,0xbb,0xf7,0x32,0x86,0xfb,0x94,0x41,0xff,
0xcd,0xed,0x69,0xeb,0xc6,0x5e,0xb6,0xa8,0x15,0x82,0x3b,0x60,0x1e,0x91,0x55,0xd5,0x2c,0xa5,0x74,0x5a,
0x65,0x8f,0xc6,0x56,0xc4,0x3f,0x4e,0xe3,0x3a,0x71,0xb2,0x63,0x66,0xa4,0x0d,0x0d,0xf9,0xdd,0x1e,0x48,
0x81,0xe9,0xbf,0x8f,0xbb,0x85,0x47,0x81,0x68,0x11,0xb5,0x91,0x6b,0xc4,0x05,0xef,0xa3,0xc7,0xbf,0x26,
0x53,0x4f,0xc4,0x10,0xfd,0xfa,0xed,0x61,0x64,0xd6,0x2e,0xad,0x04,0x3e,0x82,0xed,0xb2,0x22,0x76,0xd0,
0x44,0xad,0xc1,0x4c,0xde,0x33,0xa3,0x61,0x55,0xec,0x24,0xe5,0x79,0x45,0xcf,0x94,0x39,0x92,0x9f,0xd8,
0x24,0xce,0x85,0xb9
}

Definition at line 3833 of file bcrypt.c.

Referenced by test_DSA().

◆ dsaSignature

UCHAR dsaSignature[]
static
Initial value:
=
{
0x5f,0x95,0x1f,0x08,0x19,0x44,0xa5,0xab,0x28,0x11,0x51,0x68,0x82,0x9b,0xe4,0xc3,0x04,0x1b,0xc9,0xdc,
0x41,0x2a,0x89,0xd4,0x4a,0x8b,0x86,0xaf,0x98,0x2c,0x59,0x0b,0xd2,0x88,0xf6,0xe8,0x29,0x13,0x84,0x49
}

Definition at line 3827 of file bcrypt.c.

Referenced by test_DSA().

◆ dssKey

UCHAR dssKey[]
static
Initial value:
=
{
0x07,0x02,0x00,0x00,0x00,0x22,0x00,0x00,0x44,0x53,0x53,0x32,0x00,0x04,0x00,0x00,0x01,0xd1,0xfc,0x7a,
0x70,0x53,0xb2,0x48,0x70,0x23,0x19,0x1f,0x3c,0xe1,0x26,0x14,0x7e,0x9f,0x0f,0x7f,0x33,0x5e,0x2b,0xf7,
0xca,0x01,0x74,0x8c,0xb4,0xfd,0xf6,0x44,0x95,0x35,0x56,0xaa,0x4d,0x62,0x48,0xe2,0xd1,0xa2,0x7e,0x6e,
0xeb,0xd6,0xcc,0x7c,0xe8,0xfd,0x21,0x9a,0xa2,0xfd,0x7a,0x9d,0x1a,0x38,0x69,0x87,0x39,0x5a,0x91,0xc0,
0x52,0x2b,0x9f,0x2a,0x54,0x78,0x37,0x82,0x9a,0x70,0x57,0xab,0xec,0x93,0x8e,0xac,0x73,0x04,0xe8,0x53,
0x72,0x72,0x32,0xc6,0xcb,0xef,0x47,0x98,0x3c,0x56,0x49,0x62,0xcb,0xbb,0xe7,0x34,0x84,0xa6,0x72,0x3a,
0xbe,0x26,0x46,0x86,0xca,0xcb,0x35,0x62,0x4f,0x19,0x18,0x0b,0xb0,0x78,0xae,0xd5,0x42,0xdf,0x26,0xdb,
0x85,0x63,0x77,0x85,0x01,0x3b,0x32,0xbe,0x5c,0xf8,0x05,0xc8,0xde,0x17,0x7f,0xb9,0x03,0x82,0xfa,0xf1,
0x9e,0x32,0x73,0xfa,0x8d,0xea,0xa3,0x30,0x48,0xe2,0xdf,0x5a,0xcb,0x83,0x3d,0xff,0x56,0xe9,0xc0,0x94,
0xf8,0x6d,0xb3,0xaf,0x4a,0x97,0xb9,0x43,0x0e,0xd4,0x28,0x98,0x57,0x2e,0x3a,0xca,0xde,0x6f,0x45,0x0d,
0xfb,0x58,0xec,0x78,0x34,0x2e,0x46,0x4d,0xfe,0x98,0x02,0xbb,0xef,0x07,0x1a,0x13,0xb6,0xc2,0x2c,0x06,
0xd9,0x0c,0xc4,0xb0,0x4c,0x3a,0xfc,0x01,0x63,0xb5,0x5a,0x5d,0x2d,0x9c,0x47,0x04,0x67,0x51,0xf2,0x52,
0xf5,0x82,0x36,0xeb,0x6e,0x66,0x58,0x4c,0x10,0x2c,0x29,0x72,0x4a,0x6f,0x6b,0x6c,0xe0,0x93,0x31,0x42,
0xf6,0xda,0xfa,0x5b,0x22,0x43,0x9b,0x1a,0x98,0x71,0xe7,0x41,0x74,0xe9,0x12,0xa4,0x1f,0x27,0x0a,0x63,
0x94,0x49,0xd7,0xad,0xa5,0xc4,0x5c,0xc3,0xc9,0x70,0xb3,0x7b,0x16,0xb6,0x1d,0xd4,0x09,0xc4,0x9a,0x46,
0x2d,0x0e,0x75,0x07,0x31,0x7b,0xed,0x45,0xcd,0x99,0x84,0x14,0xf1,0x01,0x00,0x00,0x93,0xd5,0xa3,0xe4,
0x34,0x05,0xeb,0x98,0x3b,0x5f,0x2f,0x11,0xa4,0xa5,0xc4,0xff,0xfb,0x22,0x7c,0x54
}

Definition at line 3850 of file bcrypt.c.

Referenced by test_DSA().

◆ eccPrivkey

BYTE eccPrivkey[]
static
Initial value:
=
{
0x26, 0xff, 0x0e, 0xf9, 0x71, 0x93, 0xf8, 0xed, 0x59, 0xfa, 0x24, 0xec, 0x18, 0x13, 0xfe, 0xf5,
0x0b, 0x4a, 0xb1, 0x27, 0xb7, 0xab, 0x3e, 0x4f, 0xc5, 0x5a, 0x91, 0xa3, 0x6e, 0x21, 0x61, 0x65,
0x62, 0x7b, 0x8b, 0x30, 0x7a, 0x63, 0x4c, 0x1a, 0xf4, 0x54, 0x54, 0xbb, 0x75, 0x59, 0x68, 0x36,
0xfe, 0x49, 0x95, 0x75, 0x9e, 0x20, 0x3e, 0x69, 0x58, 0xb9, 0x7a, 0x84, 0x03, 0x45, 0x5c, 0x10,
0xb9, 0xcd, 0xbe, 0xd4, 0x75, 0x5d, 0x05, 0xe5, 0x83, 0x0c, 0xd3, 0x37, 0x34, 0x15, 0xe3, 0x2c,
0xe5, 0x85, 0x15, 0xa9, 0xee, 0xba, 0x94, 0x03, 0x03, 0x0b, 0x86, 0xea, 0x85, 0x40, 0xbd, 0x35,
}

Definition at line 2228 of file bcrypt.c.

Referenced by test_ECDSA().

◆ eccprivkey

BYTE eccprivkey[]
static
Initial value:
=
{
0x45, 0x43, 0x4b, 0x32, 0x20, 0x00, 0x00, 0x00,
0xfb, 0xbd, 0x3d, 0x20, 0x1b, 0x6d, 0x66, 0xb3, 0x7c, 0x9f, 0x89, 0xf3, 0xe4, 0x41, 0x16, 0xa5,
0x68, 0x52, 0x77, 0xac, 0xab, 0x55, 0xb2, 0x6c, 0xb0, 0x23, 0x55, 0xcb, 0x96, 0x14, 0xfd, 0x0b,
0x1c, 0xef, 0xdf, 0x07, 0x6d, 0x31, 0xaf, 0x39, 0xce, 0x8c, 0x8f, 0x9d, 0x75, 0xd0, 0x7b, 0xea,
0x81, 0xdc, 0x40, 0x21, 0x1f, 0x58, 0x22, 0x5f, 0x72, 0x55, 0xfc, 0x58, 0x8a, 0xeb, 0x88, 0x5d,
0x02, 0x09, 0x90, 0xd2, 0xe3, 0x36, 0xac, 0xfe, 0x83, 0x13, 0x6c, 0x88, 0x1a, 0xab, 0x9b, 0xdd,
0xaa, 0x8a, 0xee, 0x69, 0x9a, 0x6a, 0x62, 0x86, 0x6a, 0x13, 0x69, 0x88, 0xb7, 0xd5, 0xa3, 0xcd
}

Definition at line 3053 of file bcrypt.c.

Referenced by test_ECDH().

◆ eccPubkey

BYTE eccPubkey[]
static
Initial value:
=
{
0x3b, 0x3c, 0x34, 0xc8, 0x3f, 0x15, 0xea, 0x02, 0x68, 0x46, 0x69, 0xdf, 0x0c, 0xa6, 0xee, 0x7a,
0xd9, 0x82, 0x08, 0x9b, 0x37, 0x53, 0x42, 0xf3, 0x13, 0x63, 0xda, 0x65, 0x79, 0xe8, 0x04, 0x9e,
0x8c, 0x77, 0xc4, 0x33, 0x77, 0xd9, 0x5a, 0x7f, 0x60, 0x7b, 0x98, 0xce, 0xf3, 0x96, 0x56, 0xd6,
0xb5, 0x8d, 0x87, 0x7a, 0x00, 0x2b, 0xf3, 0x70, 0xb3, 0x90, 0x73, 0xa0, 0x56, 0x06, 0x3b, 0x22,
}

Definition at line 2240 of file bcrypt.c.

Referenced by test_ECDSA().

◆ ecdh_pubkey

BYTE ecdh_pubkey[]
static
Initial value:
=
{
0x45, 0x43, 0x4b, 0x31, 0x20, 0x00, 0x00, 0x00,
0x07, 0x61, 0x9d, 0x49, 0x63, 0x6b, 0x96, 0x94, 0xd1, 0x8f, 0xd1, 0x48, 0xcc, 0xcf, 0x72, 0x4d,
0xff, 0x43, 0xf4, 0x97, 0x0f, 0xa3, 0x8a, 0x72, 0xe9, 0xe0, 0xba, 0x87, 0x6d, 0xc3, 0x62, 0x15,
0xae, 0x65, 0xdd, 0x31, 0x51, 0xfc, 0x3b, 0xc9, 0x59, 0xa1, 0x0a, 0x92, 0x17, 0x2b, 0x64, 0x55,
0x03, 0x3e, 0x62, 0x1d, 0xac, 0x3e, 0x37, 0x40, 0x6a, 0x4c, 0xb6, 0x21, 0x3f, 0x73, 0x5c, 0xf5
}

Definition at line 3064 of file bcrypt.c.

Referenced by test_ECDH().

◆ ecdh_secret

BYTE ecdh_secret[]
static
Initial value:
=
{
0x48, 0xb0, 0x11, 0xdb, 0x69, 0x4e, 0xb4, 0xf4, 0xf5, 0x3e, 0xe1, 0x9b, 0xca, 0x00, 0x04, 0xc8,
0x9b, 0x69, 0xaf, 0xd1, 0xaf, 0x1f, 0xc2, 0xd7, 0x83, 0x0a, 0xb7, 0xf8, 0x4f, 0x24, 0x32, 0x8e,
}

Definition at line 3074 of file bcrypt.c.

Referenced by test_ECDH().

◆ encrypt_race_start_barrier

LONG encrypt_race_start_barrier
static

Definition at line 1003 of file bcrypt.c.

Referenced by encrypt_race_thread(), and test_BCryptEncrypt().

◆ exp1

BYTE exp1[512/16]

Definition at line 2461 of file bcrypt.c.

Referenced by test_SystemFunction003().

◆ exp2

BYTE exp2[512/16]

Definition at line 2462 of file bcrypt.c.

Referenced by Test_ofuncs(), and test_SystemFunction003().

◆ hash_param_buffers

BCryptBuffer hash_param_buffers[]
Initial value:

Definition at line 3080 of file bcrypt.c.

Referenced by test_ECDH(), and test_SecretAgreement().

◆ hash_params

BCryptBufferDesc hash_params
Initial value:

Definition at line 3089 of file bcrypt.c.

Referenced by test_ECDH(), and test_SecretAgreement().

◆ hashed_secret

BYTE hashed_secret[]
static
Initial value:
=
{
0x1b, 0xe7, 0xbf, 0x0f, 0x65, 0x1e, 0xd0, 0x07, 0xf9, 0xf4, 0x77, 0x48, 0x48, 0x39, 0xd0, 0xf8,
0xf3, 0xce, 0xfc, 0x89
}

Definition at line 3096 of file bcrypt.c.

Referenced by test_ECDH().

◆ header

Definition at line 2456 of file bcrypt.c.

◆ iterations

◆ long_password

UCHAR long_password[] = "passwordPASSWORDpassword"
static

Definition at line 522 of file bcrypt.c.

◆ long_salt

UCHAR long_salt[] = "saltSALTsaltSALTsaltSALTsaltSALTsalt"
static

Definition at line 523 of file bcrypt.c.

◆ LPCWSTR

Definition at line 30 of file bcrypt.c.

◆ modulus

BYTE modulus[512/8]

Definition at line 2458 of file bcrypt.c.

◆ password

UCHAR password[] = "password"
static

Definition at line 520 of file bcrypt.c.

Referenced by _CZipAskPassword(), ADsOpenObject(), Authenticate_Authenticate(), canonicalize_password(), CredPackAuthenticationBufferW(), CredUnPackAuthenticationBufferW(), do_authorization(), event_redirect(), export_password_dlg_proc(), fill_url_components(), find_existing_credential(), HTMLXMLHttpRequest_open(), HTTP_DoAuthorization(), httprequest_open(), InternetCrackUrl_test(), InternetCreateUrlA_test(), iso_connect(), CZipCreatorImpl::JustDoIt(), main(), MAPILogon(), MAPILogonEx(), mcs_connect_start(), ntlm_AcquireCredentialsHandleW(), ntlm_InitializeSecurityContextW(), SEALED_::OnRedirect(), PFXExportCertStore(), PFXExportCertStoreEx(), PFXImportCertStore(), PFXVerifyPassword(), POP3Transport_CommandPASS(), process_redirect_pdu(), rdp2vnc_connect(), rdp_connect(), rdp_reconnect(), rdp_send_logon_info(), read_password(), rpcrt4_http_internet_connect(), sec_connect(), SECUR32_CreateNTLM1SessionKey(), ServerXMLHTTPRequest_open(), set_credentials(), set_request_credentials(), SspiPrepareForCredWrite(), SspiPromptForCredentialsW(), SystemFunction006(), test_create_delete_svc(), test_CredUIPromptForCredentials(), test_espassword(), test_HlinkCreateExtensionServices(), test_IWinHttpRequest(), test_proxy_direct(), test_queryconfig2(), test_sequence(), test_SspiEncodeStringsAsAuthIdentity(), unzOpenCurrentFile3(), unzOpenCurrentFilePassword(), UserLoginThread(), winhttp_request_SetCredentials(), WinHttpCrackUrl(), WinHttpCrackUrl_test(), WinHttpSetCredentials(), WININET_PasswordDialog(), WININET_ProxyPasswordDialog(), WININET_SetAuthorization(), WNetUseConnectionA(), WNetUseConnectionW(), XMLHTTPRequest_open(), zipOpenNewFileInZip3(), zipOpenNewFileInZip3_64(), zipOpenNewFileInZip4(), and zipOpenNewFileInZip4_64().

◆ password_NUL

UCHAR password_NUL[] = "pass\0word"
static

Definition at line 524 of file bcrypt.c.

◆ prime1

BYTE prime1[512/16]

Definition at line 2459 of file bcrypt.c.

Referenced by CRYPT_AsnDecodeRsaPrivKey(), and test_decodeRsaPrivateKey().

◆ prime2

BYTE prime2[512/16]

Definition at line 2460 of file bcrypt.c.

Referenced by CRYPT_AsnDecodeRsaPrivKey(), and test_decodeRsaPrivateKey().

◆ private_exp

BYTE private_exp[512/8]

Definition at line 2464 of file bcrypt.c.

◆ PUCHAR

Definition at line 33 of file bcrypt.c.

◆ pwd

◆ pwd_len

ULONG pwd_len

Definition at line 537 of file bcrypt.c.

Referenced by BCryptDeriveKeyPBKDF2(), derive_key_pbkdf2(), and test_BcryptDeriveKeyPBKDF2().

◆ 

const struct { ... } rfc6070[]
Initial value:
=
{
{ 8, 4, 1, 20, password, salt, dk1 },
{ 8, 4, 2, 20, password, salt, dk2 },
{ 8, 4, 4096, 20, password, salt, dk3 },
{ 8, 4, 1000000, 20, password, salt, dk4 },
{ 24, 36, 4096, 25, long_password, long_salt, dk5 },
{ 9, 5, 4096, 16, password_NUL, salt_NUL, dk6 },
{ 8, 0, 1, 16, password, NULL, dk7 }
}
static UCHAR long_password[]
Definition: bcrypt.c:522
static UCHAR dk3[]
Definition: bcrypt.c:529
static UCHAR long_salt[]
Definition: bcrypt.c:523
static UCHAR salt_NUL[]
Definition: bcrypt.c:525
static UCHAR password_NUL[]
Definition: bcrypt.c:524
static UCHAR password[]
Definition: bcrypt.c:520
static UCHAR dk5[]
Definition: bcrypt.c:531
static UCHAR dk4[]
Definition: bcrypt.c:530
static UCHAR dk2[]
Definition: bcrypt.c:528
static UCHAR dk6[]
Definition: bcrypt.c:532
static UCHAR dk1[]
Definition: bcrypt.c:527
static UCHAR dk7[]
Definition: bcrypt.c:533

Referenced by test_BcryptDeriveKeyPBKDF2().

◆ rsa_encrypted_no_padding

const UCHAR rsa_encrypted_no_padding[]
static
Initial value:
=
{
0x4a, 0xc1, 0xfa, 0x4f, 0xe0, 0x3f, 0x36, 0x9a, 0x64, 0xbf, 0x2e, 0x00, 0xb4, 0xb5, 0x40, 0xbe,
0x2d, 0x9a, 0x14, 0xf6, 0x8f, 0xa5, 0xc2, 0xe2, 0x20, 0xaf, 0x21, 0x79, 0xc6, 0x32, 0x7e, 0xea,
0x73, 0x00, 0x01, 0xbb, 0x9a, 0x19, 0x73, 0x41, 0x96, 0xae, 0x88, 0x6e, 0x36, 0x56, 0xe9, 0x9c,
0xac, 0x04, 0x82, 0xa8, 0x00, 0xdb, 0x4e, 0x29, 0x61, 0x7e, 0xaf, 0x64, 0xdb, 0xa2, 0x70, 0x0f,
}

Definition at line 2521 of file bcrypt.c.

Referenced by test_rsa_encrypt().

◆ rsaFullPrivateBlob

UCHAR rsaFullPrivateBlob[]
static
Initial value:
=
{
0x52, 0x53, 0x41, 0x33, 0x00, 0x02, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
0x20, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0xa6, 0x8b, 0x46, 0x26, 0xb5,
0xa9, 0x69, 0x83, 0x94, 0x66, 0xa7, 0xf3, 0x33, 0x95, 0x74, 0xe9, 0xeb, 0xc8, 0xcd, 0xd7, 0x81,
0x9e, 0x45, 0x66, 0xb2, 0x48, 0x8b, 0x1f, 0xfe, 0xb3, 0x62, 0xc4, 0x0d, 0xa2, 0xf9, 0xf3, 0xe2,
0xa6, 0x86, 0xd1, 0x1e, 0x8a, 0xbb, 0x1d, 0xa5, 0xc5, 0xe8, 0xa7, 0x50, 0x37, 0xfd, 0x69, 0x1f,
0x6f, 0x99, 0x99, 0xca, 0x39, 0x13, 0xea, 0x5b, 0x6b, 0xe3, 0x91, 0xc0, 0xd2, 0x2c, 0x0b, 0x21,
0xb1, 0xac, 0xa9, 0xe8, 0xa0, 0x6d, 0xa4, 0x1f, 0x1b, 0x34, 0xcb, 0x88, 0x7f, 0x2e, 0xeb, 0x7d,
0x91, 0x38, 0x48, 0xce, 0x05, 0x73, 0x05, 0xdd, 0x22, 0x94, 0xc3, 0xdd, 0x1c, 0xfd, 0xc5, 0x41,
0x2e, 0x94, 0xf9, 0xed, 0xe5, 0x92, 0x5f, 0x3f, 0x06, 0xf8, 0x49, 0x60, 0xb8, 0x92, 0x52, 0x6a,
0x56, 0x6e, 0xd7, 0x04, 0x1a, 0xb5, 0xb5, 0x1c, 0x31, 0xd1, 0x1b, 0xa3, 0xf3, 0xd1, 0x69, 0x61,
0xab, 0xfe, 0xc1, 0xb6, 0x40, 0x7b, 0x19, 0xbb, 0x2d, 0x59, 0xf5, 0xda, 0x49, 0x32, 0x6f, 0x20,
0x24, 0xd3, 0xb3, 0xec, 0x21, 0xec, 0x0c, 0xc7, 0x5b, 0xf9, 0x1b, 0xba, 0x6e, 0xe9, 0x61, 0xda,
0x55, 0xc6, 0x72, 0xfd, 0x2d, 0x66, 0x3f, 0x3c, 0xcb, 0x49, 0xa9, 0xc5, 0x0d, 0x9b, 0x02, 0x36,
0x7a, 0xee, 0x36, 0x09, 0x55, 0xe4, 0x03, 0xf2, 0xe3, 0xe6, 0x25, 0x14, 0x89, 0x7f, 0x2b, 0xfb,
0x27, 0x0e, 0x8d, 0x37, 0x84, 0xfd, 0xad, 0x10, 0x79, 0x43, 0x4e, 0x38, 0x4a, 0xd4, 0x5e, 0xfa,
0xda, 0x9f, 0x88, 0x21, 0x7c, 0xb4, 0x98, 0xb6, 0x6e, 0x1c, 0x24, 0x09, 0xe5, 0xe7, 0x22, 0x6f,
0xd3, 0x84, 0xc0, 0xdc, 0x36, 0x09, 0xaf, 0x4b, 0x96, 0x8b, 0x5f, 0x47, 0xb3, 0x24, 0x80, 0xb5,
0x64, 0x69, 0xad, 0x83, 0xd5, 0x09, 0xe7, 0xb9, 0xe4, 0x81, 0x6f, 0x1a, 0xe2, 0x6d, 0xf1, 0x5e,
0x2b, 0xb3, 0x7a, 0xd0, 0x77, 0xef, 0x82, 0xcd, 0x55, 0x2e, 0xd5, 0xb1, 0xa7, 0x72, 0xec, 0x02,
0x9d, 0xe2, 0xcc, 0x5a, 0xf1, 0x68, 0x30, 0xe5, 0xbc, 0x8d, 0xad,
}

Definition at line 2430 of file bcrypt.c.

Referenced by test_RSA().

◆ rsaHash

UCHAR rsaHash[]
static
Initial value:
=
{
0x96, 0x1f, 0xa6, 0x49, 0x58, 0x81, 0x8f, 0x76, 0x77, 0x07, 0x07, 0x27, 0x55, 0xd7, 0x01, 0x8d,
0xcd, 0x27, 0x8e, 0x94
}

Definition at line 2390 of file bcrypt.c.

Referenced by test_RSA(), and test_RSA_SIGN().

◆ 

struct { ... } rsaLegacyPrivateBlob

Referenced by test_rsa_encrypt().

◆ rsaPrivateBlob

UCHAR rsaPrivateBlob[]
static
Initial value:
=
{
0x52, 0x53, 0x41, 0x32, 0x00, 0x02, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
0x20, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0xa6, 0x8b, 0x46, 0x26, 0xb5,
0xa9, 0x69, 0x83, 0x94, 0x66, 0xa7, 0xf3, 0x33, 0x95, 0x74, 0xe9, 0xeb, 0xc8, 0xcd, 0xd7, 0x81,
0x9e, 0x45, 0x66, 0xb2, 0x48, 0x8b, 0x1f, 0xfe, 0xb3, 0x62, 0xc4, 0x0d, 0xa2, 0xf9, 0xf3, 0xe2,
0xa6, 0x86, 0xd1, 0x1e, 0x8a, 0xbb, 0x1d, 0xa5, 0xc5, 0xe8, 0xa7, 0x50, 0x37, 0xfd, 0x69, 0x1f,
0x6f, 0x99, 0x99, 0xca, 0x39, 0x13, 0xea, 0x5b, 0x6b, 0xe3, 0x91, 0xc0, 0xd2, 0x2c, 0x0b, 0x21,
0xb1, 0xac, 0xa9, 0xe8, 0xa0, 0x6d, 0xa4, 0x1f, 0x1b, 0x34, 0xcb, 0x88, 0x7f, 0x2e, 0xeb, 0x7d,
0x91, 0x38, 0x48, 0xce, 0x05, 0x73, 0x05, 0xdd, 0x22, 0x94, 0xc3, 0xdd, 0x1c, 0xfd, 0xc5, 0x41,
0x2e, 0x94, 0xf9, 0xed, 0xe5, 0x92, 0x5f, 0x3f, 0x06, 0xf8, 0x49, 0x60, 0xb8, 0x92, 0x52, 0x6a,
0x56, 0x6e, 0xd7, 0x04, 0x1a, 0xb5, 0xb5, 0x1c, 0x31, 0xd1, 0x1b,
}

Definition at line 2416 of file bcrypt.c.

Referenced by test_RSA(), and test_rsa_encrypt().

◆ rsapubkey

RSAPUBKEY rsapubkey

Definition at line 2457 of file bcrypt.c.

Referenced by CNG_ImportRSAPubKey(), and convert_legacy_rsaprivate_blob().

◆ rsapublic

BYTE rsapublic[]
static
Initial value:
=
{
0x52, 0x53, 0x41, 0x31, 0x00, 0x08, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0xd5, 0xfe, 0xf6, 0x7a, 0x9a, 0xa1, 0x2d, 0xcf, 0x98,
0x60, 0xca, 0x38, 0x60, 0x0b, 0x74, 0x4c, 0x7e, 0xa1, 0x42, 0x64, 0xad, 0x05, 0xa5, 0x29, 0x25, 0xcb, 0xd5,
0x9c, 0xaf, 0x6f, 0x63, 0x85, 0x6d, 0x5b, 0x59, 0xe5, 0x17, 0x8f, 0xf9, 0x18, 0x90, 0xa7, 0x63, 0xae, 0xe0,
0x3a, 0x62, 0xf7, 0x98, 0x57, 0xe9, 0x91, 0xda, 0xfb, 0xd9, 0x36, 0x45, 0xe4, 0x9e, 0x75, 0xf6, 0x73, 0xc4,
0x99, 0x23, 0x21, 0x1b, 0x3d, 0xe1, 0xe0, 0xa6, 0xa0, 0x4a, 0x50, 0x2a, 0xcb, 0x2a, 0x50, 0xf0, 0x8b, 0x70,
0x9c, 0xe4, 0x1a, 0x14, 0x3b, 0xbe, 0x35, 0xa5, 0x5a, 0x91, 0xa3, 0xa1, 0x82, 0xea, 0x84, 0x4d, 0xe8, 0x62,
0x3b, 0x11, 0xec, 0x61, 0x09, 0x6c, 0xfe, 0xb2, 0xcc, 0x4b, 0xa8, 0xff, 0xaf, 0x73, 0x72, 0x05, 0x4e, 0x7e,
0xe5, 0x73, 0xdf, 0x24, 0xcf, 0x7f, 0x5d, 0xaf, 0x8a, 0xf0, 0xd8, 0xcb, 0x08, 0x1e, 0xf2, 0x36, 0x70, 0x8d,
0x1b, 0x9e, 0xc8, 0x98, 0x60, 0x54, 0xeb, 0x45, 0x34, 0x21, 0x43, 0x4d, 0x42, 0x0a, 0x3a, 0x2d, 0x0f, 0x0e,
0xd6, 0x0d, 0xe4, 0x2e, 0x8c, 0x31, 0x87, 0xa8, 0x09, 0x89, 0x61, 0x16, 0xca, 0x5b, 0xbe, 0x76, 0x69, 0xbb,
0xfd, 0x91, 0x63, 0xd2, 0x66, 0x57, 0x08, 0xef, 0xe2, 0x40, 0x67, 0xd7, 0x7f, 0x50, 0x15, 0x42, 0x33, 0x97,
0x54, 0x73, 0x47, 0xe7, 0x9c, 0x14, 0xa8, 0xb0, 0x3d, 0xc9, 0x23, 0xb0, 0x27, 0x3b, 0xe7, 0xdd, 0x5f, 0xd1,
0x4f, 0x31, 0x10, 0x7d, 0xdd, 0x69, 0x8e, 0xde, 0xa3, 0xe8, 0x92, 0x00, 0xfa, 0xa5, 0xa4, 0x40, 0x51, 0x23,
0x82, 0x84, 0xc7, 0xce, 0x19, 0x61, 0x26, 0xf1, 0xae, 0xf3, 0x90, 0x93, 0x98, 0x56, 0x23, 0x9a, 0xd1, 0xbd,
0xf2, 0xdf, 0xfd, 0x13, 0x9c, 0x30, 0x07, 0xf9, 0x5a, 0x2e, 0x00, 0xc6, 0x1f
}

Definition at line 3519 of file bcrypt.c.

Referenced by test_BCryptSignHash().

◆ rsaPublicBlob

UCHAR rsaPublicBlob[]
static
Initial value:
=
{
0x52, 0x53, 0x41, 0x31, 0x00, 0x08, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0xad, 0x41, 0x09, 0xa2, 0x56,
0x3a, 0x7b, 0x75, 0x4b, 0x72, 0x9b, 0x28, 0x72, 0x3b, 0xae, 0x9f, 0xd8, 0xa8, 0x25, 0x4a, 0x4c,
0x19, 0xf5, 0xa6, 0xd0, 0x05, 0x1c, 0x59, 0x8f, 0xe3, 0xf3, 0x2d, 0x29, 0x47, 0xf8, 0x80, 0x25,
0x25, 0x21, 0x58, 0xc2, 0xac, 0xa1, 0x9e, 0x93, 0x8e, 0x82, 0x6d, 0xd7, 0xf3, 0xe7, 0x8f, 0x0b,
0xc0, 0x41, 0x85, 0x29, 0x3c, 0xf1, 0x0b, 0x2c, 0x5d, 0x49, 0xed, 0xb4, 0x30, 0x6e, 0x02, 0x15,
0x4b, 0x9a, 0x08, 0x0d, 0xe1, 0x6f, 0xa8, 0xd3, 0x12, 0xab, 0x66, 0x48, 0x4d, 0xd9, 0x28, 0x03,
0x6c, 0x9d, 0x44, 0x7a, 0xed, 0xc9, 0x43, 0x4f, 0x9d, 0x4e, 0x3c, 0x7d, 0x0e, 0xff, 0x07, 0x87,
0xeb, 0xca, 0xca, 0x65, 0x6d, 0xbe, 0xc5, 0x31, 0x8b, 0xcc, 0x7e, 0x0a, 0x71, 0x4a, 0x4d, 0x9d,
0x3d, 0xfd, 0x7a, 0x56, 0x32, 0x8a, 0x6c, 0x6d, 0x9d, 0x2a, 0xd9, 0x8e, 0x68, 0x89, 0x63, 0xc6,
0x4f, 0x24, 0xd1, 0x2a, 0x72, 0x69, 0x08, 0x77, 0xa0, 0x7f, 0xfe, 0xc6, 0x33, 0x8d, 0xb4, 0x7d,
0x73, 0x91, 0x13, 0x9c, 0x47, 0x53, 0x6a, 0x13, 0xdf, 0x19, 0xc7, 0xed, 0x48, 0x81, 0xed, 0xd8,
0x1f, 0x11, 0x11, 0xbb, 0x41, 0x15, 0x5b, 0xa4, 0xf5, 0xc9, 0x2b, 0x48, 0x5e, 0xd8, 0x4b, 0x52,
0x1f, 0xf7, 0x87, 0xf2, 0x68, 0x25, 0x28, 0x79, 0xee, 0x39, 0x41, 0xc9, 0x0e, 0xc8, 0xf9, 0xf2,
0xd8, 0x24, 0x09, 0xb4, 0xd4, 0xb7, 0x90, 0xba, 0x26, 0xe8, 0x1d, 0xb4, 0xd7, 0x09, 0x00, 0xc4,
0xa0, 0xb6, 0x14, 0xe8, 0x4c, 0x29, 0x60, 0x54, 0x2e, 0x01, 0xde, 0x54, 0x66, 0x40, 0x22, 0x50,
0x27, 0xf1, 0xe7, 0x62, 0xa9, 0x00, 0x5a, 0x61, 0x2e, 0xfa, 0xfe, 0x16, 0xd8, 0xe0, 0xe7, 0x66,
0x17, 0xda, 0xb8, 0x0c, 0xa6, 0x04, 0x8d, 0xf8, 0x21, 0x68, 0x39
}

Definition at line 2368 of file bcrypt.c.

Referenced by test_RSA(), test_rsa_encrypt(), and test_RSA_SIGN().

◆ rsaPublicBlobWithInvalidPublicExpSize

UCHAR rsaPublicBlobWithInvalidPublicExpSize[]
static
Initial value:
=
{
0x52, 0x53, 0x41, 0x31, 0x00, 0x04, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x01, 0xc7, 0x8f, 0xac, 0x2a, 0xce, 0xbf, 0xc9, 0x6c, 0x7b,
0x85, 0x74, 0x71, 0xbb, 0xff, 0xbb, 0x9b, 0x20, 0x03, 0x79, 0x17, 0x34,
0xe7, 0x26, 0x91, 0x5c, 0x1f, 0x1b, 0x03, 0x3d, 0x46, 0xdf, 0xb6, 0xf2,
0x10, 0x55, 0xf0, 0x39, 0x55, 0x0a, 0xe3, 0x9c, 0x0c, 0x63, 0xc2, 0x14,
0x03, 0x94, 0x51, 0x0d, 0xb4, 0x22, 0x09, 0xf2, 0x5c, 0xb2, 0xd1, 0xc3,
0xac, 0x6f, 0xa8, 0xc4, 0xac, 0xb8, 0xbc, 0x59, 0xe7, 0xed, 0x77, 0x6e,
0xb1, 0x80, 0x58, 0x7d, 0xb2, 0x94, 0x46, 0xe5, 0x00, 0xe2, 0xb7, 0x33,
0x48, 0x7a, 0xd3, 0x78, 0xe9, 0x26, 0x01, 0xc7, 0x00, 0x7b, 0x41, 0x6d,
0x94, 0x3a, 0xe1, 0x50, 0x2b, 0x9f, 0x6b, 0x1c, 0x08, 0xa3, 0xfc, 0x0a,
0x44, 0x81, 0x09, 0x41, 0x80, 0x23, 0x7b, 0xf6, 0x3f, 0xaf, 0x91, 0xa1,
0x87, 0x75, 0x33, 0x15, 0xb8, 0xde, 0x32, 0x30, 0xb4, 0x5e, 0xfd
}

Definition at line 2504 of file bcrypt.c.

Referenced by test_RSA().

◆ rsaSignature

UCHAR rsaSignature[]
static
Initial value:
=
{
0xa8, 0x3a, 0x9d, 0xaf, 0x92, 0x94, 0xa4, 0x4d, 0x34, 0xba, 0x41, 0x0c, 0xc1, 0x23, 0x91, 0xc7,
0x91, 0xa8, 0xf8, 0xfc, 0x94, 0x87, 0x4d, 0x05, 0x85, 0x63, 0xe8, 0x7d, 0xea, 0x7f, 0x6b, 0x8d,
0xbb, 0x9a, 0xd4, 0x46, 0xa6, 0xc0, 0xd6, 0xdc, 0x91, 0xba, 0xd3, 0x1a, 0xbf, 0xf4, 0x52, 0xa0,
0xc7, 0x15, 0x87, 0xe9, 0x1e, 0x60, 0x49, 0x9c, 0xee, 0x5a, 0x9c, 0x6c, 0xbd, 0x7a, 0x3e, 0xc3,
0x48, 0xb3, 0xee, 0xca, 0x68, 0x40, 0x9b, 0xa1, 0x4c, 0x6e, 0x20, 0xd6, 0xca, 0x6c, 0x72, 0xaf,
0x2b, 0x6b, 0x62, 0x7c, 0x78, 0x06, 0x94, 0x4c, 0x02, 0xf3, 0x8d, 0x49, 0xe0, 0x11, 0xc4, 0x9b,
0x62, 0x5b, 0xc2, 0xfd, 0x68, 0xf4, 0x07, 0x15, 0x71, 0x11, 0x4c, 0x35, 0x97, 0x5d, 0xc0, 0xe6,
0x22, 0xc9, 0x8a, 0x7b, 0x96, 0xc9, 0xc3, 0xe4, 0x2b, 0x1e, 0x88, 0x17, 0x4f, 0x98, 0x9b, 0xf3,
0x42, 0x23, 0x0c, 0xa0, 0xfa, 0x19, 0x03, 0x2a, 0xf7, 0x13, 0x2d, 0x27, 0xac, 0x9f, 0xaf, 0x2d,
0xa3, 0xce, 0xf7, 0x63, 0xbb, 0x39, 0x9f, 0x72, 0x80, 0xdd, 0x6c, 0x73, 0x00, 0x85, 0x70, 0xf2,
0xed, 0x50, 0xed, 0xa0, 0x74, 0x42, 0xd7, 0x22, 0x46, 0x24, 0xee, 0x67, 0xdf, 0xb5, 0x45, 0xe8,
0x49, 0xf4, 0x9c, 0xe4, 0x00, 0x83, 0xf2, 0x27, 0x8e, 0xa2, 0xb1, 0xc3, 0xc2, 0x01, 0xd7, 0x59,
0x2e, 0x4d, 0xac, 0x49, 0xa2, 0xc1, 0x8d, 0x88, 0x4b, 0xfe, 0x28, 0xe5, 0xac, 0xa6, 0x85, 0xc4,
0x1f, 0xf8, 0xc5, 0xc5, 0x14, 0x4e, 0xa3, 0xcb, 0x17, 0xb7, 0x64, 0xb3, 0xc2, 0x12, 0xf8, 0xf8,
0x36, 0x99, 0x1c, 0x91, 0x9b, 0xbd, 0xed, 0x55, 0x0f, 0xfd, 0x49, 0x85, 0xbb, 0x32, 0xad, 0x78,
0xc1, 0x74, 0xe6, 0x7c, 0x18, 0x0f, 0x2b, 0x3b, 0xaa, 0xd1, 0x9d, 0x40, 0x71, 0x1d, 0x19, 0x53
}

Definition at line 2396 of file bcrypt.c.

Referenced by test_RSA(), and test_RSA_SIGN().

◆ salt

◆ salt_len

ULONG salt_len

◆ salt_NUL

UCHAR salt_NUL[] = "sa\0lt"
static

Definition at line 525 of file bcrypt.c.

◆ ULONG

Definition at line 30 of file bcrypt.c.

◆ ULONGLONG

Definition at line 42 of file bcrypt.c.