Source code for tlslite.utils.pycrypto_tripledes

# Author: Trevor Perrin
# See the LICENSE file for legal information regarding use of this file.

"""PyCrypto 3DES implementation."""

from .cryptomath import *
from .tripledes import *

if pycryptoLoaded:
    import Crypto.Cipher.DES3

[docs] def new(key, mode, IV): return PyCrypto_TripleDES(key, mode, IV)
[docs] class PyCrypto_TripleDES(TripleDES):
[docs] def __init__(self, key, mode, IV): TripleDES.__init__(self, key, mode, IV, "pycrypto") key = bytes(key) IV = bytes(IV) self.context = Crypto.Cipher.DES3.new(key, mode, IV)
[docs] def encrypt(self, plaintext): plaintext = bytes(plaintext) return bytearray(self.context.encrypt(plaintext))
[docs] def decrypt(self, ciphertext): ciphertext = bytes(ciphertext) return bytearray(self.context.decrypt(ciphertext))