aboutsummaryrefslogtreecommitdiffstats
path: root/docs/hazmat/primitives/constant-time.rst
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2013-12-15 23:09:13 -0800
committerAlex Gaynor <alex.gaynor@gmail.com>2013-12-15 23:09:13 -0800
commit5175e4e6394ade40e38dc00b8e1e14a2877aafe4 (patch)
treece9073684c790f908044f939e92312ad82112514 /docs/hazmat/primitives/constant-time.rst
parent973499aded3ce3580a8c6d44aa111288240f90a1 (diff)
parentffb7726fa3042e66e8011fbd17a8b6f83f0c8110 (diff)
downloadcryptography-5175e4e6394ade40e38dc00b8e1e14a2877aafe4.tar.gz
cryptography-5175e4e6394ade40e38dc00b8e1e14a2877aafe4.tar.bz2
cryptography-5175e4e6394ade40e38dc00b8e1e14a2877aafe4.zip
Merge branch 'master' into validate-iv
Conflicts: cryptography/hazmat/primitives/ciphers/modes.py tests/hazmat/primitives/test_block.py
Diffstat (limited to 'docs/hazmat/primitives/constant-time.rst')
-rw-r--r--docs/hazmat/primitives/constant-time.rst38
1 files changed, 38 insertions, 0 deletions
diff --git a/docs/hazmat/primitives/constant-time.rst b/docs/hazmat/primitives/constant-time.rst
new file mode 100644
index 00000000..632e7c68
--- /dev/null
+++ b/docs/hazmat/primitives/constant-time.rst
@@ -0,0 +1,38 @@
+.. hazmat::
+
+Constant time functions
+=======================
+
+.. currentmodule:: cryptography.hazmat.primitives.constant_time
+
+This module contains functions for operating with secret data in a way that
+does not leak information about that data through how long it takes to perform
+the operation. These functions should be used whenever operating on secret data
+along with data that is user supplied.
+
+An example would be comparing a HMAC signature received from a client to the
+one generated by the server code for authentication purposes.
+
+For more information about this sort of issue, see `Coda Hale's blog post`_
+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.
+
+ .. doctest::
+
+ >>> from cryptography.hazmat.primitives import constant_time
+ >>> constant_time.bytes_eq(b"foo", b"foo")
+ True
+ >>> 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``.
+
+
+.. _`Coda Hale's blog post`: http://codahale.com/a-lesson-in-timing-attacks/