Skip to content

Commit

Permalink
Merge pull request #563 from alex/better-constant-time-docs
Browse files Browse the repository at this point in the history
More clearly describe the behavior of constant_time.bytes_eq
  • Loading branch information
reaperhulk committed Feb 5, 2014
2 parents 3eb7a9e + e6c41b0 commit 48ef0c1
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions docs/hazmat/primitives/constant-time.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ about the timing attacks on KeyCzar and Java's ``MessageDigest.isEqual()``.

.. function:: bytes_eq(a, b)

Compare ``a`` and ``b`` to one another in constant time if they are of the
same length.
Compares ``a`` and ``b`` with one another. If ``a`` and ``b`` have
different lengths, this returns ``False`` immediately. Otherwise it
compares them in a way that takes the same amount of time, regardless of
how many characters are the same between the two.

.. doctest::

Expand All @@ -30,9 +32,10 @@ about the timing attacks on KeyCzar and Java's ``MessageDigest.isEqual()``.
>>> constant_time.bytes_eq(b"foo", b"bar")
False

:param a bytes: The left-hand side.
:param b bytes: The right-hand side.
:returns boolean: True if ``a`` has the same bytes as ``b``.
:param bytes a: The left-hand side.
:param bytes b: The right-hand side.
:returns bool: ``True`` if ``a`` has the same bytes as ``b``, otherwise
``False``.


.. _`Coda Hale's blog post`: http://codahale.com/a-lesson-in-timing-attacks/

0 comments on commit 48ef0c1

Please sign in to comment.