Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-winehq
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-winehq
Commits
d70c8e46
Commit
d70c8e46
authored
Sep 29, 2020
by
Alexandre Julliard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bcrypt: Add a helper function to create an asymmetric key.
Signed-off-by:
Alexandre Julliard
<
julliard@winehq.org
>
parent
65013aae
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
62 deletions
+27
-62
bcrypt_main.c
dlls/bcrypt/bcrypt_main.c
+27
-62
No files found.
dlls/bcrypt/bcrypt_main.c
View file @
d70c8e46
...
...
@@ -854,6 +854,24 @@ NTSTATUS WINAPI BCryptHash( BCRYPT_ALG_HANDLE algorithm, UCHAR *secret, ULONG se
return
BCryptDestroyHash
(
handle
);
}
static
NTSTATUS
key_asymmetric_create
(
struct
key
**
ret_key
,
struct
algorithm
*
alg
,
ULONG
bitlen
,
const
UCHAR
*
pubkey
,
ULONG
pubkey_len
)
{
struct
key
*
key
;
NTSTATUS
status
;
if
(
!
(
key
=
heap_alloc_zero
(
sizeof
(
*
key
)
)))
return
STATUS_NO_MEMORY
;
key
->
hdr
.
magic
=
MAGIC_KEY
;
if
((
status
=
key_asymmetric_init
(
key
,
alg
,
bitlen
,
pubkey
,
pubkey_len
)))
{
heap_free
(
key
);
return
status
;
}
*
ret_key
=
key
;
return
STATUS_SUCCESS
;
}
#if defined(HAVE_GNUTLS_CIPHER_INIT) || defined(HAVE_COMMONCRYPTO_COMMONCRYPTOR_H) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1080
BOOL
key_is_symmetric
(
struct
key
*
key
)
{
...
...
@@ -1175,18 +1193,8 @@ static NTSTATUS key_import_pair( struct algorithm *alg, const WCHAR *type, BCRYP
if
(
ecc_blob
->
cbKey
!=
key_size
||
input_len
<
sizeof
(
*
ecc_blob
)
+
ecc_blob
->
cbKey
*
2
)
return
STATUS_INVALID_PARAMETER
;
if
(
!
(
key
=
heap_alloc_zero
(
sizeof
(
*
key
)
)))
return
STATUS_NO_MEMORY
;
key
->
hdr
.
magic
=
MAGIC_KEY
;
size
=
sizeof
(
*
ecc_blob
)
+
ecc_blob
->
cbKey
*
2
;
if
((
status
=
key_asymmetric_init
(
key
,
alg
,
key_size
*
8
,
(
BYTE
*
)
ecc_blob
,
size
)))
{
heap_free
(
key
);
return
status
;
}
*
ret_key
=
key
;
return
STATUS_SUCCESS
;
return
key_asymmetric_create
(
(
struct
key
**
)
ret_key
,
alg
,
key_size
*
8
,
(
BYTE
*
)
ecc_blob
,
size
);
}
else
if
(
!
strcmpW
(
type
,
BCRYPT_ECCPRIVATE_BLOB
))
{
...
...
@@ -1215,17 +1223,10 @@ static NTSTATUS key_import_pair( struct algorithm *alg, const WCHAR *type, BCRYP
if
(
ecc_blob
->
cbKey
!=
key_size
||
input_len
<
sizeof
(
*
ecc_blob
)
+
ecc_blob
->
cbKey
*
3
)
return
STATUS_INVALID_PARAMETER
;
if
(
!
(
key
=
heap_alloc_zero
(
sizeof
(
*
key
)
)))
return
STATUS_NO_MEMORY
;
key
->
hdr
.
magic
=
MAGIC_KEY
;
if
((
status
=
key_asymmetric_init
(
key
,
alg
,
key_size
*
8
,
NULL
,
0
)))
{
heap_free
(
key
);
return
status
;
}
if
((
status
=
key_asymmetric_create
(
&
key
,
alg
,
key_size
*
8
,
NULL
,
0
)))
return
status
;
if
((
status
=
key_import_ecc
(
key
,
input
,
input_len
)))
{
heap_free
(
key
);
BCryptDestroyKey
(
key
);
return
status
;
}
...
...
@@ -1241,18 +1242,8 @@ static NTSTATUS key_import_pair( struct algorithm *alg, const WCHAR *type, BCRYP
if
((
alg
->
id
!=
ALG_ID_RSA
&&
alg
->
id
!=
ALG_ID_RSA_SIGN
)
||
rsa_blob
->
Magic
!=
BCRYPT_RSAPUBLIC_MAGIC
)
return
STATUS_NOT_SUPPORTED
;
if
(
!
(
key
=
heap_alloc_zero
(
sizeof
(
*
key
)
)))
return
STATUS_NO_MEMORY
;
key
->
hdr
.
magic
=
MAGIC_KEY
;
size
=
sizeof
(
*
rsa_blob
)
+
rsa_blob
->
cbPublicExp
+
rsa_blob
->
cbModulus
;
if
((
status
=
key_asymmetric_init
(
key
,
alg
,
rsa_blob
->
BitLength
,
(
BYTE
*
)
rsa_blob
,
size
)))
{
heap_free
(
key
);
return
status
;
}
*
ret_key
=
key
;
return
STATUS_SUCCESS
;
return
key_asymmetric_create
(
(
struct
key
**
)
ret_key
,
alg
,
rsa_blob
->
BitLength
,
(
BYTE
*
)
rsa_blob
,
size
);
}
else
if
(
!
strcmpW
(
type
,
BCRYPT_DSA_PUBLIC_BLOB
))
{
...
...
@@ -1263,18 +1254,8 @@ static NTSTATUS key_import_pair( struct algorithm *alg, const WCHAR *type, BCRYP
if
((
alg
->
id
!=
ALG_ID_DSA
)
||
dsa_blob
->
dwMagic
!=
BCRYPT_DSA_PUBLIC_MAGIC
)
return
STATUS_NOT_SUPPORTED
;
if
(
!
(
key
=
heap_alloc_zero
(
sizeof
(
*
key
)
)))
return
STATUS_NO_MEMORY
;
key
->
hdr
.
magic
=
MAGIC_KEY
;
size
=
sizeof
(
*
dsa_blob
)
+
dsa_blob
->
cbKey
*
3
;
if
((
status
=
key_asymmetric_init
(
key
,
alg
,
dsa_blob
->
cbKey
*
8
,
(
BYTE
*
)
dsa_blob
,
size
)))
{
heap_free
(
key
);
return
status
;
}
*
ret_key
=
key
;
return
STATUS_SUCCESS
;
return
key_asymmetric_create
(
(
struct
key
**
)
ret_key
,
alg
,
dsa_blob
->
cbKey
*
8
,
(
BYTE
*
)
dsa_blob
,
size
);
}
else
if
(
!
strcmpW
(
type
,
LEGACY_DSA_V2_PRIVATE_BLOB
))
{
...
...
@@ -1301,17 +1282,10 @@ static NTSTATUS key_import_pair( struct algorithm *alg, const WCHAR *type, BCRYP
if
(
input_len
<
sizeof
(
*
hdr
)
+
sizeof
(
*
pubkey
)
+
(
pubkey
->
bitlen
/
8
)
*
2
+
40
+
sizeof
(
DSSSEED
))
return
STATUS_INVALID_PARAMETER
;
if
(
!
(
key
=
heap_alloc_zero
(
sizeof
(
*
key
)
)))
return
STATUS_NO_MEMORY
;
key
->
hdr
.
magic
=
MAGIC_KEY
;
if
((
status
=
key_asymmetric_init
(
key
,
alg
,
pubkey
->
bitlen
,
NULL
,
0
)))
{
heap_free
(
key
);
return
status
;
}
if
((
status
=
key_asymmetric_create
(
&
key
,
alg
,
pubkey
->
bitlen
,
NULL
,
0
)))
return
status
;
if
((
status
=
key_import_dsa_capi
(
key
,
input
,
input_len
)))
{
heap_free
(
key
);
BCryptDestroyKey
(
key
);
return
status
;
}
...
...
@@ -1465,17 +1439,8 @@ NTSTATUS WINAPI BCryptGenerateKeyPair( BCRYPT_ALG_HANDLE algorithm, BCRYPT_KEY_H
if
(
!
alg
||
alg
->
hdr
.
magic
!=
MAGIC_ALG
)
return
STATUS_INVALID_HANDLE
;
if
(
!
handle
)
return
STATUS_INVALID_PARAMETER
;
if
(
!
(
key
=
heap_alloc_zero
(
sizeof
(
*
key
)
)))
return
STATUS_NO_MEMORY
;
key
->
hdr
.
magic
=
MAGIC_KEY
;
if
((
status
=
key_asymmetric_init
(
key
,
alg
,
key_len
,
NULL
,
0
)))
{
heap_free
(
key
);
return
status
;
}
*
handle
=
key
;
return
STATUS_SUCCESS
;
if
(
!
(
status
=
key_asymmetric_create
(
&
key
,
alg
,
key_len
,
NULL
,
0
)))
*
handle
=
key
;
return
status
;
}
NTSTATUS
WINAPI
BCryptFinalizeKeyPair
(
BCRYPT_KEY_HANDLE
handle
,
ULONG
flags
)
...
...
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