Advertisement
Guest User

Untitled

a guest
May 10th, 2018
595
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. int compareKey() {
  2. unsigned int leng = strleng(keyInput);
  3. unsigned int correctLeng = strleng(correctKey);
  4. int i, randomTime, falseKey = 0;
  5.  
  6. unsigned int seed = getpid() + keyInput[0];
  7. srand(seed); // initialize the random seed
  8.  
  9. if (leng != correctLeng)
  10. return 1;
  11.  
  12. for (i = correctLeng-1; i >= 0; i--) {
  13. if (keyInput[i] != correctKey[i]) {
  14. usleep(500000); // that delay will stop bruteforce attack
  15.  
  16. falseKey = 1;
  17. }
  18. }
  19. randomTime = 500000 * (rand() % 3);
  20. usleep(randomTime); // take that
  21. // and this will prevent the attacker to perform a timed attack
  22.  
  23. return falseKey;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement