From 8b6d5a12cd81344fe18cd3c8978281e7f46896c3 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Sun, 22 Apr 2018 19:17:55 +0200 Subject: [PATCH] [client:client.internal] implemented 'rescue(y1, y2) error' for extracting response data + rescuing key --- .../schastsp/client/client.internal.go | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/git.xdrm.io/schastsp/client/client.internal.go b/src/git.xdrm.io/schastsp/client/client.internal.go index b4770d1..98ca375 100644 --- a/src/git.xdrm.io/schastsp/client/client.internal.go +++ b/src/git.xdrm.io/schastsp/client/client.internal.go @@ -266,4 +266,39 @@ func (c *T) generateRequest(x1 []byte, x2 []byte) error { } return nil; +} + + + +/* (5) Rescue management +* +* @Y1<[]byte> First rescue parameter +* @Y2<[]byte> Second rescue parameter +* +* @return err The error or NIL if not +* +---------------------------------------------------------*/ +func (c *T) rescue(y1 []byte, y2 []byte) error { + + /* (1) Extract time mod */ + timeMod := uint32( xor.ByteArray(y1, y2)[0] % 2 ) + + /* (2) Try to guess time id from timeM */ + timeId := timeid.Guess(c.ctx.Window(), timeMod); + var timeIdBytes []byte; + binary.BigEndian.PutUint32(timeIdBytes, timeId) + + /* (3) Hash timeId */ + hashedTimeId, err := scha.Hash(timeIdBytes, 1, nil, nil); + if err != nil { return err } + + /* (4) Get the received hash */ + receivedHash := xor.ByteArray(y1, hashedTimeId); + + /* (4) Try to rescue the key */ + err = c.key.Rescue(receivedHash) + + /* (5) Dispatch error */ + return err + } \ No newline at end of file