Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for crypto/dsa #135

Merged
merged 24 commits into from
Sep 12, 2024
Merged
Changes from 2 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions dsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,19 @@ func newDSA(params DSAParameters, x, y BigInt) (C.GO_EVP_PKEY_PTR, error) {
}
}

func newDSA1(params DSAParameters, x, y BigInt) (C.GO_EVP_PKEY_PTR, error) {
func newDSA1(params DSAParameters, x, y BigInt) (pkey C.GO_EVP_PKEY_PTR, err error) {
checkMajorVersion(1)

dsa := C.go_openssl_DSA_new()
if dsa == nil {
return nil, newOpenSSLError("DSA_new failed")
}
defer func() {
if pkey == nil {
C.go_openssl_DSA_free(dsa)
}
}()

p, q, g := bigToBN(params.P), bigToBN(params.Q), bigToBN(params.G)
var ret C.int
if vMinor == 0 {
Expand All @@ -212,7 +221,6 @@ func newDSA1(params DSAParameters, x, y BigInt) (C.GO_EVP_PKEY_PTR, error) {
C.go_openssl_BN_free(p)
C.go_openssl_BN_free(q)
C.go_openssl_BN_free(g)
C.go_openssl_DSA_free(dsa)
return nil, newOpenSSLError("DSA_set0_pqg failed")
}
if y != nil {
Expand All @@ -225,22 +233,18 @@ func newDSA1(params DSAParameters, x, y BigInt) (C.GO_EVP_PKEY_PTR, error) {
if ret != 1 {
C.go_openssl_BN_free(pub)
C.go_openssl_BN_clear_free(priv)
C.go_openssl_DSA_free(dsa)
return nil, newOpenSSLError("DSA_set0_key failed")
}
} else {
if C.go_openssl_DSA_generate_key(dsa) != 1 {
C.go_openssl_DSA_free(dsa)
return nil, newOpenSSLError("DSA_generate_key failed")
}
}
pkey := C.go_openssl_EVP_PKEY_new()
pkey = C.go_openssl_EVP_PKEY_new()
if pkey == nil {
C.go_openssl_DSA_free(dsa)
return nil, newOpenSSLError("EVP_PKEY_new failed")
}
if C.go_openssl_EVP_PKEY_assign(pkey, C.GO_EVP_PKEY_DSA, unsafe.Pointer(dsa)) != 1 {
C.go_openssl_DSA_free(dsa)
dagood marked this conversation as resolved.
Show resolved Hide resolved
C.go_openssl_EVP_PKEY_free(pkey)
return nil, newOpenSSLError("EVP_PKEY_assign failed")
}
Expand All @@ -264,6 +268,7 @@ func newDSA3(params DSAParameters, x, y BigInt) (C.GO_EVP_PKEY_PTR, error) {
if C.go_openssl_OSSL_PARAM_BLD_push_BN(bld, OSSL_PKEY_PARAM_FFC_P, p) != 1 ||
C.go_openssl_OSSL_PARAM_BLD_push_BN(bld, OSSL_PKEY_PARAM_FFC_Q, q) != 1 ||
C.go_openssl_OSSL_PARAM_BLD_push_BN(bld, OSSL_PKEY_PARAM_FFC_G, g) != 1 {

return nil, newOpenSSLError("OSSL_PARAM_BLD_push_BN")
}
selection := C.int(C.GO_EVP_PKEY_KEYPAIR)
Expand Down Expand Up @@ -296,9 +301,9 @@ func newDSA3(params DSAParameters, x, y BigInt) (C.GO_EVP_PKEY_PTR, error) {
if y != nil {
return pkey, nil
}
// pkey doesn't contain the public component, but the crypto/dsa expects
// it to be always there. Generate a new key using pkey as domain parameters
// placeholder.
// pkey doesn't contain the public component, but the crypto/dsa package
// expects it to be always there. Generate a new key using pkey as domain
// parameters placeholder.
defer C.go_openssl_EVP_PKEY_free(pkey)
ctx := C.go_openssl_EVP_PKEY_CTX_new_from_pkey(nil, pkey, nil)
if ctx == nil {
Expand Down
Loading