123456789101112131415161718192021222324252627282930 |
- def aes(key, data, counter=False):
- """ encrypt data with aes, using either pycryptopp or PyCrypto.
- Args
- key: The encryption key
- data: plain text data
- counter: a callable, usually not needed
- """
- # using either pycryptopp...
- if hasattr(AES, "process"):
- a = AES(key)
- return a.process(data)
- # ... or PyCrypto
- counter = counter or Counter()
- a = AES.new(key, AES.MODE_CTR, counter=counter)
- rest = len(data) % 16
- if not rest:
- return a.encrypt(data)
- # Data length must be a multiple of 16
- # Pad with bytes all of the same value as the number of padding bytes
- pad = (16 - rest)
- data += chr(pad) * pad
- return a.encrypt(data)[:-pad]
- class SHA256d(object):
- """ implements SHA-265d against length-extensions-attacks
- as defined by Schneier and Fergusson
- """
-
-
|