def try_once(i): key = bits.getrandbytes(16) bytes = bits.getrandbytes(16) py_e = py_encrypt(key, bytes) c_e = c_encrypt(key, bytes) assert py_e == c_e py_d = py_decrypt(key, py_e) c_d = c_decrypt(key, c_e) py_d_c = py_decrypt(key, c_e) c_d_py = c_decrypt(key, py_e) assert py_d_c == bytes assert py_d == bytes assert c_d == bytes assert c_d_py == bytes if ((i*100)/TRIALS) == ((i*100)//TRIALS): sys.stdout.write('|')
def try_once(i): key = bits.getrandbytes(16) bytes = bits.getrandbytes(16) py_e = py_encrypt(key, bytes) c_e = c_encrypt(key, bytes) assert py_e == c_e py_d = py_decrypt(key, py_e) c_d = c_decrypt(key, c_e) py_d_c = py_decrypt(key, c_e) c_d_py = c_decrypt(key, py_e) assert py_d_c == bytes assert py_d == bytes assert c_d == bytes assert c_d_py == bytes if ((i * 100) / TRIALS) == ((i * 100) // TRIALS): sys.stdout.write('|')
def hotmail_token(token, tag, rru='/cgi-bin/HoTMaiL'): nonce = bits.getrandbytes(24) secret = base64.b64decode(str(token.RequestedProofToken.BinarySecret)) key = mail.passport.derive_key(secret, 'WS-SecureConversation'+nonce) info = ( ('ct',str(int(time.time()))), ('bver','4'), ('id','2'), ('rru', rru), ('svc','mail'), ('js','yes'), ('pl','?id=2'), ('da', extract_encrypted(tag)), ('nonce',base64.b64encode(nonce)), ) message = [] add = message.append for k,v in info: add('&') add(k) add('=') v = v.encode('url') if k == 'rru': v = v.replace('/', '%2F').replace('.', '%2E') if k == 'da': v = v.replace('%3A', ':') add(v) message.pop(0) message = ''.join(message) hash = hmac.HMAC(key, message, hashlib.sha1).digest() message += '&hash=%s' % base64.b64encode(hash).encode('url') return 'token=%s' % message.encode('url').replace('%3A', ':')
def hotmail_token(token, tag, rru='/cgi-bin/HoTMaiL'): nonce = bits.getrandbytes(24) secret = base64.b64decode(str(token.RequestedProofToken.BinarySecret)) key = mail.passport.derive_key(secret, 'WS-SecureConversation' + nonce) info = ( ('ct', str(int(time.time()))), ('bver', '4'), ('id', '2'), ('rru', rru), ('svc', 'mail'), ('js', 'yes'), ('pl', '?id=2'), ('da', extract_encrypted(tag)), ('nonce', base64.b64encode(nonce)), ) message = [] add = message.append for k, v in info: add('&') add(k) add('=') v = v.encode('url') if k == 'rru': v = v.replace('/', '%2F').replace('.', '%2E') if k == 'da': v = v.replace('%3A', ':') add(v) message.pop(0) message = ''.join(message) hash = hmac.HMAC(key, message, hashlib.sha1).digest() message += '&hash=%s' % base64.b64encode(hash).encode('url') return 'token=%s' % message.encode('url').replace('%3A', ':')
def mbi_crypt(key, nonce, iv=None): wssec = "WS-SecureConversation" from util.cryptography import DES3 if iv is None: iv = bits.getrandbytes(8) key1 = key.decode('base64') key2 = derive_key(key1, wssec+'SESSION KEY HASH') key3 = derive_key(key1, wssec+'SESSION KEY ENCRYPTION') hash = HMAC(key2, nonce, sha1).digest() des = DES3(key3, 2, iv) # wincrypt pads with '\x08' bytes pad = lambda s: s+((8-(len(s)%8))*chr(8)) cipher = des.encrypt(pad(nonce)) return keystruct(iv, hash, cipher).pack().encode('base64').replace('\n','')
def mbi_crypt(key, nonce, iv=None): wssec = "WS-SecureConversation" from util.cryptography import DES3 if iv is None: iv = bits.getrandbytes(8) key1 = key.decode('base64') key2 = derive_key(key1, wssec + 'SESSION KEY HASH') key3 = derive_key(key1, wssec + 'SESSION KEY ENCRYPTION') hash = HMAC(key2, nonce, sha1).digest() des = DES3(key3, 2, iv) # wincrypt pads with '\x08' bytes pad = lambda s: s + ((8 - (len(s) % 8)) * chr(8)) cipher = des.encrypt(pad(nonce)) return keystruct(iv, hash, cipher).pack().encode('base64').replace('\n', '')
assert c_d_py == bytes if ((i*100)/TRIALS) == ((i*100)//TRIALS): sys.stdout.write('|') threadpool.ThreadPool(15) #print '\nthreaded' #for i in range(TRIALS): # util.threaded(try_once)(i) # #print 'sequential' #for i in range(TRIALS): # try_once(i) key = bits.getrandbytes(16) c_crypter = c_rijndael(key) py_crypter = py_rijndael(key) py_encrypt = lambda _key, x: py_crypter.encrypt(x) py_decrypt = lambda _key, x: py_crypter.decrypt(x) c_encrypt = lambda _key, x: c_crypter.encrypt(x) c_decrypt = lambda _key, x: c_crypter.decrypt(x) print '\nsequential stateful' for i in range(TRIALS): try_once(i) #import time #time.sleep(TRIALS//1000 * 5)
if ((i * 100) / TRIALS) == ((i * 100) // TRIALS): sys.stdout.write('|') threadpool.ThreadPool(15) #print '\nthreaded' #for i in range(TRIALS): # util.threaded(try_once)(i) # #print 'sequential' #for i in range(TRIALS): # try_once(i) key = bits.getrandbytes(16) c_crypter = c_rijndael(key) py_crypter = py_rijndael(key) py_encrypt = lambda _key, x: py_crypter.encrypt(x) py_decrypt = lambda _key, x: py_crypter.decrypt(x) c_encrypt = lambda _key, x: c_crypter.encrypt(x) c_decrypt = lambda _key, x: c_crypter.decrypt(x) print '\nsequential stateful' for i in range(TRIALS): try_once(i) #import time #time.sleep(TRIALS//1000 * 5)