<br><div class="gmail_quote">def streq_const_time(s1, s2):<br><br>    if len(s1) != len(s2):<br>        return False<br>    result = 0<br>    for (a, b) in zip(s1, s2):<br>        result |= ord(a) ^ ord(b)<br>    return result == 0<br>
<br>+++++++++++++++++++++++++++++++++++++++++<br>
<br>If s1 and s2 are of the same length,  then the function will compare every <br>characters in them.  I think it may be more efficient as follow:<br><br>def streq_const_time(s1, s2):<br>
<br>
    if len(s1) != len(s2):<br>
        return False<br>
    result = 0<br>
    for (a, b) in zip(s1, s2):<br>
        if ord(a) ^ ord(b):<br>          return False<br>    return True<br><br>
</div><br>