diff options
author | Alex Gaynor <alex.gaynor@gmail.com> | 2013-12-17 07:35:34 -0800 |
---|---|---|
committer | Alex Gaynor <alex.gaynor@gmail.com> | 2013-12-17 07:35:34 -0800 |
commit | 875b36be29e6bcfd1cb2a9cb216aba49c1d9d2f0 (patch) | |
tree | 71372f15c53afdd4bf2459e9a4774f3d526075a5 /docs/hazmat/primitives/constant-time.rst | |
parent | 4eec0bb4e1d79f107f40b3856f2c9ec76c3eef88 (diff) | |
parent | a4aa420cc6c0203d201a0f418af68d1f11abbcf5 (diff) | |
download | cryptography-875b36be29e6bcfd1cb2a9cb216aba49c1d9d2f0.tar.gz cryptography-875b36be29e6bcfd1cb2a9cb216aba49c1d9d2f0.tar.bz2 cryptography-875b36be29e6bcfd1cb2a9cb216aba49c1d9d2f0.zip |
Merge branch 'master' into no-more-generator
Conflicts:
tests/hazmat/primitives/utils.py
Diffstat (limited to 'docs/hazmat/primitives/constant-time.rst')
-rw-r--r-- | docs/hazmat/primitives/constant-time.rst | 38 |
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/ |