From eb1d60f2c0c9e41fa148f7e9791732113e11dd00 Mon Sep 17 00:00:00 2001 From: George Tankersley Date: Wed, 9 Oct 2019 23:25:01 -0400 Subject: [PATCH] merlin: add complex protocol test from dalek merlin --- merlin.go | 4 +++- merlin_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/merlin.go b/merlin.go index 6ec5061..bdafa80 100644 --- a/merlin.go +++ b/merlin.go @@ -63,5 +63,7 @@ func (t *Transcript) ExtractBytes(label []byte, outLen int) []byte { t.s.AD(true, labelSize) // a PRF call directly to the output buffer would be better - return t.s.PRF(outLen) + outBytes := t.s.PRF(outLen) + fmt.Printf("PRF : %x\n", outBytes) + return outBytes } diff --git a/merlin_test.go b/merlin_test.go index 6cd2e87..4499f9f 100644 --- a/merlin_test.go +++ b/merlin_test.go @@ -26,3 +26,27 @@ func TestSimpleTranscript(t *testing.T) { t.Errorf("\nGot : %s\nWant: %s", cHex, expectedHex) } } + +func TestComplexTranscript(t *testing.T) { + tr := NewTranscript("test protocol") + tr.AppendMessage([]byte("step1"), []byte("some data")) + + data := make([]byte, 1024) + for i := range data { + data[i] = 99 + } + + var chlBytes []byte + for i := 0; i < 32; i++ { + chlBytes = tr.ExtractBytes([]byte("challenge"), 32) + tr.AppendMessage([]byte("bigdata"), data) + tr.AppendMessage([]byte("challengedata"), chlBytes) + } + + expectedChlHex := "a8c933f54fae76e3f9bea93648c1308e7dfa2152dd51674ff3ca438351cf003c" + chlHex := fmt.Sprintf("%x", chlBytes) + + if chlHex != expectedChlHex { + t.Errorf("\nGot : %s\nWant: %s", chlHex, expectedChlHex) + } +}