Skip to content

Commit a496169

Browse files
committed
fix openssl 3
1 parent 1e911ba commit a496169

File tree

5 files changed

+27
-19
lines changed

5 files changed

+27
-19
lines changed

dsa.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ func newDSA3(params DSAParameters, x, y BigInt) (C.GO_EVP_PKEY_PTR, error) {
280280
return nil, err
281281
}
282282
defer C.go_openssl_OSSL_PARAM_free(bldparams)
283-
pkey, err := newEvpFromParams(C.GO_EVP_PKEY_DSA, selection, bldparams, false)
283+
pkey, err := newEvpFromParams(C.GO_EVP_PKEY_DSA, selection, bldparams)
284284
if err != nil {
285285
return nil, err
286286
}

ecdh.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,28 @@ func newECDHPkey3(nid C.int, bytes []byte, isPrivate bool) (C.GO_EVP_PKEY_PTR, e
210210
return nil, err
211211
}
212212
defer C.go_openssl_OSSL_PARAM_free(params)
213-
return newEvpFromParams(C.GO_EVP_PKEY_EC, selection, params, true)
213+
pkey, err := newEvpFromParams(C.GO_EVP_PKEY_EC, selection, params)
214+
if err != nil {
215+
return nil, err
216+
}
217+
ctx := C.go_openssl_EVP_PKEY_CTX_new(pkey, nil)
218+
if ctx == nil {
219+
return nil, newOpenSSLError("EVP_PKEY_CTX_new")
220+
}
221+
defer C.go_openssl_EVP_PKEY_CTX_free(ctx)
222+
if isPrivate {
223+
if C.go_openssl_EVP_PKEY_private_check(ctx) != 1 {
224+
// Match upstream error message.
225+
return nil, errors.New("crypto/ecdh: invalid private key")
226+
}
227+
} else {
228+
// Upstream Go does a partial check here, so do we.
229+
if C.go_openssl_EVP_PKEY_public_check_quick(ctx) != 1 {
230+
// Match upstream error message.
231+
return nil, errors.New("crypto/ecdh: invalid public key")
232+
}
233+
}
234+
return pkey, nil
214235
}
215236

216237
func pointMult(group C.GO_EC_GROUP_PTR, priv C.GO_BIGNUM_PTR) (C.GO_EC_POINT_PTR, error) {

ecdsa.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,5 +207,5 @@ func newECDSAKey3(nid C.int, bx, by, bd C.GO_BIGNUM_PTR) (C.GO_EVP_PKEY_PTR, err
207207
return nil, err
208208
}
209209
defer C.go_openssl_OSSL_PARAM_free(params)
210-
return newEvpFromParams(C.GO_EVP_PKEY_EC, selection, params, false)
210+
return newEvpFromParams(C.GO_EVP_PKEY_EC, selection, params)
211211
}

evp.go

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ func getECKey(pkey C.GO_EVP_PKEY_PTR) (key C.GO_EC_KEY_PTR) {
502502
return key
503503
}
504504

505-
func newEvpFromParams(id C.int, selection C.int, params C.GO_OSSL_PARAM_PTR, validate bool) (C.GO_EVP_PKEY_PTR, error) {
505+
func newEvpFromParams(id C.int, selection C.int, params C.GO_OSSL_PARAM_PTR) (C.GO_EVP_PKEY_PTR, error) {
506506
ctx := C.go_openssl_EVP_PKEY_CTX_new_id(id, nil)
507507
if ctx == nil {
508508
return nil, newOpenSSLError("EVP_PKEY_CTX_new_id")
@@ -515,18 +515,5 @@ func newEvpFromParams(id C.int, selection C.int, params C.GO_OSSL_PARAM_PTR, val
515515
if C.go_openssl_EVP_PKEY_fromdata(ctx, &pkey, selection, params) != 1 {
516516
return nil, newOpenSSLError("EVP_PKEY_fromdata")
517517
}
518-
if validate {
519-
if selection == C.GO_EVP_PKEY_KEYPAIR { // Private key
520-
if C.go_openssl_EVP_PKEY_private_check(ctx) != 1 {
521-
// Match upstream error message.
522-
return nil, errors.New("crypto/ecdh: invalid private key")
523-
}
524-
} else { // Public key
525-
if C.go_openssl_EVP_PKEY_public_check_quick(ctx) != 1 {
526-
// Match upstream error message.
527-
return nil, errors.New("crypto/ecdh: invalid public key")
528-
}
529-
}
530-
}
531518
return pkey, nil
532519
}

rsa.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ func saltLength(saltLen int, sign bool) (C.int, error) {
238238
// A salt length of -2 is valid in OpenSSL, but not in crypto/rsa, so reject
239239
// it, and lengths < -2, before we convert to the OpenSSL sentinel values.
240240
if saltLen <= -2 {
241-
return 0, errors.New("crypto/rsa: PSSOptions.SaltLength cannot be negative")
241+
return 0, errors.New("crypto/rsa: invalid PSS salt length")
242242
}
243243
// OpenSSL uses sentinel salt length values like Go crypto does,
244244
// but the values don't fully match for rsa.PSSSaltLengthAuto (0).
@@ -404,5 +404,5 @@ func newRSAKey3(isPriv bool, n, e, d, p, q, dp, dq, qinv BigInt) (C.GO_EVP_PKEY_
404404
if isPriv {
405405
selection = C.GO_EVP_PKEY_KEYPAIR
406406
}
407-
return newEvpFromParams(C.GO_EVP_PKEY_RSA, C.int(selection), params, false)
407+
return newEvpFromParams(C.GO_EVP_PKEY_RSA, C.int(selection), params)
408408
}

0 commit comments

Comments
 (0)