Example #1
0
	def aes_ctr_crypt(key, data_orig, ctr_val):
		data = [x for x in data_orig]
		AESr = AES.new(_OT.bytes_to_cbytes(key), AES.MODE_CTR, counter=OtrCrypt.aes_counter(ctr_val))
		# need to fill to a multiple of 16; since it is in 
		# counter mode, we can just ignore the end of the encrypted output
		fill_len = (16 - (len(data) % 16)) % 16
		data.extend([0]*fill_len)
		# do the encryption
		enc_str = AESr.encrypt(_OT.bytes_to_cbytes(data))
		return _OT.string_to_bytes(enc_str[:-fill_len])
Example #2
0
	def process_outgoing(self, msg):
		logging.debug("Outgoing")
		if self.auth.message_state_is("MSGSTATE_ENCRYPTED"):
			self.auth.dh_keys.prepare_session_to_send()
			vars = self.auth.dh_keys.encrypt_data_message(_OT.string_to_bytes(msg.getBody()))
			logging.debug( vars )
			#r = raw_input()
			enc_msg = self.message_factory().create_data(*vars)
			self.client.send(enc_msg.jabber_msg)
		else:
			self.client.send(msg)
		return msg
Example #3
0
	def payload_to_bytes(self, payload):
		return _OT.string_to_bytes(base64.b64decode(payload))
Example #4
0
	def get_sha1_bytes(data):
		return _OT.string_to_bytes(SHA.new(_OT.bytes_to_string(data)).digest())
Example #5
0
	def get_sha1_hmac(key, data):
		return _OT.string_to_bytes(HMAC.new(_OT.bytes_to_string(key), _OT.bytes_to_string(data), SHA).digest())