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
4a395899
Commit
4a395899
authored
Jul 28, 2022
by
Santino Mazza
Committed by
Alexandre Julliard
Aug 03, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bcrypt/tests: Test for BCryptEncrypt with RSA keys.
Signed-off-by:
Santino Mazza
<
mazzasantino1206@gmail.com
>
parent
68f6d6ba
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
117 additions
and
0 deletions
+117
-0
bcrypt.c
dlls/bcrypt/tests/bcrypt.c
+111
-0
bcrypt.h
include/bcrypt.h
+6
-0
No files found.
dlls/bcrypt/tests/bcrypt.c
View file @
4a395899
...
...
@@ -2019,6 +2019,114 @@ static UCHAR rsaPublicBlobWithInvalidPublicExpSize[] =
0x87
,
0x75
,
0x33
,
0x15
,
0xb8
,
0xde
,
0x32
,
0x30
,
0xb4
,
0x5e
,
0xfd
};
static
void
test_rsa_encrypt
(
void
)
{
static
UCHAR
input
[]
=
"Hello World!"
;
static
UCHAR
input_no_padding
[
64
]
=
{
0
};
BCRYPT_ALG_HANDLE
rsa
=
0
;
BCRYPT_KEY_HANDLE
key
=
0
;
NTSTATUS
ret
=
0
;
DWORD
encrypted_size
=
60
;
UCHAR
*
encrypted_a
=
NULL
;
UCHAR
*
encrypted_b
=
NULL
;
DWORD
decrypted_size
=
0
;
UCHAR
*
decrypted
=
NULL
;
BCRYPT_OAEP_PADDING_INFO
oaep_pad
;
oaep_pad
.
pszAlgId
=
BCRYPT_MD5_ALGORITHM
;
oaep_pad
.
pbLabel
=
(
PUCHAR
)
"test"
;
oaep_pad
.
cbLabel
=
5
;
BCryptOpenAlgorithmProvider
(
&
rsa
,
BCRYPT_RSA_ALGORITHM
,
NULL
,
0
);
BCryptGenerateKeyPair
(
rsa
,
&
key
,
512
,
0
);
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 */
memset
(
input_no_padding
,
0
,
sizeof
(
input_no_padding
));
strcpy
((
char
*
)
input_no_padding
,
"Hello World"
);
ret
=
BCryptEncrypt
(
key
,
input_no_padding
,
sizeof
(
input_no_padding
),
NULL
,
NULL
,
0
,
NULL
,
0
,
&
encrypted_size
,
BCRYPT_PAD_NONE
);
ok
(
ret
==
STATUS_SUCCESS
,
"got %lx
\n
"
,
ret
);
ok
(
encrypted_size
==
64
,
"got size of %ld
\n
"
,
encrypted_size
);
encrypted_a
=
malloc
(
encrypted_size
);
memset
(
encrypted_a
,
0
,
encrypted_size
);
encrypted_b
=
malloc
(
encrypted_size
);
memset
(
encrypted_b
,
0xff
,
encrypted_size
);
ret
=
BCryptEncrypt
(
key
,
input
,
sizeof
(
input
),
NULL
,
NULL
,
0
,
encrypted_a
,
encrypted_size
,
&
encrypted_size
,
BCRYPT_PAD_NONE
);
ok
(
ret
==
STATUS_INVALID_PARAMETER
,
"got %lx
\n
"
,
ret
);
ret
=
BCryptEncrypt
(
key
,
input_no_padding
,
sizeof
(
input_no_padding
),
NULL
,
NULL
,
0
,
encrypted_a
,
12
,
&
encrypted_size
,
BCRYPT_PAD_NONE
);
ok
(
ret
==
STATUS_BUFFER_TOO_SMALL
,
"got %lx
\n
"
,
ret
);
ret
=
BCryptEncrypt
(
key
,
input_no_padding
,
sizeof
(
input_no_padding
),
NULL
,
NULL
,
0
,
encrypted_a
,
encrypted_size
,
&
encrypted_size
,
BCRYPT_PAD_NONE
);
ok
(
ret
==
STATUS_SUCCESS
,
"got %lx
\n
"
,
ret
);
ret
=
BCryptEncrypt
(
key
,
input_no_padding
,
sizeof
(
input_no_padding
),
NULL
,
NULL
,
0
,
encrypted_b
,
encrypted_size
,
&
encrypted_size
,
BCRYPT_PAD_NONE
);
ok
(
ret
==
STATUS_SUCCESS
,
"got %lx
\n
"
,
ret
);
ok
(
!
memcmp
(
encrypted_a
,
encrypted_b
,
encrypted_size
),
"Both outputs should be the same
\n
"
);
BCryptDecrypt
(
key
,
encrypted_a
,
encrypted_size
,
NULL
,
NULL
,
0
,
NULL
,
0
,
&
decrypted_size
,
BCRYPT_PAD_NONE
);
decrypted
=
malloc
(
decrypted_size
);
BCryptDecrypt
(
key
,
encrypted_a
,
encrypted_size
,
NULL
,
NULL
,
0
,
decrypted
,
decrypted_size
,
&
decrypted_size
,
BCRYPT_PAD_NONE
);
ok
(
!
memcmp
(
decrypted
,
input_no_padding
,
sizeof
(
input_no_padding
)),
"Decrypted output it's not what expected
\n
"
);
free
(
decrypted
);
encrypted_size
=
60
;
/* PKCS1 Padding */
ret
=
BCryptEncrypt
(
key
,
input
,
sizeof
(
input
),
NULL
,
NULL
,
0
,
NULL
,
0
,
&
encrypted_size
,
BCRYPT_PAD_PKCS1
);
ok
(
ret
==
STATUS_SUCCESS
,
"got %lx
\n
"
,
ret
);
ok
(
encrypted_size
==
64
,
"got size of %ld
\n
"
,
encrypted_size
);
encrypted_a
=
realloc
(
encrypted_a
,
encrypted_size
);
memset
(
encrypted_a
,
0
,
encrypted_size
);
encrypted_b
=
realloc
(
encrypted_b
,
encrypted_size
);
memset
(
encrypted_b
,
0
,
encrypted_size
);
ret
=
BCryptEncrypt
(
key
,
input
,
sizeof
(
input
),
NULL
,
NULL
,
0
,
encrypted_a
,
encrypted_size
,
&
encrypted_size
,
BCRYPT_PAD_PKCS1
);
ok
(
ret
==
STATUS_SUCCESS
,
"got %lx
\n
"
,
ret
);
ret
=
BCryptEncrypt
(
key
,
input
,
sizeof
(
input
),
NULL
,
NULL
,
0
,
encrypted_b
,
encrypted_size
,
&
encrypted_size
,
BCRYPT_PAD_PKCS1
);
ok
(
ret
==
STATUS_SUCCESS
,
"got %lx
\n
"
,
ret
);
ok
(
memcmp
(
encrypted_a
,
encrypted_b
,
encrypted_size
),
"Both outputs are the same
\n
"
);
BCryptDecrypt
(
key
,
encrypted_a
,
encrypted_size
,
NULL
,
NULL
,
0
,
NULL
,
0
,
&
decrypted_size
,
BCRYPT_PAD_PKCS1
);
decrypted
=
malloc
(
decrypted_size
);
BCryptDecrypt
(
key
,
encrypted_a
,
encrypted_size
,
NULL
,
NULL
,
0
,
decrypted
,
decrypted_size
,
&
decrypted_size
,
BCRYPT_PAD_PKCS1
);
ok
(
!
memcmp
(
decrypted
,
input
,
sizeof
(
input
)),
"Decrypted output it's not what expected
\n
"
);
free
(
decrypted
);
encrypted_size
=
60
;
/* OAEP Padding */
ret
=
BCryptEncrypt
(
key
,
input
,
sizeof
(
input
),
&
oaep_pad
,
NULL
,
0
,
NULL
,
0
,
&
encrypted_size
,
BCRYPT_PAD_OAEP
);
ok
(
ret
==
STATUS_SUCCESS
,
"got %lx
\n
"
,
ret
);
ok
(
encrypted_size
==
64
,
"got size of %ld
\n
"
,
encrypted_size
);
encrypted_a
=
realloc
(
encrypted_a
,
encrypted_size
);
memset
(
encrypted_a
,
0
,
encrypted_size
);
encrypted_b
=
realloc
(
encrypted_b
,
encrypted_size
);
memset
(
encrypted_b
,
0
,
encrypted_size
);
ret
=
BCryptEncrypt
(
key
,
input
,
sizeof
(
input
),
&
oaep_pad
,
NULL
,
0
,
encrypted_a
,
encrypted_size
,
&
encrypted_size
,
BCRYPT_PAD_OAEP
);
ok
(
ret
==
STATUS_SUCCESS
,
"got %lx
\n
"
,
ret
);
ret
=
BCryptEncrypt
(
key
,
input
,
sizeof
(
input
),
&
oaep_pad
,
NULL
,
0
,
encrypted_b
,
encrypted_size
,
&
encrypted_size
,
BCRYPT_PAD_OAEP
);
ok
(
ret
==
STATUS_SUCCESS
,
"got %lx
\n
"
,
ret
);
ok
(
memcmp
(
encrypted_a
,
encrypted_b
,
encrypted_size
),
"Both outputs are the same
\n
"
);
BCryptDecrypt
(
key
,
encrypted_a
,
encrypted_size
,
&
oaep_pad
,
NULL
,
0
,
NULL
,
0
,
&
decrypted_size
,
BCRYPT_PAD_OAEP
);
decrypted
=
malloc
(
decrypted_size
);
BCryptDecrypt
(
key
,
encrypted_a
,
encrypted_size
,
&
oaep_pad
,
NULL
,
0
,
decrypted
,
decrypted_size
,
&
decrypted_size
,
BCRYPT_PAD_OAEP
);
ok
(
!
memcmp
(
decrypted
,
input
,
sizeof
(
input
)),
"Decrypted output it's not what expected
\n
"
);
}
free
(
decrypted
);
free
(
encrypted_a
);
free
(
encrypted_b
);
}
static
void
test_RSA
(
void
)
{
static
UCHAR
hash
[]
=
...
...
@@ -2202,6 +2310,9 @@ static void test_RSA(void)
ret
=
BCryptCloseAlgorithmProvider
(
alg
,
0
);
ok
(
!
ret
,
"got %#lx
\n
"
,
ret
);
/* RSA encryption */
test_rsa_encrypt
();
}
static
void
test_RSA_SIGN
(
void
)
...
...
include/bcrypt.h
View file @
4a395899
...
...
@@ -284,6 +284,12 @@ typedef struct _BCRYPT_PKCS1_PADDING_INFO
LPCWSTR
pszAlgId
;
}
BCRYPT_PKCS1_PADDING_INFO
;
typedef
struct
_BCRYPT_OAEP_PADDING_INFO
{
LPCWSTR
pszAlgId
;
PUCHAR
pbLabel
;
ULONG
cbLabel
;
}
BCRYPT_OAEP_PADDING_INFO
;
#define BCRYPT_PAD_NONE 0x00000001
#define BCRYPT_PAD_PKCS1 0x00000002
#define BCRYPT_PAD_OAEP 0x00000004
...
...
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