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