Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-cw
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wine
wine-cw
Commits
6f5028dd
Commit
6f5028dd
authored
Sep 10, 2022
by
Hans Leidekker
Committed by
Alexandre Julliard
Sep 13, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bcrypt: Add full support for algorithm pseudo-handles.
parent
f527e4a6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
142 additions
and
10 deletions
+142
-10
bcrypt_internal.h
dlls/bcrypt/bcrypt_internal.h
+3
-2
bcrypt_main.c
dlls/bcrypt/bcrypt_main.c
+0
-0
bcrypt.c
dlls/bcrypt/tests/bcrypt.c
+80
-6
bcrypt.h
include/bcrypt.h
+59
-2
No files found.
dlls/bcrypt/bcrypt_internal.h
View file @
6f5028dd
...
...
@@ -146,10 +146,11 @@ enum alg_id
enum
mode_id
{
MODE_ID_ECB
,
MODE_ID_CBC
,
MODE_ID_
GCM
,
MODE_ID_
ECB
,
MODE_ID_CFB
,
MODE_ID_CCM
,
MODE_ID_GCM
,
};
struct
algorithm
...
...
dlls/bcrypt/bcrypt_main.c
View file @
6f5028dd
This diff is collapsed.
Click to expand it.
dlls/bcrypt/tests/bcrypt.c
View file @
6f5028dd
...
...
@@ -63,8 +63,12 @@ static void test_BCryptGenRandom(void)
{
ret
=
BCryptGenRandom
(
BCRYPT_RNG_ALG_HANDLE
,
buffer
,
sizeof
(
buffer
),
0
);
ok
(
ret
==
STATUS_SUCCESS
,
"Expected success, got %#lx
\n
"
,
ret
);
ret
=
BCryptCloseAlgorithmProvider
(
BCRYPT_RNG_ALG_HANDLE
,
0
);
ok
(
ret
==
STATUS_INVALID_HANDLE
,
"got %#lx
\n
"
,
ret
);
}
else
win_skip
(
"BCryptGenRandom pseudo handles are not available
\n
"
);
}
static
void
test_BCryptGetFipsAlgorithmMode
(
void
)
...
...
@@ -323,6 +327,14 @@ static void test_hash(const struct hash_test *test)
ret
=
BCryptCloseAlgorithmProvider
(
alg
,
0
);
ok
(
ret
==
STATUS_SUCCESS
,
"got %#lx
\n
"
,
ret
);
if
(
pBCryptHash
)
{
ret
=
BCryptCreateHash
(
BCRYPT_SHA1_ALG_HANDLE
,
&
hash
,
NULL
,
0
,
NULL
,
0
,
0
);
ok
(
ret
==
STATUS_SUCCESS
,
"got %#lx
\n
"
,
ret
);
ret
=
BCryptDestroyHash
(
hash
);
ok
(
ret
==
STATUS_SUCCESS
,
"got %#lx
\n
"
,
ret
);
}
}
static
void
test_hashes
(
void
)
...
...
@@ -433,6 +445,15 @@ static void test_BcryptHash(void)
ret
=
BCryptCloseAlgorithmProvider
(
alg
,
0
);
ok
(
ret
==
STATUS_SUCCESS
,
"got %#lx
\n
"
,
ret
);
if
(
pBCryptHash
)
{
memset
(
md5
,
0
,
sizeof
(
md5
));
ret
=
pBCryptHash
(
BCRYPT_MD5_ALG_HANDLE
,
NULL
,
0
,
(
UCHAR
*
)
"test"
,
sizeof
(
"test"
),
md5
,
sizeof
(
md5
));
ok
(
ret
==
STATUS_SUCCESS
,
"got %#lx
\n
"
,
ret
);
format_hash
(
md5
,
sizeof
(
md5
),
str
);
ok
(
!
strcmp
(
str
,
expected
),
"got %s
\n
"
,
str
);
}
}
/* test vectors from RFC 6070 */
...
...
@@ -502,6 +523,13 @@ static void test_BcryptDeriveKeyPBKDF2(void)
ret
=
BCryptCloseAlgorithmProvider
(
alg
,
0
);
ok
(
ret
==
STATUS_SUCCESS
,
"got %#lx
\n
"
,
ret
);
if
(
pBCryptHash
)
{
ret
=
BCryptDeriveKeyPBKDF2
(
BCRYPT_HMAC_SHA1_ALG_HANDLE
,
rfc6070
[
0
].
pwd
,
rfc6070
[
0
].
pwd_len
,
rfc6070
[
0
].
salt
,
rfc6070
[
0
].
salt_len
,
1
,
buf
,
rfc6070
[
0
].
dk_len
,
0
);
ok
(
ret
==
STATUS_SUCCESS
,
"got %#lx
\n
"
,
ret
);
}
}
static
void
test_rng
(
void
)
...
...
@@ -610,6 +638,19 @@ static void test_aes(void)
ret
=
BCryptCloseAlgorithmProvider
(
alg
,
0
);
ok
(
ret
==
STATUS_SUCCESS
,
"got %#lx
\n
"
,
ret
);
if
(
pBCryptHash
)
{
ret
=
BCryptSetProperty
(
BCRYPT_AES_CBC_ALG_HANDLE
,
BCRYPT_CHAINING_MODE
,
(
UCHAR
*
)
BCRYPT_CHAIN_MODE_GCM
,
0
,
0
);
ok
(
ret
==
STATUS_ACCESS_DENIED
,
"got %#lx
\n
"
,
ret
);
size
=
0
;
memset
(
mode
,
0
,
sizeof
(
mode
));
ret
=
BCryptGetProperty
(
BCRYPT_AES_CBC_ALG_HANDLE
,
BCRYPT_CHAINING_MODE
,
mode
,
sizeof
(
mode
),
&
size
,
0
);
ok
(
ret
==
STATUS_SUCCESS
,
"got %#lx
\n
"
,
ret
);
ok
(
!
lstrcmpW
((
const
WCHAR
*
)
mode
,
BCRYPT_CHAIN_MODE_CBC
),
"got %s
\n
"
,
wine_dbgstr_w
((
const
WCHAR
*
)
mode
));
ok
(
size
==
64
,
"got %lu
\n
"
,
size
);
}
}
static
void
test_3des
(
void
)
...
...
@@ -687,7 +728,7 @@ static void test_BCryptGenerateSymmetricKey(void)
BCRYPT_KEY_HANDLE
key
,
key2
;
UCHAR
*
buf
,
ciphertext
[
16
],
plaintext
[
16
],
ivbuf
[
16
],
mode
[
64
];
BCRYPT_KEY_LENGTHS_STRUCT
key_lengths
;
ULONG
size
,
len
,
i
;
ULONG
size
,
len
,
len2
,
i
;
NTSTATUS
ret
;
DWORD
keylen
;
...
...
@@ -697,6 +738,7 @@ static void test_BCryptGenerateSymmetricKey(void)
len
=
size
=
0xdeadbeef
;
ret
=
BCryptGetProperty
(
aes
,
BCRYPT_OBJECT_LENGTH
,
(
UCHAR
*
)
&
len
,
sizeof
(
len
),
&
size
,
0
);
ok
(
ret
==
STATUS_SUCCESS
,
"got %#lx
\n
"
,
ret
);
len2
=
len
;
key
=
(
void
*
)
0xdeadbeef
;
ret
=
BCryptGenerateSymmetricKey
(
NULL
,
&
key
,
NULL
,
0
,
secret
,
sizeof
(
secret
),
0
);
...
...
@@ -848,8 +890,16 @@ static void test_BCryptGenerateSymmetricKey(void)
ret
=
BCryptDestroyKey
(
key
);
ok
(
ret
==
STATUS_SUCCESS
,
"got %#lx
\n
"
,
ret
);
free
(
buf
);
if
(
pBCryptHash
)
{
ret
=
BCryptGenerateSymmetricKey
(
BCRYPT_AES_CBC_ALG_HANDLE
,
&
key
,
buf
,
len2
,
secret
,
sizeof
(
secret
),
0
);
ok
(
ret
==
STATUS_SUCCESS
,
"got %#lx
\n
"
,
ret
);
ret
=
BCryptDestroyKey
(
key
);
ok
(
ret
==
STATUS_SUCCESS
,
"got %#lx
\n
"
,
ret
);
}
free
(
buf
);
ret
=
BCryptCloseAlgorithmProvider
(
aes
,
0
);
ok
(
ret
==
STATUS_SUCCESS
,
"got %#lx
\n
"
,
ret
);
}
...
...
@@ -1949,11 +1999,18 @@ static void test_key_import_export(void)
ret
=
BCryptImportKey
(
aes
,
NULL
,
BCRYPT_OPAQUE_KEY_BLOB
,
&
key
,
NULL
,
0
,
buf
,
size
,
0
);
ok
(
ret
==
STATUS_SUCCESS
,
"got %#lx
\n
"
,
ret
);
ok
(
key
!=
NULL
,
"key not set
\n
"
);
free
(
buf
);
ret
=
BCryptDestroyKey
(
key
);
ok
(
ret
==
STATUS_SUCCESS
,
"got %#lx
\n
"
,
ret
);
if
(
pBCryptHash
)
{
ret
=
BCryptImportKey
(
BCRYPT_AES_CBC_ALG_HANDLE
,
NULL
,
BCRYPT_OPAQUE_KEY_BLOB
,
&
key
,
NULL
,
0
,
buf
,
size
,
0
);
ok
(
ret
==
STATUS_SUCCESS
,
"got %#lx
\n
"
,
ret
);
BCryptDestroyKey
(
key
);
}
free
(
buf
);
ret
=
BCryptCloseAlgorithmProvider
(
aes
,
0
);
ok
(
ret
==
STATUS_SUCCESS
,
"got %#lx
\n
"
,
ret
);
}
...
...
@@ -2029,6 +2086,14 @@ static void test_ECDSA(void)
ok
(
!
status
,
"BCryptImportKeyPair failed: %#lx
\n
"
,
status
);
BCryptDestroyKey
(
key
);
if
(
pBCryptHash
)
{
status
=
BCryptImportKeyPair
(
BCRYPT_ECDSA_P256_ALG_HANDLE
,
NULL
,
BCRYPT_PUBLIC_KEY_BLOB
,
&
key
,
buffer
,
size
,
0
);
ok
(
!
status
,
"BCryptImportKeyPair failed: %#lx
\n
"
,
status
);
BCryptDestroyKey
(
key
);
}
status
=
BCryptImportKeyPair
(
alg
,
NULL
,
BCRYPT_ECCPUBLIC_BLOB
,
&
key
,
buffer
,
size
,
0
);
ok
(
!
status
,
"BCryptImportKeyPair failed: %#lx
\n
"
,
status
);
...
...
@@ -2208,14 +2273,15 @@ static void test_rsa_encrypt(void)
oaep_pad
.
pbLabel
=
(
PUCHAR
)
"test"
;
oaep_pad
.
cbLabel
=
5
;
BCryptOpenAlgorithmProvider
(
&
rsa
,
BCRYPT_RSA_ALGORITHM
,
NULL
,
0
);
BCryptGenerateKeyPair
(
rsa
,
&
key
,
512
,
0
);
ret
=
BCryptOpenAlgorithmProvider
(
&
rsa
,
BCRYPT_RSA_ALGORITHM
,
NULL
,
0
);
ok
(
ret
==
STATUS_SUCCESS
,
"got %lx
\n
"
,
ret
);
ret
=
BCryptGenerateKeyPair
(
rsa
,
&
key
,
512
,
0
);
ok
(
ret
==
STATUS_SUCCESS
,
"got %lx
\n
"
,
ret
);
todo_wine
{
/* Not finalized key */
ret
=
BCryptEncrypt
(
key
,
input
,
sizeof
(
input
),
NULL
,
NULL
,
0
,
NULL
,
0
,
&
encrypted_size
,
0
);
ok
(
ret
==
STATUS_INVALID_HANDLE
,
"got %lx
\n
"
,
ret
);
BCryptFinalizeKeyPair
(
key
,
0
);
/* No padding */
...
...
@@ -2300,6 +2366,14 @@ static void test_rsa_encrypt(void)
free
(
encrypted_a
);
free
(
encrypted_b
);
BCryptDestroyKey
(
key
);
if
(
pBCryptHash
)
{
ret
=
BCryptGenerateKeyPair
(
BCRYPT_RSA_ALG_HANDLE
,
&
key
,
512
,
0
);
ok
(
ret
==
STATUS_SUCCESS
,
"got %lx
\n
"
,
ret
);
BCryptDestroyKey
(
key
);
}
}
static
void
test_RSA
(
void
)
...
...
include/bcrypt.h
View file @
6f5028dd
...
...
@@ -401,8 +401,65 @@ typedef PVOID BCRYPT_HANDLE;
typedef
PVOID
BCRYPT_HASH_HANDLE
;
typedef
PVOID
BCRYPT_SECRET_HANDLE
;
/* Pseudo handles for BCryptGenRandom */
#define BCRYPT_RNG_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x00000081)
/* Pseudo handles */
#define BCRYPT_MD2_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x00000001)
#define BCRYPT_MD4_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x00000011)
#define BCRYPT_MD5_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x00000021)
#define BCRYPT_SHA1_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x00000031)
#define BCRYPT_SHA256_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x00000041)
#define BCRYPT_SHA384_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x00000051)
#define BCRYPT_SHA512_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x00000061)
#define BCRYPT_RC4_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x00000071)
#define BCRYPT_RNG_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x00000081)
#define BCRYPT_HMAC_MD5_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x00000091)
#define BCRYPT_HMAC_SHA1_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x000000a1)
#define BCRYPT_HMAC_SHA256_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x000000b1)
#define BCRYPT_HMAC_SHA384_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x000000c1)
#define BCRYPT_HMAC_SHA512_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x000000d1)
#define BCRYPT_RSA_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x000000e1)
#define BCRYPT_ECDSA_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x000000f1)
#define BCRYPT_AES_CMAC_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x00000101)
#define BCRYPT_AES_GMAC_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x00000111)
#define BCRYPT_HMAC_MD2_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x00000121)
#define BCRYPT_HMAC_MD4_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x00000131)
#define BCRYPT_3DES_CBC_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x00000141)
#define BCRYPT_3DES_ECB_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x00000151)
#define BCRYPT_3DES_CFB_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x00000161)
#define BCRYPT_3DES_112_CBC_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x00000171)
#define BCRYPT_3DES_112_ECB_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x00000181)
#define BCRYPT_3DES_112_CFB_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x00000191)
#define BCRYPT_AES_CBC_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x000001a1)
#define BCRYPT_AES_ECB_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x000001b1)
#define BCRYPT_AES_CFB_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x000001c1)
#define BCRYPT_AES_CCM_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x000001d1)
#define BCRYPT_AES_GCM_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x000001e1)
#define BCRYPT_DES_CBC_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x000001f1)
#define BCRYPT_DES_ECB_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x00000201)
#define BCRYPT_DES_CFB_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x00000211)
#define BCRYPT_DESX_CBC_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x00000221)
#define BCRYPT_DESX_ECB_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x00000231)
#define BCRYPT_DESX_CFB_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x00000241)
#define BCRYPT_RC2_CBC_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x00000251)
#define BCRYPT_RC2_ECB_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x00000261)
#define BCRYPT_RC2_CFB_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x00000271)
#define BCRYPT_DH_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x00000281)
#define BCRYPT_ECDH_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x00000291)
#define BCRYPT_ECDH_P256_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x000002a1)
#define BCRYPT_ECDH_P384_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x000002b1)
#define BCRYPT_ECDH_P521_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x000002c1)
#define BCRYPT_DSA_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x000002d1)
#define BCRYPT_ECDSA_P256_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x000002e1)
#define BCRYPT_ECDSA_P384_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x000002f1)
#define BCRYPT_ECDSA_P521_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x00000301)
#define BCRYPT_RSA_SIGN_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x00000311)
#define BCRYPT_CAPI_KDF_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x00000321)
#define BCRYPT_PBKDF2_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x00000331)
#define BCRYPT_SP800108_CTR_HMAC_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x00000341)
#define BCRYPT_SP80056A_CONCAT_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x00000351)
#define BCRYPT_TLS1_1_KDF_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x00000361)
#define BCRYPT_TLS1_2_KDF_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x00000371)
#define BCRYPT_XTS_AES_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x00000381)
#define BCRYPT_HKDF_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x00000391)
/* Flags for BCryptGenRandom */
#define BCRYPT_RNG_USE_ENTROPY_IN_BUFFER 0x00000001
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment