]> granicus.if.org Git - python/commitdiff
Merge heads.
authorGeorg Brandl <georg@python.org>
Sun, 24 Jun 2012 14:10:47 +0000 (16:10 +0200)
committerGeorg Brandl <georg@python.org>
Sun, 24 Jun 2012 14:10:47 +0000 (16:10 +0200)
1  2 
Doc/library/hmac.rst

index 3fa0bd66ae5b9d35cd22c5fd29f3d8695c42ff72,2ea3fc620c3822ac2fd3b1d78654dada8c947bc6..085c12b8576d05a4244a0739a3a65b2888fcadf0
@@@ -71,32 -70,16 +70,32 @@@ This module also provides the followin
  
  .. function:: compare_digest(a, b)
  
 -   Return ``a == b``.  This function uses an approach designed to prevent
 -   timing analysis, making it appropriate for cryptography.  *a* and *b*
 +   Return ``a == b``.  This function uses an approach designed to prevent timing
-    analysis by avoiding content based short circuiting behaviour.  The inputs
-    must either both support the buffer protocol (e.g. :class:`bytes` and
-    :class:`bytearray` instances) or be ASCII-only :class:`str` instances as
-    returned by :meth:`hexdigest`.  :class:`bytes` and :class:`str` instances
-    can't be mixed.
++   analysis by avoiding content based short circuiting behaviour, making it
++   appropriate for cryptography.  *a* and *b*
+    must both be of the same type: either :class:`str` (ASCII only, as e.g.
+    returned by :meth:`HMAC.hexdigest`), or any type that supports the
+    :term:`buffer protocol` (e.g. :class:`bytes`).
  
 +   Using a short circuiting comparison (that is, one that terminates as soon as
 +   it finds any difference between the values) to check digests for correctness
 +   can be problematic, as it introduces a potential vulnerability when an
 +   attacker can control both the message to be checked *and* the purported
 +   signature value.  By keeping the plaintext consistent and supplying different
 +   signature values, an attacker may be able to use timing variations to search
 +   the signature space for the expected value in O(n) time rather than the
 +   desired O(2**n).
 +
     .. note::
 -      If *a* and *b* are different lengths, or if an error occurs,
 -      a timing attack may be able to infer information about the types
 -      and lengths of *a* and *b*, but not their values.
 +
 +      While this function reduces the likelihood of leaking the contents of the
 +      expected digest via a timing attack, it still may leak some timing
 +      information when the input values differ in lengths as well as in error
 +      cases like unsupported types or non ASCII strings.  When the inputs have
 +      different length the timing depends solely on the length of ``b``.  It is
 +      assumed that the expected length of the digest is not a secret, as it is
 +      typically published as part of a file format, network protocol or API
 +      definition.
  
     .. versionadded:: 3.3