updated pycrypto
This commit is contained in:
@@ -44,10 +44,9 @@ An example of usage is the following:
|
||||
>>> from Crypto.Cipher import AES
|
||||
>>> from Crypto.Util import Counter
|
||||
>>>
|
||||
>>> pt = b'X'*1000000
|
||||
>>> pt = b'\x00'*1000000
|
||||
>>> ctr = Counter.new(128)
|
||||
>>> key = b'AES-128 symm key'
|
||||
>>> cipher = AES.new(key, AES.MODE_CTR, counter=ctr)
|
||||
>>> cipher = AES.new(b'\x00'*16, AES.MODE_CTR, counter=ctr)
|
||||
>>> ct = cipher.encrypt(pt)
|
||||
|
||||
:undocumented: __package__
|
||||
@@ -57,15 +56,11 @@ if sys.version_info[0] == 2 and sys.version_info[1] == 1:
|
||||
from Crypto.Util.py21compat import *
|
||||
from Crypto.Util.py3compat import *
|
||||
|
||||
from Crypto.pct_warnings import DisableShortcut_DeprecationWarning
|
||||
from Crypto.Util import _counter
|
||||
import struct
|
||||
import warnings
|
||||
|
||||
|
||||
# Factory function
|
||||
_deprecated = "deprecated"
|
||||
def new(nbits, prefix=b(""), suffix=b(""), initial_value=1, overflow=0, little_endian=False, allow_wraparound=False, disable_shortcut=_deprecated):
|
||||
def new(nbits, prefix=b(""), suffix=b(""), initial_value=1, overflow=0, little_endian=False, allow_wraparound=False, disable_shortcut=False):
|
||||
"""Create a stateful counter block function suitable for CTR encryption modes.
|
||||
|
||||
Each call to the function returns the next counter block.
|
||||
@@ -73,7 +68,7 @@ def new(nbits, prefix=b(""), suffix=b(""), initial_value=1, overflow=0, little_e
|
||||
|
||||
prefix || counter value || postfix
|
||||
|
||||
The counter value is incremented by 1 at each call.
|
||||
The counter value is incremented by one at each call.
|
||||
|
||||
:Parameters:
|
||||
nbits : integer
|
||||
@@ -86,18 +81,17 @@ def new(nbits, prefix=b(""), suffix=b(""), initial_value=1, overflow=0, little_e
|
||||
used.
|
||||
initial_value : integer
|
||||
The initial value of the counter. Default value is 1.
|
||||
overflow : integer
|
||||
This value is currently ignored.
|
||||
little_endian : boolean
|
||||
If *True*, the counter number will be encoded in little endian format.
|
||||
If *False* (default), in big endian format.
|
||||
If True, the counter number will be encoded in little endian format.
|
||||
If False (default), in big endian format.
|
||||
allow_wraparound : boolean
|
||||
If *True*, the counter will automatically restart from zero after
|
||||
reaching the maximum value (``2**nbits-1``).
|
||||
If *False* (default), the object will raise an *OverflowError*.
|
||||
disable_shortcut : deprecated
|
||||
This option is a no-op for backward compatibility. It will be removed
|
||||
in a future version. Don't use it.
|
||||
If True, the function will raise an *OverflowError* exception as soon
|
||||
as the counter wraps around. If False (default), the counter will
|
||||
simply restart from zero.
|
||||
disable_shortcut : boolean
|
||||
If True, do not make ciphers from `Crypto.Cipher` bypass the Python
|
||||
layer when invoking the counter block function.
|
||||
If False (default), bypass the Python layer.
|
||||
:Returns:
|
||||
The counter block function.
|
||||
"""
|
||||
@@ -114,13 +108,10 @@ def new(nbits, prefix=b(""), suffix=b(""), initial_value=1, overflow=0, little_e
|
||||
|
||||
initval = _encode(initial_value, nbytes, little_endian)
|
||||
|
||||
if disable_shortcut is not _deprecated: # exact object comparison
|
||||
warnings.warn("disable_shortcut has no effect and is deprecated", DisableShortcut_DeprecationWarning)
|
||||
|
||||
if little_endian:
|
||||
return _counter._newLE(bstr(prefix), bstr(suffix), initval, allow_wraparound=allow_wraparound)
|
||||
return _counter._newLE(bstr(prefix), bstr(suffix), initval, allow_wraparound=allow_wraparound, disable_shortcut=disable_shortcut)
|
||||
else:
|
||||
return _counter._newBE(bstr(prefix), bstr(suffix), initval, allow_wraparound=allow_wraparound)
|
||||
return _counter._newBE(bstr(prefix), bstr(suffix), initval, allow_wraparound=allow_wraparound, disable_shortcut=disable_shortcut)
|
||||
|
||||
def _encode(n, nbytes, little_endian=False):
|
||||
retval = []
|
||||
|
@@ -23,22 +23,15 @@
|
||||
Contains useful modules that don't belong into any of the
|
||||
other Crypto.* subpackages.
|
||||
|
||||
======================== =============================================
|
||||
Module Description
|
||||
======================== =============================================
|
||||
`Crypto.Util.number` Number-theoretic functions (primality testing, etc.)
|
||||
`Crypto.Util.Counter` Fast counter functions for CTR cipher modes.
|
||||
`Crypto.Util.randpool` Random number generation
|
||||
`Crypto.Util.RFC1751` Converts between 128-bit keys and human-readable
|
||||
strings of words.
|
||||
`Crypto.Util.asn1` Minimal support for ASN.1 DER encoding
|
||||
`Crypto.Util.Padding` Set of functions for adding and removing padding.
|
||||
======================== =============================================
|
||||
Crypto.Util.number Number-theoretic functions (primality testing, etc.)
|
||||
Crypto.Util.randpool Random number generation
|
||||
Crypto.Util.RFC1751 Converts between 128-bit keys and human-readable
|
||||
strings of words.
|
||||
Crypto.Util.asn1 Minimal support for ASN.1 DER encoding
|
||||
|
||||
"""
|
||||
|
||||
__all__ = ['randpool', 'RFC1751', 'number', 'strxor', 'asn1', 'Counter',
|
||||
'Padding' ]
|
||||
__all__ = ['randpool', 'RFC1751', 'number', 'strxor', 'asn1' ]
|
||||
|
||||
__revision__ = "$Id$"
|
||||
|
||||
|
BIN
modules/Crypto/Util/_counter.so
Executable file
BIN
modules/Crypto/Util/_counter.so
Executable file
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@@ -81,21 +81,4 @@ except TypeError:
|
||||
return True
|
||||
return False
|
||||
|
||||
#
|
||||
# Python 2.2 introduces the built-in staticmethod(). Python 2.4 turns
|
||||
# it into a function decorator (@staticmethod).
|
||||
#
|
||||
# The following recipe for achieving the same thing in Python 2.1 comes
|
||||
# from the Python Cookbok ("Implementanting Static Methods").
|
||||
#
|
||||
try:
|
||||
class A:
|
||||
def a(): pass
|
||||
a = staticmethod(a)
|
||||
except NameError:
|
||||
class staticmethod:
|
||||
def __init__(self, anycallable):
|
||||
self.__call__ = anycallable
|
||||
__all__ += ['staticmethod']
|
||||
|
||||
# vim:set ts=4 sw=4 sts=4 expandtab:
|
||||
|
@@ -77,18 +77,12 @@ if sys.version_info[0] == 2:
|
||||
return s.encode('latin-1')
|
||||
except:
|
||||
return ''.join(s)
|
||||
def tostr(bs):
|
||||
return unicode(bs, 'latin-1')
|
||||
else:
|
||||
def tobytes(s):
|
||||
if isinstance(s, unicode):
|
||||
return s.encode("latin-1")
|
||||
else:
|
||||
return ''.join(s)
|
||||
def tostr(bs):
|
||||
return bs.decode('latin-1')
|
||||
# In Pyton 2.x, StringIO is a stand-alone module
|
||||
from StringIO import StringIO as BytesIO
|
||||
else:
|
||||
def b(s):
|
||||
return s.encode("latin-1") # utf-8 would cause some side-effects we don't want
|
||||
@@ -109,9 +103,5 @@ else:
|
||||
return s.encode("latin-1")
|
||||
else:
|
||||
return bytes(s)
|
||||
def tostr(bs):
|
||||
return bs.decode("latin-1")
|
||||
# In Pyton 3.x, StringIO is a sub-module of io
|
||||
from io import BytesIO
|
||||
|
||||
|
||||
# vim:set ts=4 sw=4 sts=4 expandtab:
|
||||
|
BIN
modules/Crypto/Util/strxor.so
Executable file
BIN
modules/Crypto/Util/strxor.so
Executable file
Binary file not shown.
Reference in New Issue
Block a user