Skip to content

Commit

Permalink
use lowercase for parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
qmuntal committed Sep 4, 2024
1 parent 566095d commit 45e7f46
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions dsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (k *PublicKeyDSA) withKey(f func(C.GO_EVP_PKEY_PTR) C.int) C.int {
}

// GenerateDSAParameters generates a set of DSA parameters.
func GenerateDSAParameters(L, N int) (DSAParameters, error) {
func GenerateDSAParameters(l, n int) (DSAParameters, error) {
// The DSA parameters are generated by creating a new DSA key and
// extracting the domain parameters from it.

Expand All @@ -70,10 +70,10 @@ func GenerateDSAParameters(L, N int) (DSAParameters, error) {
if C.go_openssl_EVP_PKEY_paramgen_init(ctx) != 1 {
return DSAParameters{}, newOpenSSLError("EVP_PKEY_paramgen_init failed")
}
if C.go_openssl_EVP_PKEY_CTX_ctrl(ctx, C.GO_EVP_PKEY_DSA, -1, C.GO_EVP_PKEY_CTRL_DSA_PARAMGEN_BITS, C.int(L), nil) != 1 {
if C.go_openssl_EVP_PKEY_CTX_ctrl(ctx, C.GO_EVP_PKEY_DSA, -1, C.GO_EVP_PKEY_CTRL_DSA_PARAMGEN_BITS, C.int(l), nil) != 1 {
return DSAParameters{}, newOpenSSLError("EVP_PKEY_CTX_ctrl failed")
}
if C.go_openssl_EVP_PKEY_CTX_ctrl(ctx, C.GO_EVP_PKEY_DSA, -1, C.GO_EVP_PKEY_CTRL_DSA_PARAMGEN_Q_BITS, C.int(N), nil) != 1 {
if C.go_openssl_EVP_PKEY_CTX_ctrl(ctx, C.GO_EVP_PKEY_DSA, -1, C.GO_EVP_PKEY_CTRL_DSA_PARAMGEN_Q_BITS, C.int(n), nil) != 1 {
return DSAParameters{}, newOpenSSLError("EVP_PKEY_CTX_ctrl failed")
}
var pkey C.GO_EVP_PKEY_PTR
Expand Down Expand Up @@ -115,29 +115,29 @@ func GenerateDSAParameters(L, N int) (DSAParameters, error) {
}

// NewPrivateKeyDSA creates a new DSA private key from the given parameters.
func NewPrivateKeyDSA(params DSAParameters, X, Y BigInt) (*PrivateKeyDSA, error) {
if X == nil || Y == nil {
panic("X and Y must not be nil")
func NewPrivateKeyDSA(params DSAParameters, x, y BigInt) (*PrivateKeyDSA, error) {
if x == nil || y == nil {
panic("x and y must not be nil")
}
pkey, err := newDSA(params, X, Y)
pkey, err := newDSA(params, x, y)
if err != nil {
return nil, err
}
k := &PrivateKeyDSA{params, X, Y, pkey}
k := &PrivateKeyDSA{params, x, y, pkey}
runtime.SetFinalizer(k, (*PrivateKeyDSA).finalize)
return k, nil
}

// NewPublicKeyDSA creates a new DSA public key from the given parameters.
func NewPublicKeyDSA(params DSAParameters, Y BigInt) (*PublicKeyDSA, error) {
if Y == nil {
panic("Y must not be nil")
func NewPublicKeyDSA(params DSAParameters, y BigInt) (*PublicKeyDSA, error) {
if y == nil {
panic("y must not be nil")
}
pkey, err := newDSA(params, nil, Y)
pkey, err := newDSA(params, nil, y)
if err != nil {
return nil, err
}
k := &PublicKeyDSA{params, Y, pkey}
k := &PublicKeyDSA{params, y, pkey}
runtime.SetFinalizer(k, (*PublicKeyDSA).finalize)
return k, nil
}
Expand Down Expand Up @@ -184,18 +184,18 @@ func VerifyDSA(pub *PublicKeyDSA, hash []byte, sig []byte) bool {
return evpVerify(pub.withKey, 0, 0, 0, sig, hash) == nil
}

func newDSA(params DSAParameters, X, Y BigInt) (C.GO_EVP_PKEY_PTR, error) {
func newDSA(params DSAParameters, x, y BigInt) (C.GO_EVP_PKEY_PTR, error) {
switch vMajor {
case 1:
return newDSA1(params, X, Y)
return newDSA1(params, x, y)
case 3:
return newDSA3(params, X, Y)
return newDSA3(params, x, y)
default:
panic(errUnsupportedVersion())
}
}

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

dsa := C.go_openssl_DSA_new()
Expand All @@ -213,8 +213,8 @@ func newDSA1(params DSAParameters, X, Y BigInt) (C.GO_EVP_PKEY_PTR, error) {
C.go_openssl_DSA_free(dsa)
return nil, newOpenSSLError("DSA_set0_pqg failed")
}
if Y != nil {
pub, priv := bigToBN(Y), bigToBN(X)
if y != nil {
pub, priv := bigToBN(y), bigToBN(x)
if vMinor == 0 {
ret = C.go_openssl_DSA_set0_key_backport(dsa, pub, priv)
} else {
Expand Down Expand Up @@ -245,7 +245,7 @@ func newDSA1(params DSAParameters, X, Y BigInt) (C.GO_EVP_PKEY_PTR, error) {
return pkey, nil
}

func newDSA3(params DSAParameters, X, Y BigInt) (C.GO_EVP_PKEY_PTR, error) {
func newDSA3(params DSAParameters, x, y BigInt) (C.GO_EVP_PKEY_PTR, error) {
checkMajorVersion(3)

bld := C.go_openssl_OSSL_PARAM_BLD_new()
Expand All @@ -265,18 +265,18 @@ func newDSA3(params DSAParameters, X, Y BigInt) (C.GO_EVP_PKEY_PTR, error) {
return nil, newOpenSSLError("OSSL_PARAM_BLD_push_BN")
}
selection := C.int(C.GO_EVP_PKEY_KEYPAIR)
if Y != nil {
pub := bigToBN(Y)
if y != nil {
pub := bigToBN(y)
defer C.go_openssl_BN_free(pub)
if C.go_openssl_OSSL_PARAM_BLD_push_BN(bld, paramPubKey, pub) != 1 {
return nil, newOpenSSLError("OSSL_PARAM_BLD_push_BN")
}
if X == nil {
if x == nil {
selection = C.int(C.GO_EVP_PKEY_PUBLIC_KEY)
}
}
if X != nil {
priv := bigToBN(X)
if x != nil {
priv := bigToBN(x)
defer C.go_openssl_BN_clear_free(priv)
if C.go_openssl_OSSL_PARAM_BLD_push_BN(bld, paramPrivKey, priv) != 1 {
return nil, newOpenSSLError("OSSL_PARAM_BLD_push_BN")
Expand All @@ -291,7 +291,7 @@ func newDSA3(params DSAParameters, X, Y BigInt) (C.GO_EVP_PKEY_PTR, error) {
if err != nil {
return nil, err
}
if Y != nil {
if y != nil {
return pkey, nil
}
// pkey doesn't contain the public component, but the crypto/dsa expects
Expand Down

0 comments on commit 45e7f46

Please sign in to comment.