def set_session_key(self, session_key): """ Set session key that will be used for encryption and decryption. If you call `authentication_message` you don't need to call this method. """ self.session_key = session_key self.outgoing_sealing_key = hashlib.md5(session_key + SESSION_C2S_SEAL).digest() self.incoming_sealing_key = hashlib.md5(session_key + SESSION_S2C_SEAL).digest() self.outgoing_signing_key = hashlib.md5(session_key + SESSION_C2S_SIGN).digest() self.incoming_signing_key = hashlib.md5(session_key + SESSION_S2C_SIGN).digest() self.outgoing_seal_handle = RC4(self.outgoing_sealing_key) self.incoming_seal_handle = RC4(self.incoming_sealing_key)
def test_derivation(self): hash = nthash.raw_nthash("clientPass") response = binascii.unhexlify( "82309ECD8D708B5EA08FAA3981CD83544233114A3D85D6DF") state = MppeStateManager("", "", hash, response) assert state.masterKey == binascii.unhexlify( "FDECE3717A8C838CB388E527AE3CDD31") assert state.serverMasterKey == binascii.unhexlify( "8B7CDC149B993A1BA118CB153F56DCCB") assert state.serverSessionKey == binascii.unhexlify( "405CB2247A7956E6E211007AE27B22D4") cipher = RC4(key=state.serverSessionKey) assert cipher.update("test message") == binascii.unhexlify( "81848317DF68846272FB5ABE") cipher = RC4(key=state.serverSessionKey) assert cipher.update( binascii.unhexlify("81848317DF68846272FB5ABE")) == "test message"
def arcfour_encrypt(key, data): try: from Crypto.Cipher import ARC4 c = ARC4.new(key) return c.encrypt(data) except ImportError as e: pass try: from M2Crypto.RC4 import RC4 c = RC4(key) return c.update(data) except ImportError as e: pass raise Exception("arcfour_encrypt() requires " + "python*-crypto or python*-m2crypto or m2crypto")
def _decryptPacket(self, packet, sessionKey): cipher = RC4(key=sessionKey) plaintext = cipher.update(packet.getData()) if ord(plaintext[0]) == 0x00 and ord(plaintext[1]) == 0x21: ethPacket = packet.getEthernetFrame() ethPacket = copy.deepcopy(ethPacket) ipPacket = IP() ipPacket.unpack(plaintext[2:]) ethPacket.data = ipPacket return ethPacket return None
def rc4k(key, message): ''' Compute rc4 of `message` with initial `key`. ''' return RC4(key).update(message)
def rc4k(key, message): """ Compute rc4 of `message` with initial `key`. """ return RC4(key).update(message)
def _getNextKey(self, masterKey, lastSessionKey): nextSessionKey = self._getNextKeyFromSha(masterKey, lastSessionKey) cipher = RC4(key=nextSessionKey) return cipher.update(nextSessionKey)
def decrypt(nonce, password, data): key, salt1 = make_key(nonce, password) return RC4(key).update(b64decode(data))[len(salt1):]
def crypt(nc, password, data=''): key, salt1 = make_key(nc, password) return RC4(key).update(salt1 + data)
def simple_crypt(self, s, k=None, keymat=''): from M2Crypto.RC4 import RC4 if k is None: k = self._get_key(keymat) return RC4(k).update(s)