-/* $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>
*
/*
#cgo LDFLAGS: -lcrypto
+#include <string.h>
+
#include <openssl/bn.h>
#include <openssl/curve25519.h>
#include <openssl/dsa.h>
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
}