Skip to content

Commit

Permalink
use sodium_hex2bin() and _bin2hex() to resist timing / side channel a…
Browse files Browse the repository at this point in the history
…ttacks
  • Loading branch information
pavarnos committed Aug 12, 2018
1 parent 447c7a3 commit fb7132b
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/Threema/MsgApi/Encryptor/SodiumEncryptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,35 @@ public function getDescription()
return 'Sodium implementation ' . SODIUM_LIBRARY_VERSION;
}

/**
* Converts a binary string to an hexadecimal string.
*
* This is the same as PHP s bin2hex() implementation, but it is resistant to
* timing attacks.
*
* @param string $binaryString The binary string to convert
* @return string
*/
public function bin2hex($binaryString)
{
return sodium_bin2hex($binaryString);
}

/**
* Converts an hexadecimal string to a binary string.
*
* This is the same as PHP s hex2bin() implementation, but it is resistant to
* timing attacks.
*
* @param string $hexString The hex string to convert
* @param string|null $ignore (optional) Characters to ignore
* @return string
*/
public function hex2bin($hexString, $ignore = null)
{
return sodium_hex2bin($hexString, $ignore);
}

/**
* @param string $data
* @param string $nonce
Expand Down

0 comments on commit fb7132b

Please sign in to comment.