Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
shrapnel
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
shrapnel
Commits
b4079484
Commit
b4079484
authored
Apr 01, 2015
by
Sam Rushing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pkey.encrypt() using EVP_PKEY_encrypt.
parent
f023cfe3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
0 deletions
+30
-0
coro/ssl/openssl.pxi
coro/ssl/openssl.pxi
+7
-0
coro/ssl/openssl.pyx
coro/ssl/openssl.pyx
+23
-0
No files found.
coro/ssl/openssl.pxi
View file @
b4079484
...
...
@@ -153,6 +153,13 @@ cdef extern from "openssl/evp.h":
int
EVP_SignFinal
(
EVP_MD_CTX
*
,
char
*
,
int
*
,
EVP_PKEY
*
)
int
EVP_VerifyFinal
(
EVP_MD_CTX
*
,
char
*
,
int
,
EVP_PKEY
*
)
int
EVP_MAX_MD_SIZE
# --- public key encryption ---
ctypedef
struct
EVP_PKEY_CTX
# NOTE: replacing ENGINE * with void * here, we otherwise have no support for ENGINE.
EVP_PKEY_CTX
*
EVP_PKEY_CTX_new
(
EVP_PKEY
*
,
void
*
)
void
EVP_PKEY_CTX_free
(
EVP_PKEY_CTX
*
)
int
EVP_PKEY_encrypt_init
(
EVP_PKEY_CTX
*
)
int
EVP_PKEY_encrypt
(
EVP_PKEY_CTX
*
,
unsigned
char
*
,
size_t
*
,
const
unsigned
char
*
,
size_t
)
cdef
extern
from
"openssl/ec.h"
:
ctypedef
struct
EC_KEY
...
...
coro/ssl/openssl.pyx
View file @
b4079484
...
...
@@ -188,6 +188,29 @@ cdef class pkey:
def
bits
(
self
):
return
self
.
_bits
()
def
encrypt
(
self
,
bytes
iblock
):
cdef
size_t
outlen
=
0
cdef
bytes
oblock
# NOTE: no engine support yet...
cdef
EVP_PKEY_CTX
*
ctx
=
EVP_PKEY_CTX_new
(
self
.
pkey
,
NULL
)
if
ctx
is
NULL
:
raise_ssl_error
()
else
:
try
:
if
EVP_PKEY_encrypt_init
(
ctx
)
!=
1
:
raise_ssl_error
()
else
:
if
EVP_PKEY_encrypt
(
ctx
,
NULL
,
&
outlen
,
iblock
,
len
(
iblock
))
!=
1
:
raise_ssl_error
()
else
:
oblock
=
PyBytes_FromStringAndSize
(
NULL
,
outlen
)
if
EVP_PKEY_encrypt
(
ctx
,
oblock
,
&
outlen
,
iblock
,
len
(
iblock
))
!=
1
:
raise_ssl_error
()
else
:
return
oblock
finally
:
EVP_PKEY_CTX_free
(
ctx
)
# compatibility
def
read_pem_key
(
pem
,
pwd
):
return
pkey
(
pem
,
pwd
,
True
)
...
...
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