[client:client.internal] implemented 'rescue(y1, y2) error' for extracting response data + rescuing key

This commit is contained in:
xdrm-brackets 2018-04-22 19:17:55 +02:00
parent d759e85735
commit 8b6d5a12cd
1 changed files with 35 additions and 0 deletions

View File

@ -266,4 +266,39 @@ func (c *T) generateRequest(x1 []byte, x2 []byte) error {
} }
return nil; return nil;
}
/* (5) Rescue management
*
* @Y1<[]byte> First rescue parameter
* @Y2<[]byte> Second rescue parameter
*
* @return err<error> 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
} }