lint
This commit is contained in:
parent
402bc5743b
commit
d6a5c567ae
2 changed files with 50 additions and 5 deletions
|
@ -114,3 +114,48 @@ ciphers = {
|
||||||
'aes-192-cfb1': (24, 16, CtypesCrypto),
|
'aes-192-cfb1': (24, 16, CtypesCrypto),
|
||||||
'aes-256-cfb1': (32, 16, CtypesCrypto),
|
'aes-256-cfb1': (32, 16, CtypesCrypto),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def test():
|
||||||
|
from os import urandom
|
||||||
|
import random
|
||||||
|
import time
|
||||||
|
|
||||||
|
BLOCK_SIZE = 16384
|
||||||
|
rounds = 1 * 1024
|
||||||
|
plain = urandom(BLOCK_SIZE * rounds)
|
||||||
|
import M2Crypto.EVP
|
||||||
|
# cipher = M2Crypto.EVP.Cipher('aes_128_cfb', 'k' * 32, 'i' * 16, 1,
|
||||||
|
# key_as_bytes=0, d='md5', salt=None, i=1,
|
||||||
|
# padding=1)
|
||||||
|
# decipher = M2Crypto.EVP.Cipher('aes_128_cfb', 'k' * 32, 'i' * 16, 0,
|
||||||
|
# key_as_bytes=0, d='md5', salt=None, i=1,
|
||||||
|
# padding=1)
|
||||||
|
cipher = CtypesCrypto('aes-128-cfb', 'k' * 32, 'i' * 16, 1)
|
||||||
|
decipher = CtypesCrypto('aes-128-cfb', 'k' * 32, 'i' * 16, 0)
|
||||||
|
|
||||||
|
# cipher = Salsa20Cipher('salsa20-ctr', 'k' * 32, 'i' * 8, 1)
|
||||||
|
# decipher = Salsa20Cipher('salsa20-ctr', 'k' * 32, 'i' * 8, 1)
|
||||||
|
results = []
|
||||||
|
pos = 0
|
||||||
|
print 'salsa20 test start'
|
||||||
|
start = time.time()
|
||||||
|
while pos < len(plain):
|
||||||
|
l = random.randint(100, 32768)
|
||||||
|
c = cipher.update(plain[pos:pos + l])
|
||||||
|
results.append(c)
|
||||||
|
pos += l
|
||||||
|
pos = 0
|
||||||
|
c = ''.join(results)
|
||||||
|
results = []
|
||||||
|
while pos < len(plain):
|
||||||
|
l = random.randint(100, 32768)
|
||||||
|
results.append(decipher.update(c[pos:pos + l]))
|
||||||
|
pos += l
|
||||||
|
end = time.time()
|
||||||
|
print 'speed: %d bytes/s' % (BLOCK_SIZE * rounds / (end - start))
|
||||||
|
assert ''.join(results) == plain
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
test()
|
|
@ -112,6 +112,11 @@ class Salsa20Cipher(object):
|
||||||
return ''.join(results)
|
return ''.join(results)
|
||||||
|
|
||||||
|
|
||||||
|
ciphers = {
|
||||||
|
'salsa20-ctr': (32, 8, Salsa20Cipher),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def test():
|
def test():
|
||||||
from os import urandom
|
from os import urandom
|
||||||
import random
|
import random
|
||||||
|
@ -149,10 +154,5 @@ def test():
|
||||||
assert ''.join(results) == plain
|
assert ''.join(results) == plain
|
||||||
|
|
||||||
|
|
||||||
ciphers = {
|
|
||||||
'salsa20-ctr': (32, 8, Salsa20Cipher),
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
test()
|
test()
|
||||||
|
|
Loading…
Add table
Reference in a new issue