@@ -14,6 +14,7 @@ func TestECDH(t *testing.T) {
1414 for _ , tt := range []string {"P-256" , "P-384" , "P-521" , "X25519" } {
1515 t .Run (tt , func (t * testing.T ) {
1616 name := tt
17+ skipUnsupportedCurve (t , name )
1718 aliceKey , alicPrivBytes , err := openssl .GenerateKeyECDH (name )
1819 if err != nil {
1920 t .Fatal (err )
@@ -121,6 +122,7 @@ var ecdhvectors = []struct {
121122func TestECDHVectors (t * testing.T ) {
122123 for _ , tt := range ecdhvectors {
123124 t .Run (tt .Name , func (t * testing.T ) {
125+ skipUnsupportedCurve (t , tt .Name )
124126 key , err := openssl .NewPrivateKeyECDH (tt .Name , hexDecode (t , tt .PrivateKey ))
125127 if err != nil {
126128 t .Fatal (err )
@@ -285,6 +287,7 @@ var invalidECDHPublicKeys = map[string][]string{
285287func TestECDHNewPrivateKeyECDH_Invalid (t * testing.T ) {
286288 for _ , curve := range []string {"P-256" , "P-384" , "P-521" , "X25519" } {
287289 t .Run (curve , func (t * testing.T ) {
290+ skipUnsupportedCurve (t , curve )
288291 for _ , input := range invalidECDHPrivateKeys [curve ] {
289292 k , err := openssl .NewPrivateKeyECDH (curve , hexDecode (t , input ))
290293 if err == nil {
@@ -300,6 +303,7 @@ func TestECDHNewPrivateKeyECDH_Invalid(t *testing.T) {
300303func TestECDHNewPublicKeyECDH_Invalid (t * testing.T ) {
301304 for _ , curve := range []string {"P-256" , "P-384" , "P-521" , "X25519" } {
302305 t .Run (curve , func (t * testing.T ) {
306+ skipUnsupportedCurve (t , curve )
303307 for _ , input := range invalidECDHPublicKeys [curve ] {
304308 k , err := openssl .NewPublicKeyECDH (curve , hexDecode (t , input ))
305309 if err == nil {
@@ -313,6 +317,7 @@ func TestECDHNewPublicKeyECDH_Invalid(t *testing.T) {
313317}
314318
315319func TestX25519Failure (t * testing.T ) {
320+ skipUnsupportedCurve (t , "X25519" )
316321 identity := hexDecode (t , "0000000000000000000000000000000000000000000000000000000000000000" )
317322 lowOrderPoint := hexDecode (t , "e0eb7a7c3b41b8ae1656e3faf19fc46ada098deb9c32b1fd866205165f49b800" )
318323 randomScalar := make ([]byte , 32 )
@@ -340,3 +345,10 @@ func testX25519Failure(t *testing.T, private, public []byte) {
340345 t .Errorf ("unexpected ECDH output: %x" , secret )
341346 }
342347}
348+
349+ func skipUnsupportedCurve (t * testing.T , curve string ) {
350+ t .Helper ()
351+ if ! openssl .SupportsCurve (curve ) {
352+ t .Skipf ("skipping test: curve %q is not supported" , curve )
353+ }
354+ }
0 commit comments