Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
p2p
go-openssl
Commits
c26b4563
Commit
c26b4563
authored
Dec 15, 2017
by
Christopher Dudley
Committed by
Jeff
Jan 05, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change error checking style to match existing code.
parent
76896156
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
21 deletions
+10
-21
dh.go
dh.go
+4
-8
key.go
key.go
+6
-13
No files found.
dh.go
View file @
c26b4563
...
...
@@ -34,21 +34,18 @@ func DeriveSharedSecret(private PrivateKey, public PublicKey) ([]byte, error) {
defer
C
.
EVP_PKEY_CTX_free
(
dhCtx
)
// Initialize the context
rc
:=
C
.
EVP_PKEY_derive_init
(
dhCtx
)
if
rc
!=
1
{
if
int
(
C
.
EVP_PKEY_derive_init
(
dhCtx
))
!=
1
{
return
nil
,
errors
.
New
(
"failed initializing shared secret derivation context"
)
}
// Provide the peer's public key
rc
=
C
.
EVP_PKEY_derive_set_peer
(
dhCtx
,
public
.
evpPKey
())
if
rc
!=
1
{
if
int
(
C
.
EVP_PKEY_derive_set_peer
(
dhCtx
,
public
.
evpPKey
()))
!=
1
{
return
nil
,
errors
.
New
(
"failed adding peer public key to context"
)
}
// Determine how large of a buffer we need for the shared secret
var
buffLen
C
.
size_t
rc
=
C
.
EVP_PKEY_derive
(
dhCtx
,
nil
,
&
buffLen
)
if
rc
!=
1
{
if
int
(
C
.
EVP_PKEY_derive
(
dhCtx
,
nil
,
&
buffLen
))
!=
1
{
return
nil
,
errors
.
New
(
"failed determining shared secret length"
)
}
...
...
@@ -60,8 +57,7 @@ func DeriveSharedSecret(private PrivateKey, public PublicKey) ([]byte, error) {
defer
C
.
X_OPENSSL_free
(
buffer
)
// Derive the shared secret
rc
=
C
.
EVP_PKEY_derive
(
dhCtx
,
(
*
C
.
uchar
)(
buffer
),
&
buffLen
)
if
rc
!=
1
{
if
int
(
C
.
EVP_PKEY_derive
(
dhCtx
,
(
*
C
.
uchar
)(
buffer
),
&
buffLen
))
!=
1
{
return
nil
,
errors
.
New
(
"failed deriving the shared secret"
)
}
...
...
key.go
View file @
c26b4563
...
...
@@ -193,8 +193,7 @@ func (key *pKey) MarshalPKIXPublicKeyPEM() (pem_block []byte,
}
defer
C
.
BIO_free
(
bio
)
rc
:=
C
.
PEM_write_bio_PUBKEY
(
bio
,
key
.
key
)
if
rc
!=
1
{
if
int
(
C
.
PEM_write_bio_PUBKEY
(
bio
,
key
.
key
))
!=
1
{
return
nil
,
errors
.
New
(
"failed dumping public key pem"
)
}
...
...
@@ -374,7 +373,6 @@ func GenerateRSAKeyWithExponent(bits int, exponent int) (PrivateKey, error) {
// GenerateECKey generates a new elliptic curve private key on the speicified
// curve.
func
GenerateECKey
(
curve
EllipticCurve
)
(
PrivateKey
,
error
)
{
var
rc
C
.
int
// Create context for parameter generation
paramCtx
:=
C
.
EVP_PKEY_CTX_new_id
(
C
.
EVP_PKEY_EC
,
nil
)
...
...
@@ -384,21 +382,18 @@ func GenerateECKey(curve EllipticCurve) (PrivateKey, error) {
defer
C
.
EVP_PKEY_CTX_free
(
paramCtx
)
// Intialize the parameter generation
rc
=
C
.
EVP_PKEY_paramgen_init
(
paramCtx
)
if
rc
!=
1
{
if
int
(
C
.
EVP_PKEY_paramgen_init
(
paramCtx
))
!=
1
{
return
nil
,
errors
.
New
(
"failed initializing EC parameter generation context"
)
}
// Set curve in EC parameter generation context
rc
=
C
.
X_EVP_PKEY_CTX_set_ec_paramgen_curve_nid
(
paramCtx
,
C
.
int
(
curve
))
if
rc
!=
1
{
if
int
(
C
.
X_EVP_PKEY_CTX_set_ec_paramgen_curve_nid
(
paramCtx
,
C
.
int
(
curve
)))
!=
1
{
return
nil
,
errors
.
New
(
"failed setting curve in EC parameter generation context"
)
}
// Create parameter object
var
params
*
C
.
EVP_PKEY
rc
=
C
.
EVP_PKEY_paramgen
(
paramCtx
,
&
params
)
if
rc
!=
1
{
if
int
(
C
.
EVP_PKEY_paramgen
(
paramCtx
,
&
params
))
!=
1
{
return
nil
,
errors
.
New
(
"failed creating EC key generation parameters"
)
}
defer
C
.
EVP_PKEY_free
(
params
)
...
...
@@ -412,12 +407,10 @@ func GenerateECKey(curve EllipticCurve) (PrivateKey, error) {
// Generate the key
var
privKey
*
C
.
EVP_PKEY
rc
=
C
.
EVP_PKEY_keygen_init
(
keyCtx
)
if
rc
!=
1
{
if
int
(
C
.
EVP_PKEY_keygen_init
(
keyCtx
))
!=
1
{
return
nil
,
errors
.
New
(
"failed initializing EC key generation context"
)
}
rc
=
C
.
EVP_PKEY_keygen
(
keyCtx
,
&
privKey
)
if
rc
!=
1
{
if
int
(
C
.
EVP_PKEY_keygen
(
keyCtx
,
&
privKey
))
!=
1
{
return
nil
,
errors
.
New
(
"failed generating EC private key"
)
}
...
...
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