From c9af87a89b408f489390e1ac577f575764f25eec Mon Sep 17 00:00:00 2001 From: Kris Kwiatkowski Date: Wed, 22 Aug 2018 15:03:50 +0100 Subject: [PATCH] Final version of the test --- src/runner.go | 195 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 119 insertions(+), 76 deletions(-) diff --git a/src/runner.go b/src/runner.go index 418217d..3e7e66b 100644 --- a/src/runner.go +++ b/src/runner.go @@ -11,15 +11,25 @@ import rand "crypto/rand" import sidh "github.com/henrydcase/nobs/dh/sidh" import sike "github.com/henrydcase/nobs/kem/sike" import "unsafe" +import "runtime" const ( - CSKsz = 644 - GSKsz = 80 // 80 because MSR concatenates public key to the secret key + GSKsz = 32+48 // 80=(MSG+KeySize). + CSKsz = 644 // 80+public key size, which MSR concatenates with secret key PKsz = 564 CTsz = 596 SSsz = 24 ) +func FailNow() { + pc := make([]uintptr, 10) // at least 1 entry needed + runtime.Callers(2, pc) + f := runtime.FuncForPC(pc[0]) + file, line := f.FileLine(pc[0]) + fmt.Printf("%s:%d %s\n", file, line, f.Name()) + panic(0) +} + // Helpers for byte convertion // ------------------------------ @@ -69,34 +79,28 @@ func keygenCf() (*sidh.PublicKey, *sidh.PrivateKey) { } // MSR keygen -// MSR Encapsulate -// CF Decapsulate -func test_msrK_msrE_cfD() { - var msrCipherText [CTsz]C.uchar - var ss2 [SSsz]C.uchar - var msrSK [CSKsz]C.uchar +// CF Encapsulate +// MSR Decapsulate +func test_msrK_cfE_msrD() { + var cCT [CTsz]C.uchar + var cSS [SSsz]C.uchar + var cSK [CSKsz]C.uchar pubKey, prvKey := keygenMsr() - ctext, ss1, err := sike.Encapsulate(rand.Reader, pubKey) + gCT, gSS, err := sike.Encapsulate(rand.Reader, pubKey) if err != nil { panic(0) } - - for i,_:=range(ctext) { - msrCipherText[i] = C.uchar(ctext[i]) - } - - convBytesGoToC(prvKey.Export(), msrSK[:]) - convBytesGoToC(pubKey.Export(), msrSK[80:]) - if C.crypto_kem_dec_SIKEp751(&msrSK[0], &msrCipherText[0], &ss2[0]) != 0 { + convBytesGoToC(gCT, cCT[:]) + convBytesGoToC(prvKey.Export(), cSK[:]) + convBytesGoToC(pubKey.Export(), cSK[80:]) + if C.crypto_kem_dec_SIKEp751(&cSS[0], &cCT[0], &cSK[0]) != 0 { panic(0) } - for _,i:=range(ss2) { - if byte(ss2[i]) != ss1[i] { - fmt.Printf("LEN=%d %X\n", len(ss2), ss2) - // fmt.Printf("LEN=%d %X\n", len(ss1), ss1) + for i:=0; i