def new(key, mode=MODE_ECB, IV=None, counter=None, segment_size=None): """Create a new cipher object DES using pycrypto for algo and pycryptoplus for ciphermode key = raw string containing the keys mode = python_AES.MODE_ECB/CBC/CFB/OFB/CTR/CMAC, default is ECB IV = IV as a raw string, default is "all zero" IV -> only needed for CBC mode counter = counter object (CryptoPlus.Util.util.Counter) -> only needed for CTR mode segment_size = amount of bits to use from the keystream in each chain part -> supported values: multiple of 8 between 8 and the blocksize of the cipher (only per byte access possible), default is 8 -> only needed for CFB mode EXAMPLES: ********** IMPORTING: ----------- >>> from CryptoPlus.Cipher import DES EXAMPLE (test vectors from NESSIE): ----------------------------------- >>> cipher = DES.new(('7CA110454A1A6E57').decode('hex')) >>> ciphertext = cipher.encrypt(('01A1D6D039776742').decode('hex')) >>> (ciphertext).encode('hex') '690f5b0d9a26939b' >>> plaintext = cipher.decrypt(ciphertext) >>> (plaintext).encode('hex') '01a1d6d039776742' """ return DES(key, mode, IV, counter, segment_size)
def __init__(self, userproject, parameters, project_meta): self.parameters = self.PARAMETERS self.parameters.update(parameters) self.userproject = userproject meta_workunit_bits, str_patterns = project_meta.split(",") meta_workunit_bits = int(meta_workunit_bits) assert meta_workunit_bits == self.parameters[ "WORKUNIT_BITS"], "workunit bits disagrees between server and local config" patterns = [] while len(str_patterns): pattern = str_patterns[:16].decode('hex') assert len(pattern) == 8 patterns.append(pattern) str_patterns = str_patterns[16:] self.patterns = patterns self.nr_cores = self.parameters["NR_CORES"] self.waiting = True self.workunits = [] self.workunits_finished = [] assert len(patterns) <= self.parameters["NR_PATTERNS"] # fill with dummy entries patterns += ["\0" * 8 ] * (self.parameters["NR_PATTERNS"] - len(patterns)) self.cores = [] for i in range(self.nr_cores): c = DES(i, self.parameters["WORKUNIT_BITS"]) self.cores.append(c) self.des = self.cores[:] self.res = RES(self.parameters["NR_PATTERNS"], self.res_event) self.cores.append(self.res)