From 4f26b9f54486f216177e26315cde22c55f6a749b Mon Sep 17 00:00:00 2001 From: tb Date: Fri, 24 Aug 2018 17:34:46 +0000 Subject: [PATCH] Also test DSA with the DER encoded key. Lots of help from jsing, thanks! --- .../lib/libcrypto/wycheproof/wycheproof.go | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/regress/lib/libcrypto/wycheproof/wycheproof.go b/regress/lib/libcrypto/wycheproof/wycheproof.go index a9db5f530ab..5bbfb7c2af7 100644 --- a/regress/lib/libcrypto/wycheproof/wycheproof.go +++ b/regress/lib/libcrypto/wycheproof/wycheproof.go @@ -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 * @@ -21,6 +21,8 @@ package main /* #cgo LDFLAGS: -lcrypto +#include + #include #include #include @@ -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 } -- 2.20.1