def _regen_b3b4(self): """Regenerate b3 and b4. This is the encrypted form of L. """ tw = MCRYPT('twofish', 'ecb') tw.init(self.pprime) self.b3b4 = tw.encrypt(self.hshkey) log.debug("B3/B4 set to %s" % repr(self.b3b4))
def _regen_b1b2(self): """Regenerate b1 and b2. This is the encrypted form of K. """ tw = MCRYPT('twofish', 'ecb') tw.init(self.pprime) self.b1b2 = tw.encrypt(self.enckey) log.debug("B1/B2 set to %s" % repr(self.b1b2))
def decrypt_data(self): """Decrypt encrypted portion of header and data""" log.debug("Creating mcrypt object") tw = MCRYPT('twofish', 'cbc') log.debug("Adding key & iv") tw.init(self.enckey, self.iv) log.debug("Decrypting data") self.fulldata = tw.decrypt(self.cryptdata)
def calc_keys(self): """Calculate sessions keys for encryption and hmac. Is based on pprime, b1b2, b3b4""" tw = MCRYPT('twofish', 'ecb') tw.init(self.pprime) self.enckey = tw.decrypt(self.b1b2) # its ok to reuse; ecb doesn't keep state info self.hshkey = tw.decrypt(self.b3b4) log.debug("Encryption key K: %s " % repr(self.enckey)) log.debug("HMAC Key L: %s " % repr(self.hshkey))
#!/usr/bin/python _author__ = 'm_messiah' from mcrypt import MCRYPT as CR import base64 as base from redis import StrictRedis as DB from math import sin as si, cos as co, sqrt as sq, pow as pw, atan2 as at db = DB(host='localhost', port=6379, db=0) cr = CR("gost", "ecb") cr.init("0" * 32) def func1(t, p): try: s = pp(cp(p)) if len(s) <= 1: return "Invalid path data\n" n = gn(t) db.lpush(t, p) sa = sp(s) + "\t" + str(sum(s[:12])) db.lpush(n, sa) db.zadd("users", sum(s[:12]), n) return "stored:" + sa + "\n" except Exception as e: try: db.lpop(t) except: pass
def encryptXtea(key, iv, str): m = MCRYPT('xtea', 'ecb') key = key.ljust(m.get_key_size(), "\0") iv = iv.ljust(m.get_iv_size(), "\0") m.init(key, iv) return m.encrypt(str)
from mcrypt import MCRYPT import base64 crypt = MCRYPT('MCRYPT_RIJNDAEL_128', 'MCRYPT_MODE_CBC') key = 'uc1N6G3r!n9'
def encrypt_data(self): """Encrypted fulldata to cryptdata""" tw = MCRYPT('twofish', 'cbc') tw.init(self.enckey, self.iv) self.cryptdata = tw.encrypt(self.fulldata)
def decrypt_data(self): """Decrypt encrypted portion of header and data""" tw = MCRYPT('twofish', 'cbc') tw.init(self.enckey, self.iv) self.fulldata = tw.decrypt(self.cryptdata)
#!/usr/bin/python _author__ = 'm_messiah' from mcrypt import MCRYPT as CR import base64 as base from redis import StrictRedis as DB from math import sin as si, cos as co, sqrt as sq, pow as pw, atan2 as at db = DB(host='localhost', port=6379, db=0) cr = CR("gost", "ecb") cr.init("0" * 32) def func1(t, p): try: s = pp(cp(p)) if len(s) <= 1: return "Invalid path data\n" n = gn(t) db.lpush(t, p) sa = sp(s) + "\t" + str(sum(s[:12])) db.lpush(n, sa) db.zadd("users", sum(s[:12]), n) return "stored:" + sa + "\n" except Exception as e: try: db.lpop(t) except: pass finally: