Also test DSA with the DER encoded key. Lots of help from jsing, thanks!
authortb <tb@openbsd.org>
Fri, 24 Aug 2018 17:34:46 +0000 (17:34 +0000)
committertb <tb@openbsd.org>
Fri, 24 Aug 2018 17:34:46 +0000 (17:34 +0000)
regress/lib/libcrypto/wycheproof/wycheproof.go

index a9db5f5..5bbfb7c 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: wycheproof.go,v 1.16 2018/08/23 19:46:59 tb Exp $ */
+/* $OpenBSD: wycheproof.go,v 1.17 2018/08/24 17:34:46 tb Exp $ */
 /*
  * Copyright (c) 2018 Joel Sing <jsing@openbsd.org>
  *
@@ -21,6 +21,8 @@ package main
 /*
 #cgo LDFLAGS: -lcrypto
 
+#include <string.h>
+
 #include <openssl/bn.h>
 #include <openssl/curve25519.h>
 #include <openssl/dsa.h>
@@ -450,12 +452,36 @@ func runDSATestGroup(wtg *wycheproofTestGroupDSA) bool {
                log.Fatalf("Failed to get hash: %v", err)
        }
 
+       der, err := hex.DecodeString(wtg.KeyDER)
+       if err != nil {
+               log.Fatalf("Failed to decode DER encoded key: %v", err)
+       }
+
+       derLen := len(der)
+       if derLen == 0 {
+               der = append(der, 0)
+       }
+
+       Cder := (*C.uchar)(C.malloc((C.ulong)(derLen)))
+       if Cder == nil {
+               log.Fatal("malloc failed")
+       }
+       C.memcpy(unsafe.Pointer(Cder), unsafe.Pointer(&der[0]), C.ulong(derLen))
+
+       p := (*C.uchar)(Cder)
+       dsaDER := C.d2i_DSA_PUBKEY(nil, (**C.uchar)(&p), C.long(derLen))
+       defer C.DSA_free(dsaDER)
+       C.free(unsafe.Pointer(Cder))
+
        /// XXX audit acceptable cases
        success := true
        for _, wt := range wtg.Tests {
                if !runDSATest(dsa, h, wt) {
                        success = false
                }
+               if !runDSATest(dsaDER, h, wt) {
+                       success = false
+               }
        }
        return success
 }