Skip to content

Commit e402ef5

Browse files
authored
implement SupportsDSA (#187)
1 parent 6189676 commit e402ef5

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

dsa.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ var (
1717
OSSL_PKEY_PARAM_FFC_G = C.CString("g")
1818
)
1919

20+
// SupportsDSA returns true if the OpenSSL library supports DSA.
21+
func SupportsDSA() bool {
22+
ctx := C.go_openssl_EVP_PKEY_CTX_new_id(C.GO_EVP_PKEY_DSA, nil)
23+
if ctx == nil {
24+
return false
25+
}
26+
C.go_openssl_EVP_PKEY_CTX_free(ctx)
27+
return true
28+
}
29+
2030
// DSAParameters contains the DSA parameters.
2131
type DSAParameters struct {
2232
P, Q, G BigInt

dsa_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ type dsaSignature struct {
1616
}
1717

1818
func TestDSAGenerateParameters(t *testing.T) {
19+
if !openssl.SupportsDSA() {
20+
t.Skip("DSA is not supported")
21+
}
22+
1923
var tests = []struct {
2024
L, N int
2125
}{
@@ -128,9 +132,13 @@ func testDSASignAndVerify(t *testing.T, priv *openssl.PrivateKeyDSA) {
128132
}
129133

130134
func TestDSASignAndVerify(t *testing.T) {
135+
if !openssl.SupportsDSA() {
136+
t.Skip("DSA is not supported")
137+
}
131138
if openssl.FIPS() {
132139
t.Skip("DSA signing with L = 2048 is not supported in FIPS mode")
133140
}
141+
134142
params := openssl.DSAParameters{
135143
P: bbig.Enc(fromHex("A9B5B793FB4785793D246BAE77E8FF63CA52F442DA763C440259919FE1BC1D6065A9350637A04F75A2F039401D49F08E066C4D275A5A65DA5684BC563C14289D7AB8A67163BFBF79D85972619AD2CFF55AB0EE77A9002B0EF96293BDD0F42685EBB2C66C327079F6C98000FBCB79AACDE1BC6F9D5C7B1A97E3D9D54ED7951FEF")),
136144
Q: bbig.Enc(fromHex("E1D3391245933D68A0714ED34BBCB7A1F422B9C1")),
@@ -147,6 +155,10 @@ func TestDSASignAndVerify(t *testing.T) {
147155
}
148156

149157
func TestDSANewPrivateKeyWithDegenerateKeys(t *testing.T) {
158+
if !openssl.SupportsDSA() {
159+
t.Skip("DSA is not supported")
160+
}
161+
150162
// Signing with degenerate private keys should not cause an infinite loop
151163
badKeys := []struct {
152164
p, q, g, y, x string
@@ -175,6 +187,10 @@ func TestDSANewPrivateKeyWithDegenerateKeys(t *testing.T) {
175187
}
176188

177189
func TestDSANewPublicKeyWithBadPublicKey(t *testing.T) {
190+
if !openssl.SupportsDSA() {
191+
t.Skip("DSA is not supported")
192+
}
193+
178194
params := openssl.DSAParameters{
179195
P: bbig.Enc(fromHex("A9B5B793FB4785793D246BAE77E8FF63CA52F442DA763C440259919FE1BC1D6065A9350637A04F75A2F039401D49F08E066C4D275A5A65DA5684BC563C14289D7AB8A67163BFBF79D85972619AD2CFF55AB0EE77A9002B0EF96293BDD0F42685EBB2C66C327079F6C98000FBCB79AACDE1BC6F9D5C7B1A97E3D9D54ED7951FEF")),
180196
Q: bbig.Enc(fromHex("FA")),

0 commit comments

Comments
 (0)