Skip to content
This repository has been archived by the owner on Jul 28, 2022. It is now read-only.

Commit

Permalink
Add constant time explaination
Browse files Browse the repository at this point in the history
  • Loading branch information
lstrojny authored and jordisala1991 committed Mar 17, 2018
1 parent f4f4be1 commit f874c50
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/GoogleAuthenticator.php
Expand Up @@ -78,6 +78,14 @@ public function __construct(int $passCodeLength = 6, int $secretLength = 10, \Da
*/
public function checkCode($secret, $code): bool
{
/**
* The result of each comparison is accumulated here instead of using a guard clause
* (https://refactoring.com/catalog/replaceNestedConditionalWithGuardClauses.html). This is to implement
* constant time comparison to make side-channel attacks harder. See
* https://cryptocoding.net/index.php/Coding_rules#Compare_secret_strings_in_constant_time for details.
* Each comparison uses hash_equals() instead of an operator to implement constant time equality comparison
* for each code.
*/
$result = 0;

// current period
Expand Down

0 comments on commit f874c50

Please sign in to comment.